[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [stem/master] Use binascii.b2a_hex instead of hand-tweaked string concatenation



commit fa5bd4c0522afa46156f05858d8fccd6b6d87dfc
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date:   Wed Aug 13 20:44:14 2014 -0400

    Use binascii.b2a_hex instead of hand-tweaked string concatenation
    
    This is a major performance win for parsing.
---
 stem/descriptor/router_status_entry.py |   16 +---------------
 1 file changed, 1 insertion(+), 15 deletions(-)

diff --git a/stem/descriptor/router_status_entry.py b/stem/descriptor/router_status_entry.py
index c1003d7..ee18705 100644
--- a/stem/descriptor/router_status_entry.py
+++ b/stem/descriptor/router_status_entry.py
@@ -715,8 +715,6 @@ def _base64_to_hex(identity, validate, check_if_fingerprint = True):
   missing_padding = len(identity) % 4
   identity += '=' * missing_padding
 
-  fingerprint = ''
-
   try:
     identity_decoded = base64.b64decode(stem.util.str_tools._to_bytes(identity))
   except (TypeError, binascii.Error):
@@ -725,19 +723,7 @@ def _base64_to_hex(identity, validate, check_if_fingerprint = True):
 
     raise ValueError("Unable to decode identity string '%s'" % identity)
 
-  for char in identity_decoded:
-    # Individual characters are either standard ASCII or hex encoded, and each
-    # represent two hex digits. For instance...
-    #
-    # >>> ord('\n')
-    # 10
-    # >>> hex(10)
-    # '0xa'
-    # >>> '0xa'[2:].zfill(2).upper()
-    # '0A'
-
-    char_int = char if isinstance(char, int) else ord(char)
-    fingerprint += hex(char_int)[2:].zfill(2).upper()
+  fingerprint = binascii.b2a_hex(identity_decoded).upper()
 
   if check_if_fingerprint:
     if not stem.util.tor_tools.is_valid_fingerprint(fingerprint):



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits