[tor-commits] [stem/master] Rename DigestHashType to DigestHash

atagar at torproject.org atagar at torproject.org
Thu Nov 15 20:29:50 UTC 2018


commit 909fbee87461a98fbaa7e4319a86637168c96c6e
Author: Damian Johnson <atagar at torproject.org>
Date:   Thu Nov 15 08:53:58 2018 -0800

    Rename DigestHashType to DigestHash
    
    Shorter is better in enum names, and the 'Type' suffix didn't convey anything.
---
 stem/descriptor/__init__.py                  |  6 +++---
 stem/descriptor/extrainfo_descriptor.py      | 18 +++++++++---------
 test/unit/descriptor/extrainfo_descriptor.py |  4 ++--
 3 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/stem/descriptor/__init__.py b/stem/descriptor/__init__.py
index bb890afd..a35cd4e4 100644
--- a/stem/descriptor/__init__.py
+++ b/stem/descriptor/__init__.py
@@ -19,7 +19,7 @@ Package for parsing and processing descriptor data.
     |- get_unrecognized_lines - unparsed descriptor content
     +- __str__ - string that the descriptor was made from
 
-.. data:: DigestHashType (enum)
+.. data:: DigestHash (enum)
 
   .. versionadded:: 1.8.0
 
@@ -27,7 +27,7 @@ Package for parsing and processing descriptor data.
   hash padding to match Tor.
 
   =================== ===========
-  DigestHashType      Description
+  DigestHash          Description
   =================== ===========
   SHA1                SHA1 hash
   SHA256              SHA256 hash
@@ -132,7 +132,7 @@ skFtXhOHHqTRN4GPPrZsAIUOQGzQtGb66IQgT4tO/pj+P6QmSCCdTfhvGfgTCsC+
 WPi4Fl2qryzTb3QO5r5x7T8OsG2IBUET1bLQzmtbC560SYR49IvVAgMBAAE=
 """
 
-DigestHashType = stem.util.enum.UppercaseEnum(
+DigestHash = stem.util.enum.UppercaseEnum(
   'SHA1',
   'SHA256',
 )
diff --git a/stem/descriptor/extrainfo_descriptor.py b/stem/descriptor/extrainfo_descriptor.py
index f1e29cd2..a374ea03 100644
--- a/stem/descriptor/extrainfo_descriptor.py
+++ b/stem/descriptor/extrainfo_descriptor.py
@@ -80,7 +80,7 @@ import stem.util.str_tools
 from stem.descriptor import (
   PGP_BLOCK_END,
   Descriptor,
-  DigestHashType,
+  DigestHash,
   create_signing_key,
   _descriptor_content,
   _read_until_keywords,
@@ -868,7 +868,7 @@ class ExtraInfoDescriptor(Descriptor):
     else:
       self._entries = entries
 
-  def digest(self, hash_type = DigestHashType.SHA1):
+  def digest(self, hash_type = DigestHash.SHA1):
     """
     Provides the upper-case hex encoded sha1 of our content. This value is part
     of the server descriptor entry for this relay.
@@ -876,7 +876,7 @@ class ExtraInfoDescriptor(Descriptor):
     .. versionchanged:: 1.8.0
        Added the hash_type argument.
 
-    :param stem.descriptor.DigestHashType hash_type: digest hashing algorithm
+    :param stem.descriptor.DigestHash hash_type: digest hashing algorithm
 
     :returns: **str** with the upper-case hex digest value for this server
       descriptor
@@ -953,14 +953,14 @@ class RelayExtraInfoDescriptor(ExtraInfoDescriptor):
     return cls(cls.content(attr, exclude, sign, signing_key), validate = validate)
 
   @lru_cache()
-  def digest(self, hash_type = DigestHashType.SHA1):
-    if hash_type == DigestHashType.SHA1:
+  def digest(self, hash_type = DigestHash.SHA1):
+    if hash_type == DigestHash.SHA1:
       # our digest is calculated from everything except our signature
 
       raw_content, ending = str(self), '\nrouter-signature\n'
       raw_content = stem.util.str_tools._to_bytes(raw_content[:raw_content.find(ending) + len(ending)])
       return hashlib.sha1(raw_content).hexdigest().upper()
-    elif hash_type == DigestHashType.SHA256:
+    elif hash_type == DigestHash.SHA256:
       # Due to a tor bug sha256 digests are calculated from the
       # whole descriptor rather than ommiting the signature...
       #
@@ -1013,10 +1013,10 @@ class BridgeExtraInfoDescriptor(ExtraInfoDescriptor):
       ('router-digest', _random_fingerprint()),
     ))
 
-  def digest(self, hash_type = DigestHashType.SHA1):
-    if hash_type == DigestHashType.SHA1:
+  def digest(self, hash_type = DigestHash.SHA1):
+    if hash_type == DigestHash.SHA1:
       return self._digest
-    elif hash_type == DigestHashType.SHA256:
+    elif hash_type == DigestHash.SHA256:
       return self.router_digest_sha256
     else:
       raise NotImplementedError('Bridge extrainfo digests are only available in sha1 and sha256, not %s' % hash_type)
diff --git a/test/unit/descriptor/extrainfo_descriptor.py b/test/unit/descriptor/extrainfo_descriptor.py
index 7a85dd06..f4823c72 100644
--- a/test/unit/descriptor/extrainfo_descriptor.py
+++ b/test/unit/descriptor/extrainfo_descriptor.py
@@ -53,8 +53,8 @@ k0d2aofcVbHr4fPQOSST0LXDrhFl5Fqo5um296zpJGvRUeO6S44U/EfJAGShtqWw
     self.assertEqual(datetime.datetime(2012, 5, 5, 17, 2, 45), desc.dir_write_history_end)
     self.assertEqual(900, desc.dir_write_history_interval)
     self.assertEqual(expected_signature, desc.signature)
-    self.assertEqual('00A57A9AAB5EA113898E2DD02A755E31AFC27227', desc.digest(stem.descriptor.DigestHashType.SHA1))
-    self.assertEqual('n2+wh6uM+lbKnhbkOog2jv9X5tPytlrFdO+I+auSmME', desc.digest(stem.descriptor.DigestHashType.SHA256))
+    self.assertEqual('00A57A9AAB5EA113898E2DD02A755E31AFC27227', desc.digest(stem.descriptor.DigestHash.SHA1))
+    self.assertEqual('n2+wh6uM+lbKnhbkOog2jv9X5tPytlrFdO+I+auSmME', desc.digest(stem.descriptor.DigestHash.SHA256))
     self.assertEqual([], desc.get_unrecognized_lines())
 
     # The read-history, write-history, dirreq-read-history, and





More information about the tor-commits mailing list