From e48d4edfb8975aa7bf8d623282941ffcd8f24ba1 Mon Sep 17 00:00:00 2001
From: Andreas Jung <yet@gmx.de>
Date: Mon, 30 Mar 2009 20:40:10 +0000
Subject: [PATCH] using ZEO.hash

---
 src/ZEO/hash.py                 | 29 +++++++++++++++++++++++++++++
 src/ZEO/tests/auth_plaintext.py | 10 ++++------
 2 files changed, 33 insertions(+), 6 deletions(-)
 create mode 100644 src/ZEO/hash.py

diff --git a/src/ZEO/hash.py b/src/ZEO/hash.py
new file mode 100644
index 00000000..4dfac764
--- /dev/null
+++ b/src/ZEO/hash.py
@@ -0,0 +1,29 @@
+##############################################################################
+#
+# Copyright (c) 2008 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+
+"""In Python 2.6, the "sha" and "md5" modules have been deprecated
+in favor of using hashlib for both. This class allows for compatibility
+between versions."""
+
+import sys
+
+if sys.version_info[:2] >= (2, 6):
+    import hashlib
+    sha1 = hashlib.sha1
+    new = sha1
+else:
+    import sha
+    sha1 = sha.new
+    new = sha1
+    digest_size = sha.digest_size
diff --git a/src/ZEO/tests/auth_plaintext.py b/src/ZEO/tests/auth_plaintext.py
index 0d6fc4d8..b7e8ccd0 100644
--- a/src/ZEO/tests/auth_plaintext.py
+++ b/src/ZEO/tests/auth_plaintext.py
@@ -19,17 +19,15 @@ This mechanism offers *no network security at all*; the only security
 is provided by not storing plaintext passwords on disk.
 """
 
-try:
-    from hashlib import sha1 as sha
-except ImportError:
-    import sha
 
 from ZEO.StorageServer import ZEOStorage
 from ZEO.auth import register_module
 from ZEO.auth.base import Client, Database
 
+from ZEO.hash import sha1
+
 def session_key(username, realm, password):
-    return sha.new("%s:%s:%s" % (username, realm, password)).hexdigest()
+    return sha1.new("%s:%s:%s" % (username, realm, password)).hexdigest()
 
 class StorageClass(ZEOStorage):
 
@@ -39,7 +37,7 @@ class StorageClass(ZEOStorage):
         except LookupError:
             return 0
 
-        password_dig = sha.new(password).hexdigest()
+        password_dig = sha1.new(password).hexdigest()
         if dbpw == password_dig:
             self.connection.setSessionKey(session_key(username,
                                                       self.database.realm,
-- 
2.30.9