Update of /cvsroot/tmda/tmda/TMDA
In directory usw-pr-cvs1:/tmp/cvs-serv11693/TMDA
Modified Files:
ChangeLog Cookie.py Defaults.py Util.py
Log Message:
Python2ism.
The hexlify and unhexlify functions from Util are no longer necessary.
Instead we use the analogous functions from the binascii module which
are more efficient since the module is written in C.
Index: ChangeLog
===================================================================
RCS file: /cvsroot/tmda/tmda/TMDA/ChangeLog,v
retrieving revision 1.132
retrieving revision 1.133
diff -u -r1.132 -r1.133
--- ChangeLog 2002/01/29 20:48:48 1.132
+++ ChangeLog 2002/01/31 01:18:51 1.133
@@ -1,3 +1,20 @@
+2002-01-30 Jason R. Mastaler <jasonrm@xxxxxxxxxxxxxxxxxxxxxxxxxx>
+
+ * Defaults.py (CRYPT_KEY): Use binascii.unhexlify instead of
+ Util.unhexlify.
+
+ * Cookie.py (confirmationmac): Use binascii.hexlify instead of
+ Util.hexlify.
+
+ (datemac): Ditto.
+
+ (make_sender_cookie): Ditto.
+
+ (make_keywordmac): Ditto.
+
+ * Util.py: Remove hexlify and unhexlify functions; use the
+ binascii module instead.
+
2002-01-29 Jason R. Mastaler <jasonrm@xxxxxxxxxxxxxxxxxxxxxxxxxx>
* Defaults.py: Add a new variable PARENTDIR that refers to the
Index: Cookie.py
===================================================================
RCS file: /cvsroot/tmda/tmda/TMDA/Cookie.py,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- Cookie.py 2001/12/17 23:31:47 1.14
+++ Cookie.py 2002/01/31 01:18:51 1.15
@@ -4,6 +4,7 @@
import base64
+import binascii
import os
import re
import string
@@ -22,7 +23,7 @@
chmac.update(pid)
if keyword:
chmac.update(keyword)
- return Util.hexlify(chmac.digest()[:Defaults.HMAC_BYTES])
+ return binascii.hexlify(chmac.digest()[:Defaults.HMAC_BYTES])
def make_confirm_cookie(time,pid,keyword=None):
@@ -46,7 +47,7 @@
def datemac(time):
"""Expects time as a string, and returns an HMAC in hex."""
datemac = HMAC.new(Defaults.CRYPT_KEY,time).digest()[:Defaults.HMAC_BYTES]
- return Util.hexlify(datemac)
+ return binascii.hexlify(datemac)
def make_dated_cookie(time):
@@ -73,7 +74,7 @@
address = string.lower(address)
sender_cookie = HMAC.new(Defaults.CRYPT_KEY,
address).digest()[:Defaults.HMAC_BYTES]
- return Util.hexlify(sender_cookie)
+ return binascii.hexlify(sender_cookie)
def make_sender_address(address, sender):
@@ -88,7 +89,7 @@
def make_keywordmac(keyword):
"""Expects a keyword as a string, returns an HMAC in hex."""
keywordmac = HMAC.new(Defaults.CRYPT_KEY,
keyword).digest()[:Defaults.HMAC_BYTES]
- return Util.hexlify(keywordmac)
+ return binascii.hexlify(keywordmac)
def make_keyword_cookie(keyword):
Index: Defaults.py
===================================================================
RCS file: /cvsroot/tmda/tmda/TMDA/Defaults.py,v
retrieving revision 1.98
retrieving revision 1.99
diff -u -r1.98 -r1.99
--- Defaults.py 2002/01/29 21:10:54 1.98
+++ Defaults.py 2002/01/31 01:18:51 1.99
@@ -3,6 +3,7 @@
"""TMDA configuration variable defaults."""
+import binascii
import os
import stat
import string
@@ -238,8 +239,8 @@
else:
# Convert key from hex back into raw binary.
# Hex has only 4 bits of entropy per byte as opposed to 8.
- CRYPT_KEY = Util.unhexlify(CRYPT_KEY)
-
+ CRYPT_KEY = binascii.unhexlify(CRYPT_KEY)
+
# FILTER_INCOMING
# Filter file which controls how incoming messages are tagged.
# Default is ~/.tmda/filters/incoming
Index: Util.py
===================================================================
RCS file: /cvsroot/tmda/tmda/TMDA/Util.py,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -r1.29 -r1.30
--- Util.py 2002/01/22 18:53:56 1.29
+++ Util.py 2002/01/31 01:18:51 1.30
@@ -3,6 +3,7 @@
"""General purpose functions."""
+import binascii
import fileinput
import fnmatch
import os
@@ -12,21 +13,6 @@
import sys
import time
import types
-
-
-def hexlify(b):
- """Return the hexadecimal representation of the binary data."""
- return "%02x"*len(b) % tuple(map(ord, b))
-
-
-def unhexlify(s):
- """Return the binary data represented by the hexadecimal string."""
- acc = []
- append = acc.append
- int16 = string.atoi
- for i in range(0, len(s), 2):
- append(chr(int16(s[i:i+2], 16)))
- return string.join(acc, '')
def gethostname():
_______________________________________________
tmda-cvs mailing list
http://libertine.org/lists/listinfo/tmda-cvs
|