Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 19 Jun 2009 12:07:09 GMT
From:      Keith Gaughan <kmgaughan@eircom.net>
To:        freebsd-gnats-submit@FreeBSD.org
Subject:   ports/135832: security/py-pycrypto: Deprecation warnings when used with Python 2.6.
Message-ID:  <200906191207.n5JC79aM093363@www.freebsd.org>
Resent-Message-ID: <200906191210.n5JCA8Sf031403@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         135832
>Category:       ports
>Synopsis:       security/py-pycrypto: Deprecation warnings when used with Python 2.6.
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-ports-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Fri Jun 19 12:10:08 UTC 2009
>Closed-Date:
>Last-Modified:
>Originator:     Keith Gaughan
>Release:        FreeBSD 7.1
>Organization:
>Environment:
FreeBSD lir 7.1-RELEASE FreeBSD 7.1-RELEASE #0: Thu Jan  1 14:37:25 UTC 2009     root@logan.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC  i386
>Description:
While the md5 and sha modules have been regarded as deprecated for quite some time now, it's only in Python 2.6 that importing these modules rather than using hashlib has started giving deprecation warnings. Quite a number of python ports use pycrypto, so anybody who's now using Python 2.6 will see lots of deprecations warnings concerning these two modules.

The affected files in pycrypto are lib/Crypto/Hash/SHA.py and lib/Crypto/Hash/MD5.py
>How-To-Repeat:
Install security/py-pycrypto with Python 2.6, and do the following:

$ python
>Fix:
A patch to modify these two modules to use hashlib if possible is attached. it patches them to be practically identical (save some differing whitespace and comments) to the same modules in the current development branch of pycrypto at http://gitweb.pycrypto.org/?p=crypto/pycrypto-2.x.git;a=summary

The patch may be safely used with Python 2.5 and after.

Patch attached with submission follows:

--- MD5.py.orig	2009-06-19 12:46:41.000000000 +0100
+++ MD5.py	2009-06-19 12:50:24.000000000 +0100
@@ -3,11 +3,20 @@
 
 __revision__ = "$Id: MD5.py,v 1.4 2002/07/11 14:31:19 akuchling Exp $"
 
-from md5 import *
+__all__ = ['new', 'digest_size']
 
-import md5
-if hasattr(md5, 'digestsize'):
-    digest_size = digestsize
-    del digestsize
-del md5
 
+try:
+    # The md5 module is deprecated in Python 2.6, so use hashlib when possible.
+    import hashlib
+    def new(data=""):
+        return hashlib.md5(data)
+    digest_size = new().digest_size
+
+except ImportError:
+    from md5 import *
+    import md5
+    if hasattr(md5, 'digestsize'):
+        digest_size = digestsize
+        del digestsize
+    del md5
--- SHA.py.orig	2009-06-19 12:46:52.000000000 +0100
+++ SHA.py	2009-06-19 12:49:49.000000000 +0100
@@ -3,9 +3,20 @@
 
 __revision__ = "$Id: SHA.py,v 1.4 2002/07/11 14:31:19 akuchling Exp $"
 
-from sha import *
-import sha
-if hasattr(sha, 'digestsize'):
-    digest_size = digestsize
-    del digestsize
-del sha
+__all__ = ['new', 'digest_size']
+
+
+try:
+    # The md5 module is deprecated in Python 2.6, so use hashlib when possible.
+    import hashlib
+    def new(data=""):
+        return hashlib.sha1(data)
+    digest_size = new().digest_size
+
+except ImportError:
+    from sha import *
+    import sha
+    if hasattr(sha, 'digestsize'):
+        digest_size = digestsize
+        del digestsize
+    del sha


>Release-Note:
>Audit-Trail:
>Unformatted:
 >>> import Crypto.Hash.SHA
 
 This will give the warning "/usr/local/lib/python2.6/site-packages/Crypto/Hash/SHA.py:6: DeprecationWarning: the sha module is deprecated; use the hashlib module instead"



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200906191207.n5JC79aM093363>