annotate Modules/md5module.c @ 12357:5b59ea41db4e legacy-trunk

Install the docs (with fewer rules). Add descriptions for the system variables.
author Guido van Rossum <guido@python.org>
date Mon, 10 Apr 2000 19:36:27 +0000
parents dc65c5f6ad7c
children 1c7c2dd1beb1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1132
6461dac9a9f2 * mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff changeset
1 /***********************************************************
2061
172ba04a5191 Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents: 2055
diff changeset
2 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
172ba04a5191 Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents: 2055
diff changeset
3 The Netherlands.
1132
6461dac9a9f2 * mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff changeset
4
6461dac9a9f2 * mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff changeset
5 All Rights Reserved
6461dac9a9f2 * mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff changeset
6
4503
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 2860
diff changeset
7 Permission to use, copy, modify, and distribute this software and its
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 2860
diff changeset
8 documentation for any purpose and without fee is hereby granted,
1132
6461dac9a9f2 * mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff changeset
9 provided that the above copyright notice appear in all copies and that
4503
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 2860
diff changeset
10 both that copyright notice and this permission notice appear in
1132
6461dac9a9f2 * mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff changeset
11 supporting documentation, and that the names of Stichting Mathematisch
4503
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 2860
diff changeset
12 Centrum or CWI or Corporation for National Research Initiatives or
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 2860
diff changeset
13 CNRI not be used in advertising or publicity pertaining to
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 2860
diff changeset
14 distribution of the software without specific, written prior
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 2860
diff changeset
15 permission.
1132
6461dac9a9f2 * mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff changeset
16
4503
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 2860
diff changeset
17 While CWI is the initial source for this software, a modified version
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 2860
diff changeset
18 is made available by the Corporation for National Research Initiatives
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 2860
diff changeset
19 (CNRI) at the Internet address ftp://ftp.python.org.
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 2860
diff changeset
20
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 2860
diff changeset
21 STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 2860
diff changeset
22 REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 2860
diff changeset
23 MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 2860
diff changeset
24 CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 2860
diff changeset
25 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 2860
diff changeset
26 PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 2860
diff changeset
27 TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 2860
diff changeset
28 PERFORMANCE OF THIS SOFTWARE.
1132
6461dac9a9f2 * mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff changeset
29
6461dac9a9f2 * mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff changeset
30 ******************************************************************/
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1418
diff changeset
31
1132
6461dac9a9f2 * mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff changeset
32 /* MD5 module */
6461dac9a9f2 * mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff changeset
33
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1418
diff changeset
34 /* 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
35 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
36 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
37 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
38
1132
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 /* MD5 objects */
6461dac9a9f2 * mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff changeset
41
4635
49745ddb4f69 Renamed
Barry Warsaw <barry@python.org>
parents: 4503
diff changeset
42 #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
43 #include "md5.h"
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 typedef struct {
4635
49745ddb4f69 Renamed
Barry Warsaw <barry@python.org>
parents: 4503
diff changeset
46 PyObject_HEAD
1132
6461dac9a9f2 * mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff changeset
47 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
48 } md5object;
6461dac9a9f2 * mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff changeset
49
4635
49745ddb4f69 Renamed
Barry Warsaw <barry@python.org>
parents: 4503
diff changeset
50 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
51
6461dac9a9f2 * mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff changeset
52 #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
53
6461dac9a9f2 * mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff changeset
54 static md5object *
6461dac9a9f2 * mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff changeset
55 newmd5object()
6461dac9a9f2 * mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff changeset
56 {
6461dac9a9f2 * mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff changeset
57 md5object *md5p;
6461dac9a9f2 * mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff changeset
58
4635
49745ddb4f69 Renamed
Barry Warsaw <barry@python.org>
parents: 4503
diff changeset
59 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
60 if (md5p == NULL)
6461dac9a9f2 * mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff changeset
61 return NULL;
6461dac9a9f2 * mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff changeset
62
6461dac9a9f2 * mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff changeset
63 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
64 return md5p;
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1418
diff changeset
65 }
1132
6461dac9a9f2 * mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff changeset
66
6461dac9a9f2 * mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff changeset
67
6461dac9a9f2 * mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff changeset
68 /* MD5 methods */
6461dac9a9f2 * mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff changeset
69
6461dac9a9f2 * mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff changeset
70 static void
6461dac9a9f2 * mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff changeset
71 md5_dealloc(md5p)
6461dac9a9f2 * mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff changeset
72 md5object *md5p;
6461dac9a9f2 * mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff changeset
73 {
4635
49745ddb4f69 Renamed
Barry Warsaw <barry@python.org>
parents: 4503
diff changeset
74 PyMem_DEL(md5p);
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1418
diff changeset
75 }
1132
6461dac9a9f2 * mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff changeset
76
6461dac9a9f2 * mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff changeset
77
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1418
diff changeset
78 /* MD5 methods-as-attributes */
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1418
diff changeset
79
4635
49745ddb4f69 Renamed
Barry Warsaw <barry@python.org>
parents: 4503
diff changeset
80 static PyObject *
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1418
diff changeset
81 md5_update(self, args)
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1418
diff changeset
82 md5object *self;
4635
49745ddb4f69 Renamed
Barry Warsaw <barry@python.org>
parents: 4503
diff changeset
83 PyObject *args;
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 unsigned char *cp;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1418
diff changeset
86 int len;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1418
diff changeset
87
4635
49745ddb4f69 Renamed
Barry Warsaw <barry@python.org>
parents: 4503
diff changeset
88 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
89 return NULL;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1418
diff changeset
90
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1418
diff changeset
91 MD5Update(&self->md5, cp, len);
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1418
diff changeset
92
4635
49745ddb4f69 Renamed
Barry Warsaw <barry@python.org>
parents: 4503
diff changeset
93 Py_INCREF(Py_None);
49745ddb4f69 Renamed
Barry Warsaw <barry@python.org>
parents: 4503
diff changeset
94 return Py_None;
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1418
diff changeset
95 }
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1418
diff changeset
96
9363
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
97 static char update_doc [] =
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
98 "update (arg)\n\
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
99 \n\
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
100 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
101 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
102 arguments.";
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
103
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
104
4635
49745ddb4f69 Renamed
Barry Warsaw <barry@python.org>
parents: 4503
diff changeset
105 static PyObject *
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1418
diff changeset
106 md5_digest(self, args)
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1418
diff changeset
107 md5object *self;
4635
49745ddb4f69 Renamed
Barry Warsaw <barry@python.org>
parents: 4503
diff changeset
108 PyObject *args;
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1418
diff changeset
109 {
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1418
diff changeset
110
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1418
diff changeset
111 MD5_CTX mdContext;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1418
diff changeset
112 unsigned char aDigest[16];
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1418
diff changeset
113
4635
49745ddb4f69 Renamed
Barry Warsaw <barry@python.org>
parents: 4503
diff changeset
114 if (!PyArg_NoArgs(args))
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1418
diff changeset
115 return NULL;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1418
diff changeset
116
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1418
diff changeset
117 /* 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
118 mdContext = self->md5;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1418
diff changeset
119 MD5Final(aDigest, &mdContext);
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1418
diff changeset
120
4635
49745ddb4f69 Renamed
Barry Warsaw <barry@python.org>
parents: 4503
diff changeset
121 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
122 }
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1418
diff changeset
123
9363
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
124 static char digest_doc [] =
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
125 "digest() -> string\n\
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
126 \n\
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
127 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
128 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
129 including null bytes.";
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
130
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
131
4635
49745ddb4f69 Renamed
Barry Warsaw <barry@python.org>
parents: 4503
diff changeset
132 static PyObject *
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1418
diff changeset
133 md5_copy(self, args)
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1418
diff changeset
134 md5object *self;
4635
49745ddb4f69 Renamed
Barry Warsaw <barry@python.org>
parents: 4503
diff changeset
135 PyObject *args;
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1418
diff changeset
136 {
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1418
diff changeset
137 md5object *md5p;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1418
diff changeset
138
4635
49745ddb4f69 Renamed
Barry Warsaw <barry@python.org>
parents: 4503
diff changeset
139 if (!PyArg_NoArgs(args))
1746
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 if ((md5p = newmd5object()) == NULL)
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1418
diff changeset
143 return NULL;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1418
diff changeset
144
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1418
diff changeset
145 md5p->md5 = self->md5;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1418
diff changeset
146
4635
49745ddb4f69 Renamed
Barry Warsaw <barry@python.org>
parents: 4503
diff changeset
147 return (PyObject *)md5p;
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1418
diff changeset
148 }
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1418
diff changeset
149
9363
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
150 static char copy_doc [] =
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
151 "copy() -> md5 object\n\
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
152 \n\
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
153 Return a copy (``clone'') of the md5 object.";
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
154
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
155
4635
49745ddb4f69 Renamed
Barry Warsaw <barry@python.org>
parents: 4503
diff changeset
156 static PyMethodDef md5_methods[] = {
9363
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
157 {"update", (PyCFunction)md5_update, 0, update_doc},
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
158 {"digest", (PyCFunction)md5_digest, 0, digest_doc},
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
159 {"copy", (PyCFunction)md5_copy, 0, copy_doc},
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1418
diff changeset
160 {NULL, NULL} /* sentinel */
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1418
diff changeset
161 };
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1418
diff changeset
162
4635
49745ddb4f69 Renamed
Barry Warsaw <barry@python.org>
parents: 4503
diff changeset
163 static PyObject *
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1418
diff changeset
164 md5_getattr(self, name)
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1418
diff changeset
165 md5object *self;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1418
diff changeset
166 char *name;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1418
diff changeset
167 {
4635
49745ddb4f69 Renamed
Barry Warsaw <barry@python.org>
parents: 4503
diff changeset
168 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
169 }
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1418
diff changeset
170
9363
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
171 static char module_doc [] =
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
172
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
173 "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
174 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
175 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
176 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
177 at any point you can ask it for the digest (a strong kind of 128-bit\n\
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
178 checksum, a.k.a. ``fingerprint'') of the contatenation of the strings\n\
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
179 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
180 \n\
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
181 Functions:\n\
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
182 \n\
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
183 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
184 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
185 \n\
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
186 Special Objects:\n\
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
187 \n\
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
188 MD5Type -- type object for md5 objects\n\
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
189 ";
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
190
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
191 static char md5type_doc [] =
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
192 "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
193 string of information.\n\
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
194 \n\
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
195 Methods:\n\
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
196 \n\
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
197 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
198 digest() -- return the current digest value\n\
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
199 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
200 ";
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
201
4635
49745ddb4f69 Renamed
Barry Warsaw <barry@python.org>
parents: 4503
diff changeset
202 statichere PyTypeObject MD5type = {
11711
6546ea06e157 Patch from Paul Sokolovsky <Paul.Sokolovsky@technologist.com>:
Fred Drake <fdrake@acm.org>
parents: 9588
diff changeset
203 PyObject_HEAD_INIT(NULL)
4635
49745ddb4f69 Renamed
Barry Warsaw <barry@python.org>
parents: 4503
diff changeset
204 0, /*ob_size*/
49745ddb4f69 Renamed
Barry Warsaw <barry@python.org>
parents: 4503
diff changeset
205 "md5", /*tp_name*/
49745ddb4f69 Renamed
Barry Warsaw <barry@python.org>
parents: 4503
diff changeset
206 sizeof(md5object), /*tp_size*/
49745ddb4f69 Renamed
Barry Warsaw <barry@python.org>
parents: 4503
diff changeset
207 0, /*tp_itemsize*/
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1418
diff changeset
208 /* methods */
4635
49745ddb4f69 Renamed
Barry Warsaw <barry@python.org>
parents: 4503
diff changeset
209 (destructor)md5_dealloc, /*tp_dealloc*/
49745ddb4f69 Renamed
Barry Warsaw <barry@python.org>
parents: 4503
diff changeset
210 0, /*tp_print*/
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1418
diff changeset
211 (getattrfunc)md5_getattr, /*tp_getattr*/
4635
49745ddb4f69 Renamed
Barry Warsaw <barry@python.org>
parents: 4503
diff changeset
212 0, /*tp_setattr*/
49745ddb4f69 Renamed
Barry Warsaw <barry@python.org>
parents: 4503
diff changeset
213 0, /*tp_compare*/
49745ddb4f69 Renamed
Barry Warsaw <barry@python.org>
parents: 4503
diff changeset
214 0, /*tp_repr*/
49745ddb4f69 Renamed
Barry Warsaw <barry@python.org>
parents: 4503
diff changeset
215 0, /*tp_as_number*/
9363
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
216 0, /*tp_as_sequence*/
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
217 0, /*tp_as_mapping*/
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
218 0, /*tp_hash*/
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
219 0, /*tp_call*/
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
220 0, /*tp_str*/
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
221 0, /*tp_getattro*/
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
222 0, /*tp_setattro*/
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
223 0, /*tp_as_buffer*/
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
224 0, /*tp_xxx4*/
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
225 md5type_doc, /*tp_doc*/
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1418
diff changeset
226 };
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1418
diff changeset
227
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1418
diff changeset
228
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1418
diff changeset
229 /* MD5 functions */
1132
6461dac9a9f2 * mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff changeset
230
4635
49745ddb4f69 Renamed
Barry Warsaw <barry@python.org>
parents: 4503
diff changeset
231 static PyObject *
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
232 MD5_new(self, args)
4635
49745ddb4f69 Renamed
Barry Warsaw <barry@python.org>
parents: 4503
diff changeset
233 PyObject *self;
49745ddb4f69 Renamed
Barry Warsaw <barry@python.org>
parents: 4503
diff changeset
234 PyObject *args;
1132
6461dac9a9f2 * mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff changeset
235 {
6461dac9a9f2 * mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff changeset
236 md5object *md5p;
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1418
diff changeset
237 unsigned char *cp = NULL;
2860
6ae9b377e522 use newgetargs
Guido van Rossum <guido@python.org>
parents: 2506
diff changeset
238 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
239
11882
dc65c5f6ad7c Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents: 11711
diff changeset
240 if (!PyArg_ParseTuple(args, "|s#:new", &cp, &len))
2860
6ae9b377e522 use newgetargs
Guido van Rossum <guido@python.org>
parents: 2506
diff changeset
241 return NULL;
1132
6461dac9a9f2 * mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff changeset
242
6461dac9a9f2 * mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff changeset
243 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
244 return NULL;
6461dac9a9f2 * mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff changeset
245
6461dac9a9f2 * mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff changeset
246 if (cp)
6461dac9a9f2 * mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff changeset
247 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
248
4635
49745ddb4f69 Renamed
Barry Warsaw <barry@python.org>
parents: 4503
diff changeset
249 return (PyObject *)md5p;
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1418
diff changeset
250 }
1132
6461dac9a9f2 * mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff changeset
251
9363
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
252 static char new_doc [] =
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
253 "new([arg]) -> md5 object\n\
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
254 \n\
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
255 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
256 is made.";
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
257
1132
6461dac9a9f2 * mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff changeset
258
6461dac9a9f2 * mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff changeset
259 /* 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
260
4635
49745ddb4f69 Renamed
Barry Warsaw <barry@python.org>
parents: 4503
diff changeset
261 static PyMethodDef md5_functions[] = {
9363
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
262 {"new", (PyCFunction)MD5_new, 1, new_doc},
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
263 {"md5", (PyCFunction)MD5_new, 1, new_doc}, /* Backward compatibility */
2860
6ae9b377e522 use newgetargs
Guido van Rossum <guido@python.org>
parents: 2506
diff changeset
264 {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
265 };
6461dac9a9f2 * mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff changeset
266
6461dac9a9f2 * mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff changeset
267
6461dac9a9f2 * mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff changeset
268 /* Initialize this module. */
6461dac9a9f2 * mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff changeset
269
9588
38023a425e48 Add DL_EXPORT() to all modules that could possibly be used
Guido van Rossum <guido@python.org>
parents: 9363
diff changeset
270 DL_EXPORT(void)
1132
6461dac9a9f2 * mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff changeset
271 initmd5()
6461dac9a9f2 * mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
diff changeset
272 {
9363
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
273 PyObject *m, *d;
11711
6546ea06e157 Patch from Paul Sokolovsky <Paul.Sokolovsky@technologist.com>:
Fred Drake <fdrake@acm.org>
parents: 9588
diff changeset
274
6546ea06e157 Patch from Paul Sokolovsky <Paul.Sokolovsky@technologist.com>:
Fred Drake <fdrake@acm.org>
parents: 9588
diff changeset
275 MD5type.ob_type = &PyType_Type;
9363
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
276 m = Py_InitModule3("md5", md5_functions, module_doc);
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
277 d = PyModule_GetDict(m);
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
278 PyDict_SetItemString(d, "MD5Type", (PyObject *)&MD5type);
f351c64c82ed Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 4635
diff changeset
279 /* 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
280 }