Update of /cvsroot/mailman/mailman/Mailman
In directory sc8-pr-cvs1:/tmp/cvs-serv6756
Modified Files:
Pending.py
Log Message:
new(): A Timbot approved, better random cookie generator.
Index: Pending.py
===================================================================
RCS file: /cvsroot/mailman/mailman/Mailman/Pending.py,v
retrieving revision 2.13
retrieving revision 2.14
diff -u -d -r2.13 -r2.14
--- Pending.py 21 Mar 2003 03:40:54 -0000 2.13
+++ Pending.py 8 Jul 2003 23:00:58 -0000 2.14
@@ -49,6 +49,12 @@
RE_ENABLE,
)]
+try:
+ True, False
+except NameError:
+ True = 1
+ False = 0
+
def new(*content):
@@ -73,12 +79,20 @@
continue
# Load the current database
db = _load()
- # Calculate a unique cookie
- while 1:
- n = random.random()
+ # Calculate a unique cookie. Algorithm vetted by the Timbot.
+ # time() has high resolution on Linux, clock() on Windows. random
+ # gives us about 45 bits in Python 2.2, 53 bits on Python 2.3.
+ # The time and clock values basically help obscure the random
+ # number generator, as does the hash calculation. The integral
+ # parts of the time values are discarded because they're the most
+ # predictable bits.
+ while True:
now = time.time()
- hashfood = str(now) + str(n) + str(content)
+ x = random.random() + now % 1.0 + time.clock() % 1.0
+ hashfood = repr(x)
cookie = sha.new(hashfood).hexdigest()
+ # We'll never get a duplicate, but we'll be anal about
+ # checking anyway.
if not db.has_key(cookie):
break
# Store the content, plus the time in the future when this entry
@@ -101,10 +115,10 @@
-def confirm(cookie, expunge=1):
+def confirm(cookie, expunge=True):
"""Return data for cookie, or None if not found.
- If optional expunge is true (the default), the record is also removed from
+ If optional expunge is True (the default), the record is also removed from
the database.
"""
if not expunge:
_______________________________________________
Mailman-checkins mailing list
[EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/mailman-checkins