[yum-git] Branch 'yum-3_2_X' - yum/misc.py

James Antill james at linux.duke.edu
Tue Jul 22 17:41:14 UTC 2008


 yum/misc.py |   15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

New commits:
commit e487f1e276838563cc81e8fa8fa02c76c6c9991b
Author: James Antill <james at and.org>
Date:   Tue Jul 22 13:39:10 2008 -0400

    Move to using hashlib directly in checksum, also add sha256/sha512 options

diff --git a/yum/misc.py b/yum/misc.py
index caae307..74bab1e 100644
--- a/yum/misc.py
+++ b/yum/misc.py
@@ -20,6 +20,7 @@ try:
     import gpgme
 except ImportError:
     gpgme = None
+import hashlib
 
 from Errors import MiscError
 
@@ -143,7 +144,7 @@ def unique(s):
 
 def checksum(sumtype, file, CHUNK=2**16):
     """takes filename, hand back Checksum of it
-       sumtype = md5 or sha
+       sumtype = md5 or sha/sha1/sha256/sha512 (note sha == sha1)
        filename = /path/to/file
        CHUNK=65536 by default"""
      
@@ -153,13 +154,11 @@ def checksum(sumtype, file, CHUNK=2**16):
             fo = file # assume it's a file-like-object
         else:           
             fo = open(file, 'r', CHUNK)
-            
-        if sumtype == 'md5':
-            import md5
-            sumalgo = md5.new()
-        elif sumtype == 'sha':
-            import sha
-            sumalgo = sha.new()
+
+        if sumtype == 'sha':
+            sumtype = 'sha1'
+        if sumtype in ['md5', 'sha1', 'sha256', 'sha512']:
+            sumalgo = hashlib.new(sumtype)
         else:
             raise MiscError, 'Error Checksumming file, bad checksum type %s' % sumtype
         chunk = fo.read



More information about the Yum-cvs-commits mailing list