Example #1
0
        internal static void Parse(OnionRouter router, string descriptor)
        {
            string[]          lines            = descriptor.Split('\n');
            document_location current_location = document_location.control_word;
            string            current_key      = null;

            foreach (string line in lines)
            {
                // onion-key
                if (line == control_words[(int)control_word_type.control_word_onion_key])
                {
                    current_location = document_location.onion_key;
                    continue;
                }
                // signing-key
                if (line == control_words[(int)control_word_type.control_word_signing_key])
                {
                    current_location = document_location.signing_key;
                    continue;
                }
                // -----BEGIN RSA PUBLIC KEY-----
                if (line == control_words[(int)control_word_type.control_word_key_begin])
                {
                    if (current_location == document_location.onion_key)
                    {
                        current_location = document_location.onion_key_content;
                    }
                    else if (current_location == document_location.signing_key)
                    {
                        current_location = document_location.signing_key_content;
                    }
                    continue;
                }
                // -----END RSA PUBLIC KEY-----
                if (line == control_words[(int)control_word_type.control_word_key_end])
                {
                    if (current_location == document_location.onion_key_content)
                    {
                        router.OnionKey = Base64.Decode(current_key);
                    }
                    else if (current_location == document_location.signing_key_content)
                    {
                        router.SigningKey = Base64.Decode(current_key);
                    }
                    current_location = document_location.control_word;
                    current_key      = null;
                }
                else if (current_location == document_location.onion_key_content ||
                         current_location == document_location.signing_key_content)
                {
                    current_key += line;
                }
            }
        }
        // using control_word_list = stack_buffer<string_hash, 4>;
        internal void parse(ConsensusOrVote consensus, string descriptor)
        {
            string[]          lines            = descriptor.Split('\n');
            document_location current_location = document_location.control_word;
            OnionRouter       current_router   = null;
            string            current_key      = null;

            foreach (string line in lines)
            {
                string[] splitted_line     = line.Split(' ');
                string   control_word_hash = splitted_line[0];

                // introduction-point
                if (control_word_hash == control_words[(int)control_word_type.control_word_introduction_point])
                {
                    string identity_fingerprint = Base16.Encode(Base32.decode(splitted_line[1]));
                    current_router = consensus.get_onion_router_by_identity_fingerprint(identity_fingerprint);
                    continue;
                }
                // service-key
                if (control_word_hash == control_words[(int)control_word_type.control_word_service_key])
                {
                    current_location = document_location.service_key;
                    continue;
                }
                // -----BEGIN RSA PUBLIC KEY-----
                if (line == control_words[(int)control_word_type.control_word_key_begin] && current_location == document_location.service_key)
                {
                    current_location = document_location.service_key_content;
                    continue;
                }
                // -----END RSA PUBLIC KEY-----
                if (line == control_words[(int)control_word_type.control_word_key_end] && current_location == document_location.service_key_content)
                {
                    if (null != current_router)
                    {
                        current_router.ServiceKey = Base64.Decode(current_key);
                        introduction_point_list.Add(current_router);
                    }
                    current_location = document_location.control_word;
                    current_key      = null;
                }
                else if (current_location == document_location.service_key_content)
                {
                    current_key += line;
                }
            }
        }
Example #3
0
        internal void parse(ConsensusOrVote consensus, string descriptor)
        {
            string[]          lines            = descriptor.Split('\n');
            document_location current_location = document_location.control_word;
            string            current_message  = string.Empty;

            foreach (string line in lines)
            {
                // introduction-points
                if (line == control_words[(int)control_word_type.control_word_introduction_points])
                {
                    current_location = document_location.introduction_points;
                    continue;
                }
                // -----BEGIN MESSAGE-----
                else if (line == control_words[(int)control_word_type.control_word_message_begin])
                {
                    current_location = document_location.introduction_points_content;
                    continue;
                }
                // -----END MESSAGE-----
                else if (line == control_words[(int)control_word_type.control_word_message_end])
                {
                    current_location = document_location.control_word;
                    break;
                }
                else if (current_location == document_location.introduction_points_content)
                {
                    current_message += line;
                }
            }
            // introduction points are base64 encoded.
            string introduction_point_descriptor_string =
                ASCIIEncoding.ASCII.GetString(Base64.Decode(current_message));

            // parse the introduction point descriptor.
            IntroductionPointParser parser = new IntroductionPointParser();

            parser.parse(consensus, introduction_point_descriptor_string);
            introduction_point_list        = parser.introduction_point_list;
            parser.introduction_point_list = null;
        }