Mercurial > cpython-lru_cache-weakref
annotate Modules/md5module.c @ 80661:94de77bd0b4b 2.7
Issue #16194: document imp.load_dynamic problems
when read several extension modules from the same binary object file.
| author | Andrew Svetlov <andrew.svetlov@gmail.com> |
|---|---|
| date | Thu, 29 Nov 2012 19:51:28 +0200 |
| parents | 4d36e56b56d9 |
| children |
| rev | line source |
|---|---|
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
1 |
|
1132
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
2 /* MD5 module */ |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
3 |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
4 /* This module provides an interface to the RSA Data Security, |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
5 Inc. MD5 Message-Digest Algorithm, described in RFC 1321. |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
6 It requires the files md5c.c and md5.h (which are slightly changed |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
7 from the versions in the RFC to avoid the "global.h" file.) */ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
8 |
|
1132
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
9 |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
10 /* MD5 objects */ |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
11 |
| 4635 | 12 #include "Python.h" |
|
35375
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
29787
diff
changeset
|
13 #include "structmember.h" |
|
1132
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
14 #include "md5.h" |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
15 |
|
1132
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
16 typedef struct { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
17 PyObject_HEAD |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
18 md5_state_t md5; /* the context holder */ |
|
1132
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
19 } md5object; |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
20 |
|
24280
1598a1e473e2
staticforward bites the dust.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23832
diff
changeset
|
21 static PyTypeObject MD5type; |
|
1132
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
22 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
23 #define is_md5object(v) ((v)->ob_type == &MD5type) |
|
1132
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
24 |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
25 static md5object * |
|
13651
8a063423e0b7
Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
26 newmd5object(void) |
|
1132
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
27 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
28 md5object *md5p; |
|
1132
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
29 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
30 md5p = PyObject_New(md5object, &MD5type); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
31 if (md5p == NULL) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
32 return NULL; |
|
1132
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
33 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
34 md5_init(&md5p->md5); /* actual initialisation */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
35 return md5p; |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
36 } |
|
1132
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
37 |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
38 |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
39 /* MD5 methods */ |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
40 |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
41 static void |
| 13503 | 42 md5_dealloc(md5object *md5p) |
|
1132
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
43 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
44 PyObject_Del(md5p); |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
45 } |
|
1132
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
46 |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
47 |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
48 /* MD5 methods-as-attributes */ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
49 |
| 4635 | 50 static PyObject * |
| 13503 | 51 md5_update(md5object *self, PyObject *args) |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
52 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
58101
diff
changeset
|
53 Py_buffer view; |
|
78975
4d36e56b56d9
Closes #15910: MD5 and SHA1 crash when "updated" with strings bigger than 2**32 bytes
Jesus Cea <jcea@jcea.es>
parents:
77118
diff
changeset
|
54 Py_ssize_t n; |
|
4d36e56b56d9
Closes #15910: MD5 and SHA1 crash when "updated" with strings bigger than 2**32 bytes
Jesus Cea <jcea@jcea.es>
parents:
77118
diff
changeset
|
55 unsigned char *buf; |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
56 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
58101
diff
changeset
|
57 if (!PyArg_ParseTuple(args, "s*:update", &view)) |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
58 return NULL; |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
59 |
|
78975
4d36e56b56d9
Closes #15910: MD5 and SHA1 crash when "updated" with strings bigger than 2**32 bytes
Jesus Cea <jcea@jcea.es>
parents:
77118
diff
changeset
|
60 n = view.len; |
|
4d36e56b56d9
Closes #15910: MD5 and SHA1 crash when "updated" with strings bigger than 2**32 bytes
Jesus Cea <jcea@jcea.es>
parents:
77118
diff
changeset
|
61 buf = (unsigned char *) view.buf; |
|
4d36e56b56d9
Closes #15910: MD5 and SHA1 crash when "updated" with strings bigger than 2**32 bytes
Jesus Cea <jcea@jcea.es>
parents:
77118
diff
changeset
|
62 while (n > 0) { |
|
4d36e56b56d9
Closes #15910: MD5 and SHA1 crash when "updated" with strings bigger than 2**32 bytes
Jesus Cea <jcea@jcea.es>
parents:
77118
diff
changeset
|
63 Py_ssize_t nbytes; |
|
4d36e56b56d9
Closes #15910: MD5 and SHA1 crash when "updated" with strings bigger than 2**32 bytes
Jesus Cea <jcea@jcea.es>
parents:
77118
diff
changeset
|
64 if (n > INT_MAX) |
|
4d36e56b56d9
Closes #15910: MD5 and SHA1 crash when "updated" with strings bigger than 2**32 bytes
Jesus Cea <jcea@jcea.es>
parents:
77118
diff
changeset
|
65 nbytes = INT_MAX; |
|
4d36e56b56d9
Closes #15910: MD5 and SHA1 crash when "updated" with strings bigger than 2**32 bytes
Jesus Cea <jcea@jcea.es>
parents:
77118
diff
changeset
|
66 else |
|
4d36e56b56d9
Closes #15910: MD5 and SHA1 crash when "updated" with strings bigger than 2**32 bytes
Jesus Cea <jcea@jcea.es>
parents:
77118
diff
changeset
|
67 nbytes = n; |
|
4d36e56b56d9
Closes #15910: MD5 and SHA1 crash when "updated" with strings bigger than 2**32 bytes
Jesus Cea <jcea@jcea.es>
parents:
77118
diff
changeset
|
68 md5_append(&self->md5, buf, |
|
4d36e56b56d9
Closes #15910: MD5 and SHA1 crash when "updated" with strings bigger than 2**32 bytes
Jesus Cea <jcea@jcea.es>
parents:
77118
diff
changeset
|
69 Py_SAFE_DOWNCAST(nbytes, Py_ssize_t, unsigned int)); |
|
4d36e56b56d9
Closes #15910: MD5 and SHA1 crash when "updated" with strings bigger than 2**32 bytes
Jesus Cea <jcea@jcea.es>
parents:
77118
diff
changeset
|
70 buf += nbytes; |
|
4d36e56b56d9
Closes #15910: MD5 and SHA1 crash when "updated" with strings bigger than 2**32 bytes
Jesus Cea <jcea@jcea.es>
parents:
77118
diff
changeset
|
71 n -= nbytes; |
|
4d36e56b56d9
Closes #15910: MD5 and SHA1 crash when "updated" with strings bigger than 2**32 bytes
Jesus Cea <jcea@jcea.es>
parents:
77118
diff
changeset
|
72 } |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
73 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
58101
diff
changeset
|
74 PyBuffer_Release(&view); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
58101
diff
changeset
|
75 Py_RETURN_NONE; |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
76 } |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
77 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22709
diff
changeset
|
78 PyDoc_STRVAR(update_doc, |
|
9363
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
79 "update (arg)\n\ |
|
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
80 \n\ |
|
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
81 Update the md5 object with the string arg. Repeated calls are\n\ |
|
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
82 equivalent to a single call with the concatenation of all the\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22709
diff
changeset
|
83 arguments."); |
|
9363
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
84 |
|
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
85 |
| 4635 | 86 static PyObject * |
|
22561
043ad7adc896
Remove many uses of PyArg_NoArgs macro, change METH_OLDARGS to METH_NOARGS.
Neal Norwitz <nnorwitz@gmail.com>
parents:
21313
diff
changeset
|
87 md5_digest(md5object *self) |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
88 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
89 md5_state_t mdContext; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
90 unsigned char aDigest[16]; |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
91 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
92 /* make a temporary copy, and perform the final */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
93 mdContext = self->md5; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
94 md5_finish(&mdContext, aDigest); |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
95 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
96 return PyString_FromStringAndSize((char *)aDigest, 16); |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
97 } |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
98 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22709
diff
changeset
|
99 PyDoc_STRVAR(digest_doc, |
|
9363
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
100 "digest() -> string\n\ |
|
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
101 \n\ |
|
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
102 Return the digest of the strings passed to the update() method so\n\ |
| 29787 | 103 far. This is a 16-byte string which may contain non-ASCII characters,\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22709
diff
changeset
|
104 including null bytes."); |
|
9363
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
105 |
|
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
106 |
| 4635 | 107 static PyObject * |
|
22561
043ad7adc896
Remove many uses of PyArg_NoArgs macro, change METH_OLDARGS to METH_NOARGS.
Neal Norwitz <nnorwitz@gmail.com>
parents:
21313
diff
changeset
|
108 md5_hexdigest(md5object *self) |
|
13979
63de7f00b5bc
md5_hexdigest(): After a brief conversation with TP, added hexdigest()
Barry Warsaw <barry@python.org>
parents:
13820
diff
changeset
|
109 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
110 md5_state_t mdContext; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
111 unsigned char digest[16]; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
112 unsigned char hexdigest[32]; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
113 int i, j; |
|
13979
63de7f00b5bc
md5_hexdigest(): After a brief conversation with TP, added hexdigest()
Barry Warsaw <barry@python.org>
parents:
13820
diff
changeset
|
114 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
115 /* make a temporary copy, and perform the final */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
116 mdContext = self->md5; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
117 md5_finish(&mdContext, digest); |
|
13979
63de7f00b5bc
md5_hexdigest(): After a brief conversation with TP, added hexdigest()
Barry Warsaw <barry@python.org>
parents:
13820
diff
changeset
|
118 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
119 /* Make hex version of the digest */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
120 for(i=j=0; i<16; i++) { |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
121 char c; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
122 c = (digest[i] >> 4) & 0xf; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
123 c = (c>9) ? c+'a'-10 : c + '0'; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
124 hexdigest[j++] = c; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
125 c = (digest[i] & 0xf); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
126 c = (c>9) ? c+'a'-10 : c + '0'; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
127 hexdigest[j++] = c; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
128 } |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
129 return PyString_FromStringAndSize((char*)hexdigest, 32); |
|
13979
63de7f00b5bc
md5_hexdigest(): After a brief conversation with TP, added hexdigest()
Barry Warsaw <barry@python.org>
parents:
13820
diff
changeset
|
130 } |
|
63de7f00b5bc
md5_hexdigest(): After a brief conversation with TP, added hexdigest()
Barry Warsaw <barry@python.org>
parents:
13820
diff
changeset
|
131 |
|
63de7f00b5bc
md5_hexdigest(): After a brief conversation with TP, added hexdigest()
Barry Warsaw <barry@python.org>
parents:
13820
diff
changeset
|
132 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22709
diff
changeset
|
133 PyDoc_STRVAR(hexdigest_doc, |
|
13979
63de7f00b5bc
md5_hexdigest(): After a brief conversation with TP, added hexdigest()
Barry Warsaw <barry@python.org>
parents:
13820
diff
changeset
|
134 "hexdigest() -> string\n\ |
|
63de7f00b5bc
md5_hexdigest(): After a brief conversation with TP, added hexdigest()
Barry Warsaw <barry@python.org>
parents:
13820
diff
changeset
|
135 \n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22709
diff
changeset
|
136 Like digest(), but returns the digest as a string of hexadecimal digits."); |
|
13979
63de7f00b5bc
md5_hexdigest(): After a brief conversation with TP, added hexdigest()
Barry Warsaw <barry@python.org>
parents:
13820
diff
changeset
|
137 |
|
63de7f00b5bc
md5_hexdigest(): After a brief conversation with TP, added hexdigest()
Barry Warsaw <barry@python.org>
parents:
13820
diff
changeset
|
138 |
|
63de7f00b5bc
md5_hexdigest(): After a brief conversation with TP, added hexdigest()
Barry Warsaw <barry@python.org>
parents:
13820
diff
changeset
|
139 static PyObject * |
|
22561
043ad7adc896
Remove many uses of PyArg_NoArgs macro, change METH_OLDARGS to METH_NOARGS.
Neal Norwitz <nnorwitz@gmail.com>
parents:
21313
diff
changeset
|
140 md5_copy(md5object *self) |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
141 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
142 md5object *md5p; |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
143 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
144 if ((md5p = newmd5object()) == NULL) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
145 return NULL; |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
146 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
147 md5p->md5 = self->md5; |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
148 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
149 return (PyObject *)md5p; |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
150 } |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
151 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22709
diff
changeset
|
152 PyDoc_STRVAR(copy_doc, |
|
9363
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
153 "copy() -> md5 object\n\ |
|
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
154 \n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22709
diff
changeset
|
155 Return a copy (``clone'') of the md5 object."); |
|
9363
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
156 |
|
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
157 |
| 4635 | 158 static PyMethodDef md5_methods[] = { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
159 {"update", (PyCFunction)md5_update, METH_VARARGS, update_doc}, |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
160 {"digest", (PyCFunction)md5_digest, METH_NOARGS, digest_doc}, |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
161 {"hexdigest", (PyCFunction)md5_hexdigest, METH_NOARGS, hexdigest_doc}, |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
162 {"copy", (PyCFunction)md5_copy, METH_NOARGS, copy_doc}, |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
163 {NULL, NULL} /* sentinel */ |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
164 }; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
165 |
| 4635 | 166 static PyObject * |
|
35375
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
29787
diff
changeset
|
167 md5_get_block_size(PyObject *self, void *closure) |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
29787
diff
changeset
|
168 { |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
29787
diff
changeset
|
169 return PyInt_FromLong(64); |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
29787
diff
changeset
|
170 } |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
29787
diff
changeset
|
171 |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
29787
diff
changeset
|
172 static PyObject * |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
29787
diff
changeset
|
173 md5_get_digest_size(PyObject *self, void *closure) |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
29787
diff
changeset
|
174 { |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
29787
diff
changeset
|
175 return PyInt_FromLong(16); |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
29787
diff
changeset
|
176 } |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
29787
diff
changeset
|
177 |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
29787
diff
changeset
|
178 static PyObject * |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
29787
diff
changeset
|
179 md5_get_name(PyObject *self, void *closure) |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
180 { |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
181 return PyString_FromStringAndSize("MD5", 3); |
|
35375
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
29787
diff
changeset
|
182 } |
|
20843
8d14f534a5c2
[Patch #476612] Add attributes from PEP247 to the md5 and sha modules
Andrew M. Kuchling <amk@amk.ca>
parents:
14375
diff
changeset
|
183 |
|
35375
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
29787
diff
changeset
|
184 static PyGetSetDef md5_getseters[] = { |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
29787
diff
changeset
|
185 {"digest_size", |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
29787
diff
changeset
|
186 (getter)md5_get_digest_size, NULL, |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
29787
diff
changeset
|
187 NULL, |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
29787
diff
changeset
|
188 NULL}, |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
29787
diff
changeset
|
189 {"block_size", |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
29787
diff
changeset
|
190 (getter)md5_get_block_size, NULL, |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
29787
diff
changeset
|
191 NULL, |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
29787
diff
changeset
|
192 NULL}, |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
29787
diff
changeset
|
193 {"name", |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
29787
diff
changeset
|
194 (getter)md5_get_name, NULL, |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
29787
diff
changeset
|
195 NULL, |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
29787
diff
changeset
|
196 NULL}, |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
29787
diff
changeset
|
197 /* the old md5 and sha modules support 'digest_size' as in PEP 247. |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
29787
diff
changeset
|
198 * the old sha module also supported 'digestsize'. ugh. */ |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
29787
diff
changeset
|
199 {"digestsize", |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
29787
diff
changeset
|
200 (getter)md5_get_digest_size, NULL, |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
29787
diff
changeset
|
201 NULL, |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
29787
diff
changeset
|
202 NULL}, |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
29787
diff
changeset
|
203 {NULL} /* Sentinel */ |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
29787
diff
changeset
|
204 }; |
|
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
29787
diff
changeset
|
205 |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
206 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22709
diff
changeset
|
207 PyDoc_STRVAR(module_doc, |
|
9363
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
208 "This module implements the interface to RSA's MD5 message digest\n\ |
|
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
209 algorithm (see also Internet RFC 1321). Its use is quite\n\ |
|
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
210 straightforward: use the new() to create an md5 object. You can now\n\ |
|
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
211 feed this object with arbitrary strings using the update() method, and\n\ |
|
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
212 at any point you can ask it for the digest (a strong kind of 128-bit\n\ |
|
13620
5b727ab37092
Spelling fixes supplied by Rob W. W. Hooft. All these are fixes in either
Thomas Wouters <thomas@python.org>
parents:
13503
diff
changeset
|
213 checksum, a.k.a. ``fingerprint'') of the concatenation of the strings\n\ |
|
9363
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
214 fed to it so far using the digest() method.\n\ |
|
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
215 \n\ |
|
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
216 Functions:\n\ |
|
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
217 \n\ |
|
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
218 new([arg]) -- return a new md5 object, initialized with arg if provided\n\ |
|
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
219 md5([arg]) -- DEPRECATED, same as new, but for compatibility\n\ |
|
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
220 \n\ |
|
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
221 Special Objects:\n\ |
|
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
222 \n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22709
diff
changeset
|
223 MD5Type -- type object for md5 objects"); |
|
9363
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
224 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22709
diff
changeset
|
225 PyDoc_STRVAR(md5type_doc, |
|
9363
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
226 "An md5 represents the object used to calculate the MD5 checksum of a\n\ |
|
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
227 string of information.\n\ |
|
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
228 \n\ |
|
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
229 Methods:\n\ |
|
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
230 \n\ |
|
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
231 update() -- updates the current digest with an additional string\n\ |
|
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
232 digest() -- return the current digest value\n\ |
|
25743
86bf840c2a1c
SF #621948, update docstring for md5 by David M. Cooke. Will backport.
Neal Norwitz <nnorwitz@gmail.com>
parents:
24471
diff
changeset
|
233 hexdigest() -- return the current digest as a string of hexadecimal digits\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22709
diff
changeset
|
234 copy() -- return a copy of the current md5 object"); |
|
9363
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
235 |
|
24283
c0a67a1cab09
Removed more stray instances of statichere, but left _sre.c alone.
Tim Peters <tim.peters@gmail.com>
parents:
24280
diff
changeset
|
236 static PyTypeObject MD5type = { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
237 PyVarObject_HEAD_INIT(NULL, 0) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
238 "_md5.md5", /*tp_name*/ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
239 sizeof(md5object), /*tp_size*/ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
240 0, /*tp_itemsize*/ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
241 /* methods */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
242 (destructor)md5_dealloc, /*tp_dealloc*/ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
243 0, /*tp_print*/ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
244 0, /*tp_getattr*/ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
245 0, /*tp_setattr*/ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
246 0, /*tp_compare*/ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
247 0, /*tp_repr*/ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
248 0, /*tp_as_number*/ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
249 0, /*tp_as_sequence*/ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
250 0, /*tp_as_mapping*/ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
251 0, /*tp_hash*/ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
252 0, /*tp_call*/ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
253 0, /*tp_str*/ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
254 0, /*tp_getattro*/ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
255 0, /*tp_setattro*/ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
256 0, /*tp_as_buffer*/ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
257 Py_TPFLAGS_DEFAULT, /*tp_flags*/ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
258 md5type_doc, /*tp_doc*/ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
259 0, /*tp_traverse*/ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
260 0, /*tp_clear*/ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
261 0, /*tp_richcompare*/ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
262 0, /*tp_weaklistoffset*/ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
263 0, /*tp_iter*/ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
264 0, /*tp_iternext*/ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
265 md5_methods, /*tp_methods*/ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
266 0, /*tp_members*/ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
267 md5_getseters, /*tp_getset*/ |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
268 }; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
269 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
270 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
271 /* MD5 functions */ |
|
1132
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
272 |
| 4635 | 273 static PyObject * |
| 13503 | 274 MD5_new(PyObject *self, PyObject *args) |
|
1132
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
275 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
276 md5object *md5p; |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
58101
diff
changeset
|
277 Py_buffer view = { 0 }; |
|
77118
290d970c011d
Issue #14888: Fix misbehaviour of the _md5 module when called on data larger than 2**32 bytes.
Antoine Pitrou <solipsis@pitrou.net>
parents:
68256
diff
changeset
|
278 Py_ssize_t n; |
|
290d970c011d
Issue #14888: Fix misbehaviour of the _md5 module when called on data larger than 2**32 bytes.
Antoine Pitrou <solipsis@pitrou.net>
parents:
68256
diff
changeset
|
279 unsigned char *buf; |
|
1132
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
280 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
58101
diff
changeset
|
281 if (!PyArg_ParseTuple(args, "|s*:new", &view)) |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
282 return NULL; |
|
1132
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
283 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
58101
diff
changeset
|
284 if ((md5p = newmd5object()) == NULL) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
58101
diff
changeset
|
285 PyBuffer_Release(&view); |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
286 return NULL; |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
58101
diff
changeset
|
287 } |
|
1132
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
288 |
|
77118
290d970c011d
Issue #14888: Fix misbehaviour of the _md5 module when called on data larger than 2**32 bytes.
Antoine Pitrou <solipsis@pitrou.net>
parents:
68256
diff
changeset
|
289 n = view.len; |
|
290d970c011d
Issue #14888: Fix misbehaviour of the _md5 module when called on data larger than 2**32 bytes.
Antoine Pitrou <solipsis@pitrou.net>
parents:
68256
diff
changeset
|
290 buf = (unsigned char *) view.buf; |
|
290d970c011d
Issue #14888: Fix misbehaviour of the _md5 module when called on data larger than 2**32 bytes.
Antoine Pitrou <solipsis@pitrou.net>
parents:
68256
diff
changeset
|
291 while (n > 0) { |
|
290d970c011d
Issue #14888: Fix misbehaviour of the _md5 module when called on data larger than 2**32 bytes.
Antoine Pitrou <solipsis@pitrou.net>
parents:
68256
diff
changeset
|
292 Py_ssize_t nbytes; |
|
290d970c011d
Issue #14888: Fix misbehaviour of the _md5 module when called on data larger than 2**32 bytes.
Antoine Pitrou <solipsis@pitrou.net>
parents:
68256
diff
changeset
|
293 if (n > INT_MAX) |
|
290d970c011d
Issue #14888: Fix misbehaviour of the _md5 module when called on data larger than 2**32 bytes.
Antoine Pitrou <solipsis@pitrou.net>
parents:
68256
diff
changeset
|
294 nbytes = INT_MAX; |
|
290d970c011d
Issue #14888: Fix misbehaviour of the _md5 module when called on data larger than 2**32 bytes.
Antoine Pitrou <solipsis@pitrou.net>
parents:
68256
diff
changeset
|
295 else |
|
290d970c011d
Issue #14888: Fix misbehaviour of the _md5 module when called on data larger than 2**32 bytes.
Antoine Pitrou <solipsis@pitrou.net>
parents:
68256
diff
changeset
|
296 nbytes = n; |
|
290d970c011d
Issue #14888: Fix misbehaviour of the _md5 module when called on data larger than 2**32 bytes.
Antoine Pitrou <solipsis@pitrou.net>
parents:
68256
diff
changeset
|
297 md5_append(&md5p->md5, buf, |
|
290d970c011d
Issue #14888: Fix misbehaviour of the _md5 module when called on data larger than 2**32 bytes.
Antoine Pitrou <solipsis@pitrou.net>
parents:
68256
diff
changeset
|
298 Py_SAFE_DOWNCAST(nbytes, Py_ssize_t, unsigned int)); |
|
290d970c011d
Issue #14888: Fix misbehaviour of the _md5 module when called on data larger than 2**32 bytes.
Antoine Pitrou <solipsis@pitrou.net>
parents:
68256
diff
changeset
|
299 buf += nbytes; |
|
290d970c011d
Issue #14888: Fix misbehaviour of the _md5 module when called on data larger than 2**32 bytes.
Antoine Pitrou <solipsis@pitrou.net>
parents:
68256
diff
changeset
|
300 n -= nbytes; |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
58101
diff
changeset
|
301 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
58101
diff
changeset
|
302 PyBuffer_Release(&view); |
|
1132
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
303 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
304 return (PyObject *)md5p; |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
305 } |
|
1132
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
306 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22709
diff
changeset
|
307 PyDoc_STRVAR(new_doc, |
|
9363
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
308 "new([arg]) -> md5 object\n\ |
|
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
309 \n\ |
|
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
310 Return a new md5 object. If arg is present, the method call update(arg)\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22709
diff
changeset
|
311 is made."); |
|
9363
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
312 |
|
1132
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
313 |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
314 /* List of functions exported by this module */ |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
315 |
| 4635 | 316 static PyMethodDef md5_functions[] = { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
317 {"new", (PyCFunction)MD5_new, METH_VARARGS, new_doc}, |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
318 {NULL, NULL} /* Sentinel */ |
|
1132
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
319 }; |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
320 |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
321 |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
322 /* Initialize this module. */ |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
323 |
|
24471
f66b3a3509c7
Excise DL_EXPORT/DL_IMPORT from Modules/*. Required adding a prototype
Mark Hammond <mhammond@skippinet.com.au>
parents:
24283
diff
changeset
|
324 PyMODINIT_FUNC |
|
35375
624918e1c1b2
[ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
29787
diff
changeset
|
325 init_md5(void) |
|
1132
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
326 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
327 PyObject *m, *d; |
|
11711
6546ea06e157
Patch from Paul Sokolovsky <Paul.Sokolovsky@technologist.com>:
Fred Drake <fdrake@acm.org>
parents:
9588
diff
changeset
|
328 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
329 Py_TYPE(&MD5type) = &PyType_Type; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
330 if (PyType_Ready(&MD5type) < 0) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
331 return; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
332 m = Py_InitModule3("_md5", md5_functions, module_doc); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
333 if (m == NULL) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
334 return; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
335 d = PyModule_GetDict(m); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
336 PyDict_SetItemString(d, "MD5Type", (PyObject *)&MD5type); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
337 PyModule_AddIntConstant(m, "digest_size", 16); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
338 /* No need to check the error here, the caller will do that */ |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
339 } |
