[Python-checkins] CVS: python/dist/src/Modules md5module.c,2.22,2.23

Barry Warsaw python-dev@python.org
Mon, 14 Aug 2000 22:59:46 -0700


Update of /cvsroot/python/python/dist/src/Modules
In directory slayer.i.sourceforge.net:/tmp/cvs-serv26746

Modified Files:
	md5module.c 
Log Message:
md5_hexdigest(): After a brief conversation with TP, added hexdigest()
to this module to mirror sha's hexdigest() method.


Index: md5module.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/md5module.c,v
retrieving revision 2.22
retrieving revision 2.23
diff -C2 -r2.22 -r2.23
*** md5module.c	2000/08/03 02:34:44	2.22
--- md5module.c	2000/08/15 05:59:44	2.23
***************
*** 82,87 ****
  md5_digest(md5object *self, PyObject *args)
  {
! 
! 	MD5_CTX mdContext;
  	unsigned char aDigest[16];
  
--- 82,86 ----
  md5_digest(md5object *self, PyObject *args)
  {
!  	MD5_CTX mdContext;
  	unsigned char aDigest[16];
  
***************
*** 105,108 ****
--- 104,142 ----
  
  static PyObject *
+ md5_hexdigest(md5object *self, PyObject *args)
+ {
+  	MD5_CTX mdContext;
+ 	unsigned char digest[16];
+ 	unsigned char hexdigest[32];
+ 	int i, j;
+ 
+ 	if (!PyArg_NoArgs(args))
+ 		return NULL;
+ 
+ 	/* make a temporary copy, and perform the final */
+ 	mdContext = self->md5;
+ 	MD5Final(digest, &mdContext);
+ 
+ 	/* Make hex version of the digest */
+ 	for(i=j=0; i<16; i++) {
+ 		char c;
+ 		c = (digest[i] >> 4) & 0xf;
+ 		c = (c>9) ? c+'a'-10 : c + '0';
+ 		hexdigest[j++] = c;
+ 		c = (digest[i] & 0xf);
+ 		c = (c>9) ? c+'a'-10 : c + '0';
+ 		hexdigest[j++] = c;
+ 	}
+ 	return PyString_FromStringAndSize((char*)hexdigest, 32);
+ }
+ 
+ 
+ static char hexdigest_doc [] =
+ "hexdigest() -> string\n\
+ \n\
+ Like digest(), but returns the digest as a string of hexadecimal digits.";
+ 
+ 
+ static PyObject *
  md5_copy(md5object *self, PyObject *args)
  {
***************
*** 127,137 ****
  
  static PyMethodDef md5_methods[] = {
! 	{"update",		(PyCFunction)md5_update, 
! 	 METH_OLDARGS, update_doc},
! 	{"digest",		(PyCFunction)md5_digest, 
! 	 METH_OLDARGS, digest_doc},
! 	{"copy",		(PyCFunction)md5_copy, 
! 	 METH_OLDARGS, copy_doc},
! 	{NULL,			NULL}		/* sentinel */
  };
  
--- 161,169 ----
  
  static PyMethodDef md5_methods[] = {
! 	{"update",    (PyCFunction)md5_update,    METH_OLDARGS, update_doc},
! 	{"digest",    (PyCFunction)md5_digest,    METH_OLDARGS, digest_doc},
! 	{"hexdigest", (PyCFunction)md5_hexdigest, METH_OLDARGS, hexdigest_doc},
! 	{"copy",      (PyCFunction)md5_copy,      METH_OLDARGS, copy_doc},
! 	{NULL, NULL}			     /* sentinel */
  };