[tor-commits] [gettor/master] Changed sha1 to sha256 (dunno why I used sha1...)

ilv at torproject.org ilv at torproject.org
Tue Sep 22 23:39:12 UTC 2015


commit 6649daa414fc11d50fb83745f10b9cba060fb2d1
Author: ilv <ilv at users.noreply.github.com>
Date:   Wed Aug 6 23:20:59 2014 -0400

    Changed sha1 to sha256 (dunno why I used sha1...)
---
 src/dropbox.py     |   10 +++++-----
 src/gettor/smtp.py |   20 ++++++++++----------
 src/gettor/xmpp.py |   12 ++++++------
 3 files changed, 21 insertions(+), 21 deletions(-)

diff --git a/src/dropbox.py b/src/dropbox.py
index 1be1ae8..2b619d3 100644
--- a/src/dropbox.py
+++ b/src/dropbox.py
@@ -45,8 +45,8 @@ def get_bundle_info(file):
     else:
         raise ValueError("Bundle invalid format %s" % file)
 
-def get_file_sha1(file):
-    """Get the sha1 of a file.
+def get_file_sha256(file):
+    """Get the sha256 of a file.
     
     Desc.
     
@@ -54,7 +54,7 @@ def get_file_sha1(file):
     
     # as seen on the internet
     BLOCKSIZE = 65536
-    hasher = hashlib.sha1()
+    hasher = hashlib.sha256()
     with open(file, 'rb') as afile:
         buf = afile.read(BLOCKSIZE)
         while len(buf) > 0:
@@ -143,12 +143,12 @@ if __name__ == '__main__':
             abs_file = os.path.abspath(os.path.join(upload_dir, file))
             abs_asc = os.path.abspath(os.path.join(upload_dir, asc))
             
-            sha1_file = get_file_sha1(abs_file)
+            sha_file = get_file_sha256(abs_file)
             
             # build links
             link_file = client.share(file)
             link_asc = client.share(asc)
-            link = link_file[u'url'] + ' ' + link_asc[u'url'] + ' ' + sha1_file
+            link = link_file[u'url'] + ' ' + link_asc[u'url'] + ' ' + sha_file
             
             # add links
             operating_system, locale = get_bundle_info(file)
diff --git a/src/gettor/smtp.py b/src/gettor/smtp.py
index 50d26a0..b563600 100644
--- a/src/gettor/smtp.py
+++ b/src/gettor/smtp.py
@@ -133,18 +133,18 @@ class SMTP(object):
         logger.propagate = False
         self.logger.debug("New smtp object created")
 
-    def _get_sha1(self, string):
-        """Get sha1 of a string.
+    def _get_sha256(self, string):
+        """Get sha256 of a string.
 
         Used whenever we want to do things with addresses (log, blacklist,
         etc.)
 
-        Params: The string to be sha1'ed.
+        Params: The string to be hashed.
 
-        Returns: sha1 of string.
+        Returns: sha256 of string.
 
         """
-        return str(hashlib.sha1(string).hexdigest())
+        return str(hashlib.sha256(string).hexdigest())
 
     def _log_request(self, addr, raw_msg):
         """Log a request.
@@ -163,9 +163,9 @@ class SMTP(object):
         # to do: obtain content of msg, not the entire email
         content = raw_msg
 
-        # We store the sha1 of the original address in order to know when
+        # We store the sha256 of the original address in order to know when
         # specific addresses are doing weird requests
-        log_addr = self._get_sha1(addr)
+        log_addr = self._get_sha256(addr)
         filename = str(time.time()) + '.log'
         path = self.logdir_emails + filename
         abs_path = os.path.abspath(path)
@@ -191,7 +191,7 @@ class SMTP(object):
         Params: addr - the address we want to check.
 
         """
-        anon_addr = self._get_sha1(addr)
+        anon_addr = self._get_sha256(addr)
         self.logger.debug("Checking if address %s is blacklisted" %
                           anon_addr)
 
@@ -242,7 +242,7 @@ class SMTP(object):
             m = re.search(r'<([^>]*)>', addr)
             if m is None:
                 raise AddressError("Couldn't extract normalized address "
-                                   "from %s" % self_get_sha1(addr))
+                                   "from %s" % self_get_sha256(addr))
             addr = m.group(1)
         return addr
 
@@ -542,7 +542,7 @@ class SMTP(object):
 
         if norm_from_addr:
             try:
-                self._check_blacklist(self._get_sha1(norm_from_addr))
+                self._check_blacklist(self._get_sha256(norm_from_addr))
             except BlacklistError as e:
                 # This shouldn't stop us from receiving other requests
                 self.logger.warning(str(e))
diff --git a/src/gettor/xmpp.py b/src/gettor/xmpp.py
index b1239c9..9c4bb89 100644
--- a/src/gettor/xmpp.py
+++ b/src/gettor/xmpp.py
@@ -169,18 +169,18 @@ class XMPP(object):
         xmpp.connect()
         xmpp.process(block=True)
 
-    def _get_sha1(self, string):
-        """Get sha1 of a string.
+    def _get_sha256(self, string):
+        """Get sha256 of a string.
 
         Used whenever we want to do things with accounts (log, blacklist,
         etc.)
 
-        Params: The string to be sha1'ed.
+        Params: The string to be hashed.
 
-        Returns: sha1 of string.
+        Returns: sha256 of string.
 
         """
-        return str(hashlib.sha1(string).hexdigest())
+        return str(hashlib.sha256(string).hexdigest())
 
     def _check_blacklist(self, account):
         """Check if an account is blacklisted.
@@ -192,7 +192,7 @@ class XMPP(object):
         Params: account - the account we want to check.
 
         """
-        anon_account = self._get_sha1(account)
+        anon_account = self._get_sha256(account)
         self.logger.debug("Checking if address %s is blacklisted" %
                           anon_account)
 





More information about the tor-commits mailing list