01: // Copyright (c) Corporation for National Research Initiatives
02:
03: // This is a JPython module wrapper around Harry Mantakos' md.java class,
04: // which provides the basic MD5 algorithm. See also MD5Object.java which
05: // is the implementation of the md5 object returned by new() and md.java
06: // which provides the md5 implementation.
07:
08: package org.python.modules;
09:
10: import org.python.core.ClassDictInit;
11: import org.python.core.Py;
12: import org.python.core.PyBuiltinFunctionSet;
13: import org.python.core.PyObject;
14: import org.python.core.PyString;
15:
16: class MD5Functions extends PyBuiltinFunctionSet {
17: public MD5Functions(String name, int index, int minargs, int maxargs) {
18: super (name, index, minargs, maxargs);
19: }
20:
21: public PyObject __call__() {
22: switch (index) {
23: case 0:
24: return new MD5Object("");
25: default:
26: throw info.unexpectedCall(0, false);
27: }
28: }
29:
30: public PyObject __call__(PyObject arg1) {
31: switch (index) {
32: case 0:
33: return new MD5Object(arg1);
34: default:
35: throw info.unexpectedCall(1, false);
36: }
37: }
38: }
39:
40: public class MD5Module implements ClassDictInit {
41: public static PyString __doc__ = new PyString(
42: "This module implements the interface to RSA's MD5 message digest\n"
43: + "algorithm (see also Internet RFC 1321). Its use is quite\n"
44: + "straightforward: use the new() to create an md5 object. "
45: + "You can now\n"
46: + "feed this object with arbitrary strings using the update() method, "
47: + "and\n"
48: + "at any point you can ask it for the digest (a strong kind of "
49: + "128-bit\n"
50: + "checksum, a.k.a. ``fingerprint'') of the concatenation of the "
51: + "strings\n"
52: + "fed to it so far using the digest() method.\n"
53: + "\n"
54: + "Functions:\n"
55: + "\n"
56: + "new([arg]) -- return a new md5 object, initialized with arg if "
57: + "provided\n"
58: + "md5([arg]) -- DEPRECATED, same as new, but for compatibility\n"
59: + "\n" + "Special Objects:\n" + "\n"
60: + "MD5Type -- type object for md5 objects\n");
61:
62: public static void classDictInit(PyObject dict) {
63: dict.__setitem__("new", new MD5Functions("new", 0, 0, 1));
64: dict.__setitem__("md5", new MD5Functions("md5", 0, 0, 1));
65: dict.__setitem__("digest_size", Py.newInteger(16));
66: dict.__setitem__("classDictInit", null);
67: }
68: }
|