commit e52f0ec96b01db7da8002479b9a864a6f18f6db8 Author: Damian Johnson atagar@torproject.org Date: Sat Sep 29 11:17:09 2012 -0700
Dropping the old KeyCertificate class
We have a new shiny and tested KeyCertificate class so dropping the old one. --- stem/descriptor/__init__.py | 92 -------------------------------------- stem/descriptor/networkstatus.py | 4 +- 2 files changed, 2 insertions(+), 94 deletions(-)
diff --git a/stem/descriptor/__init__.py b/stem/descriptor/__init__.py index 9fa1f9e..362500a 100644 --- a/stem/descriptor/__init__.py +++ b/stem/descriptor/__init__.py @@ -441,95 +441,3 @@ def _strptime(string, validate = True, optional = False): def line_matches_keyword(keyword, line): return re.search("^(opt )?" + re.escape(keyword) + "($| )", line)
-class KeyCertificate(Descriptor): - """ - Directory key certificate. - - :var str key_certificate_version: ***** version of the key certificate (Should be "3") - :var str ip: IP address on which the directory authority is listening - :var int port: port on which the directory authority is listening - :var str fingerprint: ***** hex encoded fingerprint of the authority's identity key - :var str identity_key: ***** long term authority identity key - :var datetime published: ***** time (in GMT) when this document & the key were last generated - :var str expires: ***** time (in GMT) after which this key becomes invalid - :var str signing_key: ***** directory server's public signing key - :var str crosscert: signature made using certificate's signing key - :var str certification: ***** signature of this key certificate signed with the identity key - - ***** attribute is either required when we're parsed with validation or has a default value, others are left as None if undefined - """ - - def __init__(self, raw_content, validate = True): - """ - Parse a key certificate entry and provide a KeyCertificate object. - - :param str raw_content: raw key certificate information - :param bool validate: True if the document is to be validated, False otherwise - - :raises: ValueError if the raw data is invalid - """ - - super(KeyCertificate, self).__init__(raw_content) - self.key_certificate_version, self.ip, self.port = None, None, None - self.fingerprint, self.identity_key, self.published = None, None, None - self.expires, self.signing_key, self.crosscert = None, None, None - self.certification = None - content = raw_content.splitlines() - seen_keywords = set() - - self.key_certificate_version = _read_keyword_line_str("dir-key-certificate-version", content) - if validate and self.key_certificate_version != "3": - raise ValueError("Unrecognized dir-key-certificate-version") - - def read_keyword_line(keyword): - if validate and keyword in seen_keywords: - raise ValueError("Invalid key certificate: '%s' appears twice" % keyword) - seen_keywords.add(keyword) - return _read_keyword_line_str(keyword, content, validate) - - while content: - if line_matches_keyword("dir-address", content[0]): - line = read_keyword_line("dir-address") - try: - self.ip, self.port = line.rsplit(":", 1) - self.port = int(self.port) - except Exception: - if validate: raise ValueError("Invalid dir-address line: %s" % line) - elif line_matches_keyword("fingerprint", content[0]): - self.fingerprint = read_keyword_line("fingerprint") - elif line_matches_keyword("dir-identity-key", content[0]): - read_keyword_line("dir-identity-key") - self.identity_key = _get_pseudo_pgp_block(content) - elif line_matches_keyword("dir-key-published", content[0]): - self.published = _strptime(read_keyword_line("dir-key-published")) - elif line_matches_keyword("dir-key-expires", content[0]): - self.expires = _strptime(read_keyword_line("dir-key-expires")) - elif line_matches_keyword("dir-signing-key", content[0]): - read_keyword_line("dir-signing-key") - self.signing_key = _get_pseudo_pgp_block(content) - elif line_matches_keyword("dir-key-crosscert", content[0]): - read_keyword_line("dir-key-crosscert") - self.crosscert = _get_pseudo_pgp_block(content) - elif line_matches_keyword("dir-key-certification", content[0]): - read_keyword_line("dir-key-certification") - self.certification = _get_pseudo_pgp_block(content) - break - elif validate: - raise ValueError("Key certificate contains unrecognized lines: %s" % content[0]) - else: - # ignore unrecognized lines if we aren't validating - self.unrecognized_lines.append(content.pop(0)) - - self.unrecognized_lines = content - if self.unrecognized_lines and validate: - raise ValueError("Unrecognized trailing data in key certificate") - - def get_unrecognized_lines(self): - """ - Returns any unrecognized lines. - - :returns: a list of unrecognized lines - """ - - return self.unrecognized_lines - diff --git a/stem/descriptor/networkstatus.py b/stem/descriptor/networkstatus.py index ad74442..989bd95 100644 --- a/stem/descriptor/networkstatus.py +++ b/stem/descriptor/networkstatus.py @@ -679,7 +679,7 @@ class DirectoryAuthority(stem.descriptor.Descriptor):
**Vote Attributes:** :var str legacy_dir_key: fingerprint of and obsolete identity key - :var :class:`stem.descriptor.KeyCertificate` key_certificate: ***** authority's key certificate + :var :class:`stem.descriptor.networkstatus.KeyCertificate` key_certificate: ***** authority's key certificate
***** mandatory attribute """ @@ -767,7 +767,7 @@ class DirectoryAuthority(stem.descriptor.Descriptor): self.contact = _read_keyword_line("contact", content, validate) if vote: self.legacy_dir_key = _read_keyword_line("legacy-dir-key", content, validate, True) - self.key_certificate = stem.descriptor.KeyCertificate(content.read(), validate) + self.key_certificate = KeyCertificate(content.read(), validate) else: self.vote_digest = _read_keyword_line("vote-digest", content, True, validate) self.unrecognized_lines = content.read()