[Patches] [ python-Patches-449757 ] digestsize variable for the md5 module

noreply@sourceforge.net noreply@sourceforge.net
Fri, 10 Aug 2001 08:41:11 -0700


Patches item #449757, was opened at 2001-08-10 02:52
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=305470&aid=449757&group_id=5470

Category: None
Group: None
Status: Open
>Resolution: Rejected
Priority: 3
Submitted By: Martin Sjögren (msjogren)
Assigned to: Nobody/Anonymous (nobody)
Summary: digestsize variable for the md5 module

Initial Comment:
The sha module has a digestsize constant (which is 20)
which makes it easy to know how large space to use
(e.g. in a database), while the md5 module doesn't. Yes
I know that it IS 16, but ideally, the two modules
would have the same interface and you could do tricks
like this:

insize = globals()[digestname].digestsize

So, I included a patch to md5module.c that adds a
digestsize constant both to the md5 objects and to the
module dictionary, as in the sha module.

----------------------------------------------------------------------

>Comment By: Guido van Rossum (gvanrossum)
Date: 2001-08-10 08:41

Message:
Logged In: YES 
user_id=6380

I'm for leaving well enough alone, and against code bloat. 
I would not have added those constants to sha, but I didn't
write it.  Your examples don't convince me -- they don't
seem very robust coding practices anyway.  Also, how often
do we grow new digest algorithms?


----------------------------------------------------------------------

Comment By: Martin Sjögren (msjogren)
Date: 2001-08-10 08:27

Message:
Logged In: YES 
user_id=80762

Yes, Python is a dynamic language. I think you missed my
'e.g. in a database'. In SQL you'd want create a column
"digest CHAR(nn)" and it would be nice to have the
flexibility of which digest algorithm to use. It is also
nice to know when you send a digest over a socket.

I'm not saying that this constant is vitally important to my
health! I'm saying that the sha module has it, and it would
be nice if the md5 module had it too! I'm quite aware that
the size of the digests are well-known, but instead of
having to do
    digestsizes = { 'md5': 16, 'sha': 20 }
myself, I don't see why Python can't provide those
constants. They are after all properties of the digest
algorithms!

Example: I get a message on a socket. All I know is that the
characters up to the first '\0' is the name of the digest
function used. I would like to do this:

import md5, sha
digests = { 'md5': md5, 'sha': sha } # using globals() is ugly
digest = sock.recv(digests[mdalg].digestsize)

I really don't see your problem with adding this constant.
With your argument you could as well remove the constant
from the sha module, but that would break backwards
compatability, so why not just add this constant and they'd
have more similar APIs?

----------------------------------------------------------------------

Comment By: Guido van Rossum (gvanrossum)
Date: 2001-08-10 06:27

Message:
Logged In: YES 
user_id=6380

Sorry, I fail to understand why knowing the return size in
advance is useful.  Python is a dynamic language -- why
would you have to allocate a fixed-size buffer?

----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=305470&aid=449757&group_id=5470