// 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; } } }
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; }
protected ConsensusAndVoteBaseParser(DocumentType type, ConsensusOrVote target) { if (null == target) { throw new ArgumentNullException(); } // Looks like the two next lines are redundant ? They're not. _target = target; SetTarget(target); _documentType = type; _invalidDocumentPrefix = "Invalid " + DocumentName + " document "; switch (type) { case DocumentType.Consensus: break; default: ParserInternalError("Unsupported document type {0}", type); // Not reachable. return; } }
/// <summary>This method is intended to let the subclass store the instance /// as a member in order to speed up access.</summary> /// <param name="candidate"></param> protected abstract void SetTarget(ConsensusOrVote candidate);