[tor-commits] [stem/master] Retaining padding in the server descriptor digest() funciton

atagar at torproject.org atagar at torproject.org
Tue Apr 17 15:48:47 UTC 2012


commit 21228b096617abbaabc1d53ca964b8cad591bf88
Author: Damian Johnson <atagar at torproject.org>
Date:   Tue Apr 17 08:47:19 2012 -0700

    Retaining padding in the server descriptor digest() funciton
    
    Network status entries exclude base64 padding to save on space but there's no
    reason for us to do the same. Adding a comment explaining why they might
    mismatch. Thanks to Karsten for explaining it!
---
 stem/descriptor/server_descriptor.py       |   12 +++++-------
 test/integ/descriptor/server_descriptor.py |    2 +-
 2 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/stem/descriptor/server_descriptor.py b/stem/descriptor/server_descriptor.py
index 525322c..7823cf0 100644
--- a/stem/descriptor/server_descriptor.py
+++ b/stem/descriptor/server_descriptor.py
@@ -615,6 +615,10 @@ class RelayDescriptorV3(ServerDescriptorV3):
     Provides the base64 encoded sha1 of our content. This value is part of the
     server descriptor entry for this relay.
     
+    Note that network status entries exclude the padding, so you'll need to add
+    a '=' to it so they'll match...
+    https://en.wikipedia.org/wiki/Base64#Padding
+    
     Returns:
       str with the digest value for this server descriptor
     """
@@ -625,13 +629,7 @@ class RelayDescriptorV3(ServerDescriptorV3):
       raw_content = raw_content[:raw_content.find(ending) + len(ending)]
       
       digest_sha1 = hashlib.sha1(raw_content).digest()
-      digest = base64.b64encode(digest_sha1)
-      
-      # TODO: I'm not sure why but the base64 decodings have an anomalous '='
-      # ending which the network status entries don't have. Tad puzzled, but
-      # for now stripping it so we match.
-      
-      self._digest = digest[:-1]
+      self._digest = base64.b64encode(digest_sha1)
     
     return self._digest
   
diff --git a/test/integ/descriptor/server_descriptor.py b/test/integ/descriptor/server_descriptor.py
index bd270b4..ee099b4 100644
--- a/test/integ/descriptor/server_descriptor.py
+++ b/test/integ/descriptor/server_descriptor.py
@@ -103,7 +103,7 @@ Qlx9HNCqCY877ztFRC624ja2ql6A2hBcuoYMbkHjcQ4=
     self.assertEquals(expected_signing_key, desc.signing_key)
     self.assertEquals(expected_signature, desc.signature)
     self.assertEquals([], desc.get_unrecognized_lines())
-    self.assertEquals("LHsnvqsEtOJFnYnKbVzRzF+Vpok", desc.digest())
+    self.assertEquals("LHsnvqsEtOJFnYnKbVzRzF+Vpok" + "=", desc.digest())
   
   def test_old_descriptor(self):
     """



More information about the tor-commits mailing list