annotate Modules/md5module.c @ 58765:2ba7677bfa95 legacy-trunk

testCopysign was defined twice in test_math; combine the definitions
author Mark Dickinson <dickinsm@gmail.com>
date Sat, 06 Feb 2010 23:11:25 +0000
parents ff5bc2fa38d6
children fd25030223b0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
49745ddb4f69 Renamed
Barry Warsaw <barry@python.org>
parents: 4503
diff changeset
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 {
4635
49745ddb4f69 Renamed
Barry Warsaw <barry@python.org>
parents: 4503
diff changeset
17 PyObject_HEAD
37436
115428bb1d3f - Patch #360466: Replace the MD5 implementation from RSA Data Security Inc
Matthias Klose <doko@ubuntu.com>
parents: 36324
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
6461dac9a9f2 * mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff changeset
23 #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
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 {
6461dac9a9f2 * mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff changeset
28 md5object *md5p;
6461dac9a9f2 * mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff changeset
29
12576
1c7c2dd1beb1 Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
30 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
31 if (md5p == NULL)
6461dac9a9f2 * mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff changeset
32 return NULL;
6461dac9a9f2 * mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff changeset
33
37436
115428bb1d3f - Patch #360466: Replace the MD5 implementation from RSA Data Security Inc
Matthias Klose <doko@ubuntu.com>
parents: 36324
diff changeset
34 md5_init(&md5p->md5); /* actual initialisation */
1132
6461dac9a9f2 * mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
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
6484098f40fc ANSI-fying
Peter Schneider-Kamp <nowonder@nowonder.de>
parents: 13256
diff changeset
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 {
12576
1c7c2dd1beb1 Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents: 11882
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
49745ddb4f69 Renamed
Barry Warsaw <barry@python.org>
parents: 4503
diff changeset
50 static PyObject *
13503
6484098f40fc ANSI-fying
Peter Schneider-Kamp <nowonder@nowonder.de>
parents: 13256
diff changeset
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 {
51580
1e7ac14e4938 - Issue #3745: Fix hashlib to always reject unicode and non buffer-api
Gregory P. Smith <greg@mad-scientist.com>
parents: 47527
diff changeset
53 Py_buffer view;
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1418
diff changeset
54
58101
ff5bc2fa38d6 Issue #3745: Undo the requirement for new buffer API only objects to be passed
Gregory P. Smith <greg@mad-scientist.com>
parents: 51961
diff changeset
55 if (!PyArg_ParseTuple(args, "s*:update", &view))
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
51580
1e7ac14e4938 - Issue #3745: Fix hashlib to always reject unicode and non buffer-api
Gregory P. Smith <greg@mad-scientist.com>
parents: 47527
diff changeset
58 md5_append(&self->md5, (unsigned char*)view.buf,
1e7ac14e4938 - Issue #3745: Fix hashlib to always reject unicode and non buffer-api
Gregory P. Smith <greg@mad-scientist.com>
parents: 47527
diff changeset
59 Py_SAFE_DOWNCAST(view.len, Py_ssize_t, unsigned int));
1e7ac14e4938 - Issue #3745: Fix hashlib to always reject unicode and non buffer-api
Gregory P. Smith <greg@mad-scientist.com>
parents: 47527
diff changeset
60
1e7ac14e4938 - Issue #3745: Fix hashlib to always reject unicode and non buffer-api
Gregory P. Smith <greg@mad-scientist.com>
parents: 47527
diff changeset
61 PyBuffer_Release(&view);
58101
ff5bc2fa38d6 Issue #3745: Undo the requirement for new buffer API only objects to be passed
Gregory P. Smith <greg@mad-scientist.com>
parents: 51961
diff changeset
62 Py_RETURN_NONE;
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1418
diff changeset
63 }
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1418
diff changeset
64
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 22709
diff changeset
65 PyDoc_STRVAR(update_doc,
9363
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
66 "update (arg)\n\
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
67 \n\
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
68 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
69 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
70 arguments.");
9363
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
71
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
72
4635
49745ddb4f69 Renamed
Barry Warsaw <barry@python.org>
parents: 4503
diff changeset
73 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
74 md5_digest(md5object *self)
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1418
diff changeset
75 {
37436
115428bb1d3f - Patch #360466: Replace the MD5 implementation from RSA Data Security Inc
Matthias Klose <doko@ubuntu.com>
parents: 36324
diff changeset
76 md5_state_t mdContext;
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1418
diff changeset
77 unsigned char aDigest[16];
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1418
diff changeset
78
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1418
diff changeset
79 /* 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
80 mdContext = self->md5;
37436
115428bb1d3f - Patch #360466: Replace the MD5 implementation from RSA Data Security Inc
Matthias Klose <doko@ubuntu.com>
parents: 36324
diff changeset
81 md5_finish(&mdContext, aDigest);
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1418
diff changeset
82
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
83 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
84 }
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1418
diff changeset
85
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 22709
diff changeset
86 PyDoc_STRVAR(digest_doc,
9363
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
87 "digest() -> string\n\
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
88 \n\
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
89 Return the digest of the strings passed to the update() method so\n\
29787
Skip Montanaro <skip@pobox.com>
parents: 25743
diff changeset
90 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
91 including null bytes.");
9363
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
92
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
93
4635
49745ddb4f69 Renamed
Barry Warsaw <barry@python.org>
parents: 4503
diff changeset
94 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
95 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
96 {
37436
115428bb1d3f - Patch #360466: Replace the MD5 implementation from RSA Data Security Inc
Matthias Klose <doko@ubuntu.com>
parents: 36324
diff changeset
97 md5_state_t mdContext;
13979
63de7f00b5bc md5_hexdigest(): After a brief conversation with TP, added hexdigest()
Barry Warsaw <barry@python.org>
parents: 13820
diff changeset
98 unsigned char digest[16];
63de7f00b5bc md5_hexdigest(): After a brief conversation with TP, added hexdigest()
Barry Warsaw <barry@python.org>
parents: 13820
diff changeset
99 unsigned char hexdigest[32];
63de7f00b5bc md5_hexdigest(): After a brief conversation with TP, added hexdigest()
Barry Warsaw <barry@python.org>
parents: 13820
diff changeset
100 int i, j;
63de7f00b5bc md5_hexdigest(): After a brief conversation with TP, added hexdigest()
Barry Warsaw <barry@python.org>
parents: 13820
diff changeset
101
63de7f00b5bc md5_hexdigest(): After a brief conversation with TP, added hexdigest()
Barry Warsaw <barry@python.org>
parents: 13820
diff changeset
102 /* 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
103 mdContext = self->md5;
37436
115428bb1d3f - Patch #360466: Replace the MD5 implementation from RSA Data Security Inc
Matthias Klose <doko@ubuntu.com>
parents: 36324
diff changeset
104 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
105
63de7f00b5bc md5_hexdigest(): After a brief conversation with TP, added hexdigest()
Barry Warsaw <barry@python.org>
parents: 13820
diff changeset
106 /* 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
107 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
108 char c;
63de7f00b5bc md5_hexdigest(): After a brief conversation with TP, added hexdigest()
Barry Warsaw <barry@python.org>
parents: 13820
diff changeset
109 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
110 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
111 hexdigest[j++] = c;
63de7f00b5bc md5_hexdigest(): After a brief conversation with TP, added hexdigest()
Barry Warsaw <barry@python.org>
parents: 13820
diff changeset
112 c = (digest[i] & 0xf);
63de7f00b5bc md5_hexdigest(): After a brief conversation with TP, added hexdigest()
Barry Warsaw <barry@python.org>
parents: 13820
diff changeset
113 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
114 hexdigest[j++] = c;
63de7f00b5bc md5_hexdigest(): After a brief conversation with TP, added hexdigest()
Barry Warsaw <barry@python.org>
parents: 13820
diff changeset
115 }
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
116 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
117 }
63de7f00b5bc md5_hexdigest(): After a brief conversation with TP, added hexdigest()
Barry Warsaw <barry@python.org>
parents: 13820
diff changeset
118
63de7f00b5bc md5_hexdigest(): After a brief conversation with TP, added hexdigest()
Barry Warsaw <barry@python.org>
parents: 13820
diff changeset
119
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 22709
diff changeset
120 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
121 "hexdigest() -> string\n\
63de7f00b5bc md5_hexdigest(): After a brief conversation with TP, added hexdigest()
Barry Warsaw <barry@python.org>
parents: 13820
diff changeset
122 \n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 22709
diff changeset
123 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
124
63de7f00b5bc md5_hexdigest(): After a brief conversation with TP, added hexdigest()
Barry Warsaw <barry@python.org>
parents: 13820
diff changeset
125
63de7f00b5bc md5_hexdigest(): After a brief conversation with TP, added hexdigest()
Barry Warsaw <barry@python.org>
parents: 13820
diff changeset
126 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
127 md5_copy(md5object *self)
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1418
diff changeset
128 {
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1418
diff changeset
129 md5object *md5p;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1418
diff changeset
130
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1418
diff changeset
131 if ((md5p = newmd5object()) == NULL)
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1418
diff changeset
132 return NULL;
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 md5p->md5 = self->md5;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1418
diff changeset
135
4635
49745ddb4f69 Renamed
Barry Warsaw <barry@python.org>
parents: 4503
diff changeset
136 return (PyObject *)md5p;
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1418
diff changeset
137 }
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1418
diff changeset
138
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 22709
diff changeset
139 PyDoc_STRVAR(copy_doc,
9363
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
140 "copy() -> md5 object\n\
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
141 \n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 22709
diff changeset
142 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
143
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
144
4635
49745ddb4f69 Renamed
Barry Warsaw <barry@python.org>
parents: 4503
diff changeset
145 static PyMethodDef md5_methods[] = {
22709
3aa4bf7ac31e Remove METH_OLDARGS:
Neal Norwitz <nnorwitz@gmail.com>
parents: 22561
diff changeset
146 {"update", (PyCFunction)md5_update, METH_VARARGS, update_doc},
22561
043ad7adc896 Remove many uses of PyArg_NoArgs macro, change METH_OLDARGS to METH_NOARGS.
Neal Norwitz <nnorwitz@gmail.com>
parents: 21313
diff changeset
147 {"digest", (PyCFunction)md5_digest, METH_NOARGS, digest_doc},
043ad7adc896 Remove many uses of PyArg_NoArgs macro, change METH_OLDARGS to METH_NOARGS.
Neal Norwitz <nnorwitz@gmail.com>
parents: 21313
diff changeset
148 {"hexdigest", (PyCFunction)md5_hexdigest, METH_NOARGS, hexdigest_doc},
043ad7adc896 Remove many uses of PyArg_NoArgs macro, change METH_OLDARGS to METH_NOARGS.
Neal Norwitz <nnorwitz@gmail.com>
parents: 21313
diff changeset
149 {"copy", (PyCFunction)md5_copy, METH_NOARGS, copy_doc},
13979
63de7f00b5bc md5_hexdigest(): After a brief conversation with TP, added hexdigest()
Barry Warsaw <barry@python.org>
parents: 13820
diff changeset
150 {NULL, NULL} /* sentinel */
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1418
diff changeset
151 };
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1418
diff changeset
152
4635
49745ddb4f69 Renamed
Barry Warsaw <barry@python.org>
parents: 4503
diff changeset
153 static PyObject *
35375
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents: 29787
diff changeset
154 md5_get_block_size(PyObject *self, void *closure)
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents: 29787
diff changeset
155 {
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents: 29787
diff changeset
156 return PyInt_FromLong(64);
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents: 29787
diff changeset
157 }
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents: 29787
diff changeset
158
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents: 29787
diff changeset
159 static PyObject *
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents: 29787
diff changeset
160 md5_get_digest_size(PyObject *self, void *closure)
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents: 29787
diff changeset
161 {
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents: 29787
diff changeset
162 return PyInt_FromLong(16);
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents: 29787
diff changeset
163 }
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents: 29787
diff changeset
164
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents: 29787
diff changeset
165 static PyObject *
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents: 29787
diff changeset
166 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
167 {
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
168 return PyString_FromStringAndSize("MD5", 3);
35375
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents: 29787
diff changeset
169 }
20843
8d14f534a5c2 [Patch #476612] Add attributes from PEP247 to the md5 and sha modules
Andrew M. Kuchling <amk@amk.ca>
parents: 14375
diff changeset
170
35375
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents: 29787
diff changeset
171 static PyGetSetDef md5_getseters[] = {
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents: 29787
diff changeset
172 {"digest_size",
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents: 29787
diff changeset
173 (getter)md5_get_digest_size, NULL,
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents: 29787
diff changeset
174 NULL,
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents: 29787
diff changeset
175 NULL},
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents: 29787
diff changeset
176 {"block_size",
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents: 29787
diff changeset
177 (getter)md5_get_block_size, NULL,
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents: 29787
diff changeset
178 NULL,
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents: 29787
diff changeset
179 NULL},
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents: 29787
diff changeset
180 {"name",
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents: 29787
diff changeset
181 (getter)md5_get_name, NULL,
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents: 29787
diff changeset
182 NULL,
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents: 29787
diff changeset
183 NULL},
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents: 29787
diff changeset
184 /* 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
185 * the old sha module also supported 'digestsize'. ugh. */
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents: 29787
diff changeset
186 {"digestsize",
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents: 29787
diff changeset
187 (getter)md5_get_digest_size, 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 NULL},
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents: 29787
diff changeset
190 {NULL} /* Sentinel */
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents: 29787
diff changeset
191 };
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents: 29787
diff changeset
192
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1418
diff changeset
193
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 22709
diff changeset
194 PyDoc_STRVAR(module_doc,
9363
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
195 "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
196 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
197 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
198 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
199 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
200 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
201 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
202 \n\
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
203 Functions:\n\
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
204 \n\
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
205 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
206 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
207 \n\
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
208 Special Objects:\n\
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
209 \n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 22709
diff changeset
210 MD5Type -- type object for md5 objects");
9363
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
211
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 22709
diff changeset
212 PyDoc_STRVAR(md5type_doc,
9363
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
213 "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
214 string of information.\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 Methods:\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 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
219 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
220 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
221 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
222
24283
c0a67a1cab09 Removed more stray instances of statichere, but left _sre.c alone.
Tim Peters <tim.peters@gmail.com>
parents: 24280
diff changeset
223 static PyTypeObject MD5type = {
42333
6620a510e9a9 PEP 3123: Provide forward compatibility with Python 3.0, while keeping
Martin v. Löwis <martin@v.loewis.de>
parents: 37436
diff changeset
224 PyVarObject_HEAD_INIT(NULL, 0)
35375
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents: 29787
diff changeset
225 "_md5.md5", /*tp_name*/
4635
49745ddb4f69 Renamed
Barry Warsaw <barry@python.org>
parents: 4503
diff changeset
226 sizeof(md5object), /*tp_size*/
49745ddb4f69 Renamed
Barry Warsaw <barry@python.org>
parents: 4503
diff changeset
227 0, /*tp_itemsize*/
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1418
diff changeset
228 /* methods */
4635
49745ddb4f69 Renamed
Barry Warsaw <barry@python.org>
parents: 4503
diff changeset
229 (destructor)md5_dealloc, /*tp_dealloc*/
49745ddb4f69 Renamed
Barry Warsaw <barry@python.org>
parents: 4503
diff changeset
230 0, /*tp_print*/
35375
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents: 29787
diff changeset
231 0, /*tp_getattr*/
4635
49745ddb4f69 Renamed
Barry Warsaw <barry@python.org>
parents: 4503
diff changeset
232 0, /*tp_setattr*/
49745ddb4f69 Renamed
Barry Warsaw <barry@python.org>
parents: 4503
diff changeset
233 0, /*tp_compare*/
49745ddb4f69 Renamed
Barry Warsaw <barry@python.org>
parents: 4503
diff changeset
234 0, /*tp_repr*/
49745ddb4f69 Renamed
Barry Warsaw <barry@python.org>
parents: 4503
diff changeset
235 0, /*tp_as_number*/
9363
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
236 0, /*tp_as_sequence*/
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
237 0, /*tp_as_mapping*/
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
238 0, /*tp_hash*/
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
239 0, /*tp_call*/
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
240 0, /*tp_str*/
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
241 0, /*tp_getattro*/
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
242 0, /*tp_setattro*/
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
243 0, /*tp_as_buffer*/
35375
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents: 29787
diff changeset
244 Py_TPFLAGS_DEFAULT, /*tp_flags*/
9363
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
245 md5type_doc, /*tp_doc*/
35375
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents: 29787
diff changeset
246 0, /*tp_traverse*/
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents: 29787
diff changeset
247 0, /*tp_clear*/
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents: 29787
diff changeset
248 0, /*tp_richcompare*/
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents: 29787
diff changeset
249 0, /*tp_weaklistoffset*/
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents: 29787
diff changeset
250 0, /*tp_iter*/
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents: 29787
diff changeset
251 0, /*tp_iternext*/
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents: 29787
diff changeset
252 md5_methods, /*tp_methods*/
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents: 29787
diff changeset
253 0, /*tp_members*/
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents: 29787
diff changeset
254 md5_getseters, /*tp_getset*/
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1418
diff changeset
255 };
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1418
diff changeset
256
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1418
diff changeset
257
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1418
diff changeset
258 /* MD5 functions */
1132
6461dac9a9f2 * mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff changeset
259
4635
49745ddb4f69 Renamed
Barry Warsaw <barry@python.org>
parents: 4503
diff changeset
260 static PyObject *
13503
6484098f40fc ANSI-fying
Peter Schneider-Kamp <nowonder@nowonder.de>
parents: 13256
diff changeset
261 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
262 {
6461dac9a9f2 * mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff changeset
263 md5object *md5p;
58101
ff5bc2fa38d6 Issue #3745: Undo the requirement for new buffer API only objects to be passed
Gregory P. Smith <greg@mad-scientist.com>
parents: 51961
diff changeset
264 Py_buffer view = { 0 };
1132
6461dac9a9f2 * mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff changeset
265
58101
ff5bc2fa38d6 Issue #3745: Undo the requirement for new buffer API only objects to be passed
Gregory P. Smith <greg@mad-scientist.com>
parents: 51961
diff changeset
266 if (!PyArg_ParseTuple(args, "|s*:new", &view))
2860
6ae9b377e522 use newgetargs
Guido van Rossum <guido@python.org>
parents: 2506
diff changeset
267 return NULL;
1132
6461dac9a9f2 * mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff changeset
268
51580
1e7ac14e4938 - Issue #3745: Fix hashlib to always reject unicode and non buffer-api
Gregory P. Smith <greg@mad-scientist.com>
parents: 47527
diff changeset
269 if ((md5p = newmd5object()) == NULL) {
58101
ff5bc2fa38d6 Issue #3745: Undo the requirement for new buffer API only objects to be passed
Gregory P. Smith <greg@mad-scientist.com>
parents: 51961
diff changeset
270 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
271 return NULL;
51580
1e7ac14e4938 - Issue #3745: Fix hashlib to always reject unicode and non buffer-api
Gregory P. Smith <greg@mad-scientist.com>
parents: 47527
diff changeset
272 }
1132
6461dac9a9f2 * mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff changeset
273
58101
ff5bc2fa38d6 Issue #3745: Undo the requirement for new buffer API only objects to be passed
Gregory P. Smith <greg@mad-scientist.com>
parents: 51961
diff changeset
274 if (view.len > 0) {
51580
1e7ac14e4938 - Issue #3745: Fix hashlib to always reject unicode and non buffer-api
Gregory P. Smith <greg@mad-scientist.com>
parents: 47527
diff changeset
275 md5_append(&md5p->md5, (unsigned char*)view.buf,
1e7ac14e4938 - Issue #3745: Fix hashlib to always reject unicode and non buffer-api
Gregory P. Smith <greg@mad-scientist.com>
parents: 47527
diff changeset
276 Py_SAFE_DOWNCAST(view.len, Py_ssize_t, unsigned int));
1e7ac14e4938 - Issue #3745: Fix hashlib to always reject unicode and non buffer-api
Gregory P. Smith <greg@mad-scientist.com>
parents: 47527
diff changeset
277 }
58101
ff5bc2fa38d6 Issue #3745: Undo the requirement for new buffer API only objects to be passed
Gregory P. Smith <greg@mad-scientist.com>
parents: 51961
diff changeset
278 PyBuffer_Release(&view);
51961
6c08bfe78fff Fix SHA_new and MD5_new, that would crash if not given initial data
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 51580
diff changeset
279
4635
49745ddb4f69 Renamed
Barry Warsaw <barry@python.org>
parents: 4503
diff changeset
280 return (PyObject *)md5p;
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1418
diff changeset
281 }
1132
6461dac9a9f2 * mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff changeset
282
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 22709
diff changeset
283 PyDoc_STRVAR(new_doc,
9363
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
284 "new([arg]) -> md5 object\n\
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
285 \n\
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
286 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
287 is made.");
9363
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
288
1132
6461dac9a9f2 * mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff changeset
289
6461dac9a9f2 * mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff changeset
290 /* 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
291
4635
49745ddb4f69 Renamed
Barry Warsaw <barry@python.org>
parents: 4503
diff changeset
292 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
293 {"new", (PyCFunction)MD5_new, METH_VARARGS, new_doc},
2860
6ae9b377e522 use newgetargs
Guido van Rossum <guido@python.org>
parents: 2506
diff changeset
294 {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
295 };
6461dac9a9f2 * mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff changeset
296
6461dac9a9f2 * mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff changeset
297
6461dac9a9f2 * mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff changeset
298 /* Initialize this module. */
6461dac9a9f2 * mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff changeset
299
24471
f66b3a3509c7 Excise DL_EXPORT/DL_IMPORT from Modules/*. Required adding a prototype
Mark Hammond <mhammond@skippinet.com.au>
parents: 24283
diff changeset
300 PyMODINIT_FUNC
35375
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents: 29787
diff changeset
301 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
302 {
20850
2962f01924c9 Simplify initmd5() to use PyModule_AddIntConstant().
Fred Drake <fdrake@acm.org>
parents: 20843
diff changeset
303 PyObject *m, *d;
11711
6546ea06e157 Patch from Paul Sokolovsky <Paul.Sokolovsky@technologist.com>:
Fred Drake <fdrake@acm.org>
parents: 9588
diff changeset
304
44350
26384b8180c7 #1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT. Macros for b/w compatibility are available.
Christian Heimes <christian@cheimes.de>
parents: 42333
diff changeset
305 Py_TYPE(&MD5type) = &PyType_Type;
35375
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents: 29787
diff changeset
306 if (PyType_Ready(&MD5type) < 0)
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents: 29787
diff changeset
307 return;
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents: 29787
diff changeset
308 m = Py_InitModule3("_md5", md5_functions, module_doc);
36324
1af7f719ed28 Check return result from Py_InitModule*(). This API can fail.
Neal Norwitz <nnorwitz@gmail.com>
parents: 35375
diff changeset
309 if (m == NULL)
1af7f719ed28 Check return result from Py_InitModule*(). This API can fail.
Neal Norwitz <nnorwitz@gmail.com>
parents: 35375
diff changeset
310 return;
9363
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
311 d = PyModule_GetDict(m);
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
312 PyDict_SetItemString(d, "MD5Type", (PyObject *)&MD5type);
20850
2962f01924c9 Simplify initmd5() to use PyModule_AddIntConstant().
Fred Drake <fdrake@acm.org>
parents: 20843
diff changeset
313 PyModule_AddIntConstant(m, "digest_size", 16);
9363
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
314 /* 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
315 }