diff options
author | Jacek Konieczny <jajcus@jajcus.net> | 2008-12-05 21:25:45 +0300 |
---|---|---|
committer | Jacek Konieczny <jajcus@jajcus.net> | 2008-12-05 21:25:45 +0300 |
commit | b2144632a4451c575e680e2c2f6f8d5ece49cb32 (patch) | |
tree | 02ada5db00a2a5ec72df3886982d2a77165daf1e /pyxmpp | |
parent | 33d040802518476f7a3e6aa822bfb3b2cae2d37c (diff) |
- Python 2.6 update: use 'hashlib' module instead of 'md5' and 'sha' when available
Diffstat (limited to 'pyxmpp')
-rw-r--r-- | pyxmpp/jabber/clientstream.py | 14 | ||||
-rw-r--r-- | pyxmpp/sasl/digest_md5.py | 10 |
2 files changed, 19 insertions, 5 deletions
diff --git a/pyxmpp/jabber/clientstream.py b/pyxmpp/jabber/clientstream.py index 927e9d1..9d888b3 100644 --- a/pyxmpp/jabber/clientstream.py +++ b/pyxmpp/jabber/clientstream.py @@ -23,7 +23,13 @@ Normative reference: __revision__="$Id$" __docformat__="restructuredtext en" -import sha +try: + import hashlib + sha_factory = hashlib.sha1 +except ImportError: + import sha + sha_factory = sha.new + import logging from pyxmpp.iq import Iq @@ -315,7 +321,9 @@ class LegacyClientStream(ClientStream): q=iq.new_query("jabber:iq:auth") q.newTextChild(None,"username",to_utf8(self.my_jid.node)) q.newTextChild(None,"resource",to_utf8(self.my_jid.resource)) - digest=sha.new(to_utf8(self.stream_id)+to_utf8(self.password)).hexdigest() + + digest = sha_factory(to_utf8(self.stream_id)+to_utf8(self.password)).hexdigest() + q.newTextChild(None,"digest",digest) self.send(iq) self.set_response_handlers(iq,self.auth_finish,self.auth_error) @@ -343,7 +351,7 @@ class LegacyClientStream(ClientStream): self.send(iq) return - mydigest=sha.new(to_utf8(self.stream_id)+to_utf8(password)).hexdigest() + mydigest = sha_factory(to_utf8(self.stream_id)+to_utf8(password)).hexdigest() if mydigest==digest: iq=stanza.make_result_response() diff --git a/pyxmpp/sasl/digest_md5.py b/pyxmpp/sasl/digest_md5.py index 1f1722c..4552b03 100644 --- a/pyxmpp/sasl/digest_md5.py +++ b/pyxmpp/sasl/digest_md5.py @@ -25,9 +25,15 @@ __docformat__="restructuredtext en" from binascii import b2a_hex import re -import md5 import logging +try: + import hashlib + md5_factory = hashlib.md5 +except: + import md5 + md5_factory = md5.new + from pyxmpp.sasl.core import ClientAuthenticator,ServerAuthenticator from pyxmpp.sasl.core import Failure,Response,Challenge,Success,Failure @@ -78,7 +84,7 @@ def _h_value(s): :return: MD5 sum of the string. :returntype: `str`""" - return md5.new(s).digest() + return md5_factory(s).digest() def _kd_value(k,s): """KD function of the DIGEST-MD5 algorithm. |