Mercurial > cpython-lru_cache-weakref
annotate Modules/md5module.c @ 16798:258dcafe2d0b legacy-trunk
Gustavo Niemeyer <niemeyer@conectiva.com>:
Fixed recno support (keys are integers rather than strings).
Work around DB bug that cause stdin to be closed by rnopen() when the
DB file needed to exist but did not (no longer segfaults).
This closes SF tracker patch #403445.
Also wrapped some long lines and added whitespace around operators -- FLD.
| author | Fred Drake <fdrake@acm.org> |
|---|---|
| date | Tue, 27 Feb 2001 18:56:46 +0000 |
| parents | 6f6f965c5e2d |
| children | 8d14f534a5c2 |
| 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" |
|
1132
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
13 #include "md5.h" |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
14 |
|
1132
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
15 typedef struct { |
| 4635 | 16 PyObject_HEAD |
|
1132
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
17 MD5_CTX md5; /* the context holder */ |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
18 } md5object; |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
19 |
| 4635 | 20 staticforward PyTypeObject MD5type; |
|
1132
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
21 |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
22 #define is_md5object(v) ((v)->ob_type == &MD5type) |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
23 |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
24 static md5object * |
|
13651
8a063423e0b7
Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
25 newmd5object(void) |
|
1132
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
26 { |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
27 md5object *md5p; |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
28 |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
29 md5p = PyObject_New(md5object, &MD5type); |
|
1132
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
30 if (md5p == NULL) |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
31 return NULL; |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
32 |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
33 MD5Init(&md5p->md5); /* actual initialisation */ |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
34 return md5p; |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
35 } |
|
1132
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
36 |
|
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 /* MD5 methods */ |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
39 |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
40 static void |
| 13503 | 41 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
|
42 { |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
43 PyObject_Del(md5p); |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
44 } |
|
1132
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
45 |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
46 |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
47 /* MD5 methods-as-attributes */ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
48 |
| 4635 | 49 static PyObject * |
| 13503 | 50 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
|
51 { |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
52 unsigned char *cp; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
53 int len; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
54 |
| 4635 | 55 if (!PyArg_Parse(args, "s#", &cp, &len)) |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
56 return NULL; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
57 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
58 MD5Update(&self->md5, cp, len); |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
59 |
| 4635 | 60 Py_INCREF(Py_None); |
| 61 return Py_None; | |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
62 } |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
63 |
|
9363
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
64 static char update_doc [] = |
|
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
65 "update (arg)\n\ |
|
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
66 \n\ |
|
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
67 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
|
68 equivalent to a single call with the concatenation of all the\n\ |
|
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
69 arguments."; |
|
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
70 |
|
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
71 |
| 4635 | 72 static PyObject * |
| 13503 | 73 md5_digest(md5object *self, PyObject *args) |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
74 { |
|
13979
63de7f00b5bc
md5_hexdigest(): After a brief conversation with TP, added hexdigest()
Barry Warsaw <barry@python.org>
parents:
13820
diff
changeset
|
75 MD5_CTX mdContext; |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
76 unsigned char aDigest[16]; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
77 |
| 4635 | 78 if (!PyArg_NoArgs(args)) |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
79 return NULL; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
80 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
81 /* make a temporary copy, and perform the final */ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
82 mdContext = self->md5; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
83 MD5Final(aDigest, &mdContext); |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
84 |
| 4635 | 85 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
|
86 } |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
87 |
|
9363
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
88 static char digest_doc [] = |
|
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
89 "digest() -> string\n\ |
|
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
90 \n\ |
|
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
91 Return the digest of the strings passed to the update() method so\n\ |
|
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
92 far. This is an 16-byte string which may contain non-ASCII characters,\n\ |
|
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
93 including null bytes."; |
|
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
94 |
|
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
95 |
| 4635 | 96 static PyObject * |
|
13979
63de7f00b5bc
md5_hexdigest(): After a brief conversation with TP, added hexdigest()
Barry Warsaw <barry@python.org>
parents:
13820
diff
changeset
|
97 md5_hexdigest(md5object *self, PyObject *args) |
|
63de7f00b5bc
md5_hexdigest(): After a brief conversation with TP, added hexdigest()
Barry Warsaw <barry@python.org>
parents:
13820
diff
changeset
|
98 { |
|
63de7f00b5bc
md5_hexdigest(): After a brief conversation with TP, added hexdigest()
Barry Warsaw <barry@python.org>
parents:
13820
diff
changeset
|
99 MD5_CTX mdContext; |
|
63de7f00b5bc
md5_hexdigest(): After a brief conversation with TP, added hexdigest()
Barry Warsaw <barry@python.org>
parents:
13820
diff
changeset
|
100 unsigned char digest[16]; |
|
63de7f00b5bc
md5_hexdigest(): After a brief conversation with TP, added hexdigest()
Barry Warsaw <barry@python.org>
parents:
13820
diff
changeset
|
101 unsigned char hexdigest[32]; |
|
63de7f00b5bc
md5_hexdigest(): After a brief conversation with TP, added hexdigest()
Barry Warsaw <barry@python.org>
parents:
13820
diff
changeset
|
102 int i, j; |
|
63de7f00b5bc
md5_hexdigest(): After a brief conversation with TP, added hexdigest()
Barry Warsaw <barry@python.org>
parents:
13820
diff
changeset
|
103 |
|
63de7f00b5bc
md5_hexdigest(): After a brief conversation with TP, added hexdigest()
Barry Warsaw <barry@python.org>
parents:
13820
diff
changeset
|
104 if (!PyArg_NoArgs(args)) |
|
63de7f00b5bc
md5_hexdigest(): After a brief conversation with TP, added hexdigest()
Barry Warsaw <barry@python.org>
parents:
13820
diff
changeset
|
105 return NULL; |
|
63de7f00b5bc
md5_hexdigest(): After a brief conversation with TP, added hexdigest()
Barry Warsaw <barry@python.org>
parents:
13820
diff
changeset
|
106 |
|
63de7f00b5bc
md5_hexdigest(): After a brief conversation with TP, added hexdigest()
Barry Warsaw <barry@python.org>
parents:
13820
diff
changeset
|
107 /* make a temporary copy, and perform the final */ |
|
63de7f00b5bc
md5_hexdigest(): After a brief conversation with TP, added hexdigest()
Barry Warsaw <barry@python.org>
parents:
13820
diff
changeset
|
108 mdContext = self->md5; |
|
63de7f00b5bc
md5_hexdigest(): After a brief conversation with TP, added hexdigest()
Barry Warsaw <barry@python.org>
parents:
13820
diff
changeset
|
109 MD5Final(digest, &mdContext); |
|
63de7f00b5bc
md5_hexdigest(): After a brief conversation with TP, added hexdigest()
Barry Warsaw <barry@python.org>
parents:
13820
diff
changeset
|
110 |
|
63de7f00b5bc
md5_hexdigest(): After a brief conversation with TP, added hexdigest()
Barry Warsaw <barry@python.org>
parents:
13820
diff
changeset
|
111 /* Make hex version of the digest */ |
|
63de7f00b5bc
md5_hexdigest(): After a brief conversation with TP, added hexdigest()
Barry Warsaw <barry@python.org>
parents:
13820
diff
changeset
|
112 for(i=j=0; i<16; i++) { |
|
63de7f00b5bc
md5_hexdigest(): After a brief conversation with TP, added hexdigest()
Barry Warsaw <barry@python.org>
parents:
13820
diff
changeset
|
113 char c; |
|
63de7f00b5bc
md5_hexdigest(): After a brief conversation with TP, added hexdigest()
Barry Warsaw <barry@python.org>
parents:
13820
diff
changeset
|
114 c = (digest[i] >> 4) & 0xf; |
|
63de7f00b5bc
md5_hexdigest(): After a brief conversation with TP, added hexdigest()
Barry Warsaw <barry@python.org>
parents:
13820
diff
changeset
|
115 c = (c>9) ? c+'a'-10 : c + '0'; |
|
63de7f00b5bc
md5_hexdigest(): After a brief conversation with TP, added hexdigest()
Barry Warsaw <barry@python.org>
parents:
13820
diff
changeset
|
116 hexdigest[j++] = c; |
|
63de7f00b5bc
md5_hexdigest(): After a brief conversation with TP, added hexdigest()
Barry Warsaw <barry@python.org>
parents:
13820
diff
changeset
|
117 c = (digest[i] & 0xf); |
|
63de7f00b5bc
md5_hexdigest(): After a brief conversation with TP, added hexdigest()
Barry Warsaw <barry@python.org>
parents:
13820
diff
changeset
|
118 c = (c>9) ? c+'a'-10 : c + '0'; |
|
63de7f00b5bc
md5_hexdigest(): After a brief conversation with TP, added hexdigest()
Barry Warsaw <barry@python.org>
parents:
13820
diff
changeset
|
119 hexdigest[j++] = c; |
|
63de7f00b5bc
md5_hexdigest(): After a brief conversation with TP, added hexdigest()
Barry Warsaw <barry@python.org>
parents:
13820
diff
changeset
|
120 } |
|
63de7f00b5bc
md5_hexdigest(): After a brief conversation with TP, added hexdigest()
Barry Warsaw <barry@python.org>
parents:
13820
diff
changeset
|
121 return PyString_FromStringAndSize((char*)hexdigest, 32); |
|
63de7f00b5bc
md5_hexdigest(): After a brief conversation with TP, added hexdigest()
Barry Warsaw <barry@python.org>
parents:
13820
diff
changeset
|
122 } |
|
63de7f00b5bc
md5_hexdigest(): After a brief conversation with TP, added hexdigest()
Barry Warsaw <barry@python.org>
parents:
13820
diff
changeset
|
123 |
|
63de7f00b5bc
md5_hexdigest(): After a brief conversation with TP, added hexdigest()
Barry Warsaw <barry@python.org>
parents:
13820
diff
changeset
|
124 |
|
63de7f00b5bc
md5_hexdigest(): After a brief conversation with TP, added hexdigest()
Barry Warsaw <barry@python.org>
parents:
13820
diff
changeset
|
125 static char hexdigest_doc [] = |
|
63de7f00b5bc
md5_hexdigest(): After a brief conversation with TP, added hexdigest()
Barry Warsaw <barry@python.org>
parents:
13820
diff
changeset
|
126 "hexdigest() -> string\n\ |
|
63de7f00b5bc
md5_hexdigest(): After a brief conversation with TP, added hexdigest()
Barry Warsaw <barry@python.org>
parents:
13820
diff
changeset
|
127 \n\ |
|
63de7f00b5bc
md5_hexdigest(): After a brief conversation with TP, added hexdigest()
Barry Warsaw <barry@python.org>
parents:
13820
diff
changeset
|
128 Like digest(), but returns the digest as a string of hexadecimal digits."; |
|
63de7f00b5bc
md5_hexdigest(): After a brief conversation with TP, added hexdigest()
Barry Warsaw <barry@python.org>
parents:
13820
diff
changeset
|
129 |
|
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 static PyObject * |
| 13503 | 132 md5_copy(md5object *self, PyObject *args) |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
133 { |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
134 md5object *md5p; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
135 |
| 4635 | 136 if (!PyArg_NoArgs(args)) |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
137 return NULL; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
138 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
139 if ((md5p = newmd5object()) == NULL) |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
140 return NULL; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
141 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
142 md5p->md5 = self->md5; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
143 |
| 4635 | 144 return (PyObject *)md5p; |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
145 } |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
146 |
|
9363
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
147 static char copy_doc [] = |
|
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
148 "copy() -> md5 object\n\ |
|
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
149 \n\ |
|
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
150 Return a copy (``clone'') of the md5 object."; |
|
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
151 |
|
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
152 |
| 4635 | 153 static PyMethodDef md5_methods[] = { |
|
13979
63de7f00b5bc
md5_hexdigest(): After a brief conversation with TP, added hexdigest()
Barry Warsaw <barry@python.org>
parents:
13820
diff
changeset
|
154 {"update", (PyCFunction)md5_update, METH_OLDARGS, update_doc}, |
|
63de7f00b5bc
md5_hexdigest(): After a brief conversation with TP, added hexdigest()
Barry Warsaw <barry@python.org>
parents:
13820
diff
changeset
|
155 {"digest", (PyCFunction)md5_digest, METH_OLDARGS, digest_doc}, |
|
63de7f00b5bc
md5_hexdigest(): After a brief conversation with TP, added hexdigest()
Barry Warsaw <barry@python.org>
parents:
13820
diff
changeset
|
156 {"hexdigest", (PyCFunction)md5_hexdigest, METH_OLDARGS, hexdigest_doc}, |
|
63de7f00b5bc
md5_hexdigest(): After a brief conversation with TP, added hexdigest()
Barry Warsaw <barry@python.org>
parents:
13820
diff
changeset
|
157 {"copy", (PyCFunction)md5_copy, METH_OLDARGS, copy_doc}, |
|
63de7f00b5bc
md5_hexdigest(): After a brief conversation with TP, added hexdigest()
Barry Warsaw <barry@python.org>
parents:
13820
diff
changeset
|
158 {NULL, NULL} /* sentinel */ |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
159 }; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
160 |
| 4635 | 161 static PyObject * |
| 13503 | 162 md5_getattr(md5object *self, char *name) |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
163 { |
| 4635 | 164 return Py_FindMethod(md5_methods, (PyObject *)self, name); |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
165 } |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
166 |
|
9363
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
167 static char module_doc [] = |
|
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
168 |
|
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
169 "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
|
170 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
|
171 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
|
172 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
|
173 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
|
174 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
|
175 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
|
176 \n\ |
|
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
177 Functions:\n\ |
|
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
178 \n\ |
|
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
179 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
|
180 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
|
181 \n\ |
|
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
182 Special Objects:\n\ |
|
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
183 \n\ |
|
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
184 MD5Type -- type object for md5 objects\n\ |
|
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
185 "; |
|
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
186 |
|
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
187 static char md5type_doc [] = |
|
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
188 "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
|
189 string of information.\n\ |
|
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
190 \n\ |
|
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
191 Methods:\n\ |
|
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
192 \n\ |
|
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
193 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
|
194 digest() -- return the current digest value\n\ |
|
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
195 copy() -- return a copy of the current md5 object\n\ |
|
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
196 "; |
|
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
197 |
| 4635 | 198 statichere PyTypeObject MD5type = { |
|
11711
6546ea06e157
Patch from Paul Sokolovsky <Paul.Sokolovsky@technologist.com>:
Fred Drake <fdrake@acm.org>
parents:
9588
diff
changeset
|
199 PyObject_HEAD_INIT(NULL) |
| 4635 | 200 0, /*ob_size*/ |
| 201 "md5", /*tp_name*/ | |
| 202 sizeof(md5object), /*tp_size*/ | |
| 203 0, /*tp_itemsize*/ | |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
204 /* methods */ |
| 4635 | 205 (destructor)md5_dealloc, /*tp_dealloc*/ |
| 206 0, /*tp_print*/ | |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
207 (getattrfunc)md5_getattr, /*tp_getattr*/ |
| 4635 | 208 0, /*tp_setattr*/ |
| 209 0, /*tp_compare*/ | |
| 210 0, /*tp_repr*/ | |
| 211 0, /*tp_as_number*/ | |
|
9363
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
212 0, /*tp_as_sequence*/ |
|
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
213 0, /*tp_as_mapping*/ |
|
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
214 0, /*tp_hash*/ |
|
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
215 0, /*tp_call*/ |
|
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
216 0, /*tp_str*/ |
|
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
217 0, /*tp_getattro*/ |
|
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
218 0, /*tp_setattro*/ |
|
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
219 0, /*tp_as_buffer*/ |
|
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
220 0, /*tp_xxx4*/ |
|
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
221 md5type_doc, /*tp_doc*/ |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
222 }; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
223 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
224 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
225 /* MD5 functions */ |
|
1132
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
226 |
| 4635 | 227 static PyObject * |
| 13503 | 228 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
|
229 { |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
230 md5object *md5p; |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
231 unsigned char *cp = NULL; |
| 2860 | 232 int len = 0; |
|
1132
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
233 |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11711
diff
changeset
|
234 if (!PyArg_ParseTuple(args, "|s#:new", &cp, &len)) |
| 2860 | 235 return NULL; |
|
1132
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
236 |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
237 if ((md5p = newmd5object()) == NULL) |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
238 return NULL; |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
239 |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
240 if (cp) |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
241 MD5Update(&md5p->md5, cp, len); |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
242 |
| 4635 | 243 return (PyObject *)md5p; |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
244 } |
|
1132
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
245 |
|
9363
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
246 static char new_doc [] = |
|
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
247 "new([arg]) -> md5 object\n\ |
|
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
248 \n\ |
|
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
249 Return a new md5 object. If arg is present, the method call update(arg)\n\ |
|
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
250 is made."; |
|
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
251 |
|
1132
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
252 |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
253 /* 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
|
254 |
| 4635 | 255 static PyMethodDef md5_functions[] = { |
|
13817
3c0f75a2198f
Use METH_VARARGS instead of numeric constant 1 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents:
13651
diff
changeset
|
256 {"new", (PyCFunction)MD5_new, METH_VARARGS, new_doc}, |
|
3c0f75a2198f
Use METH_VARARGS instead of numeric constant 1 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents:
13651
diff
changeset
|
257 {"md5", (PyCFunction)MD5_new, METH_VARARGS, new_doc}, /* Backward compatibility */ |
| 2860 | 258 {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
|
259 }; |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
260 |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
261 |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
262 /* Initialize this module. */ |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
263 |
|
9588
38023a425e48
Add DL_EXPORT() to all modules that could possibly be used
Guido van Rossum <guido@python.org>
parents:
9363
diff
changeset
|
264 DL_EXPORT(void) |
|
13651
8a063423e0b7
Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
265 initmd5(void) |
|
1132
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
266 { |
|
9363
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
267 PyObject *m, *d; |
|
11711
6546ea06e157
Patch from Paul Sokolovsky <Paul.Sokolovsky@technologist.com>:
Fred Drake <fdrake@acm.org>
parents:
9588
diff
changeset
|
268 |
|
6546ea06e157
Patch from Paul Sokolovsky <Paul.Sokolovsky@technologist.com>:
Fred Drake <fdrake@acm.org>
parents:
9588
diff
changeset
|
269 MD5type.ob_type = &PyType_Type; |
|
9363
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
270 m = Py_InitModule3("md5", md5_functions, module_doc); |
|
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
271 d = PyModule_GetDict(m); |
|
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
272 PyDict_SetItemString(d, "MD5Type", (PyObject *)&MD5type); |
|
f351c64c82ed
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
4635
diff
changeset
|
273 /* 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
|
274 } |
