KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > python > modules > MD5Module


1 // Copyright (c) Corporation for National Research Initiatives
2

3 // This is a JPython module wrapper around Harry Mantakos' md.java class,
4
// which provides the basic MD5 algorithm. See also MD5Object.java which
5
// is the implementation of the md5 object returned by new() and md.java
6
// which provides the md5 implementation.
7

8 package org.python.modules;
9
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 {
18     public MD5Functions(String JavaDoc name, int index, int minargs, int maxargs) {
19         super(name, index, minargs, maxargs, false, null);
20     }
21
22     public PyObject __call__() {
23         switch (index) {
24         case 0:
25             return new MD5Object("");
26         default:
27             throw argCountError(0);
28         }
29     }
30
31     public PyObject __call__(PyObject arg1) {
32         switch (index) {
33         case 0:
34             return new MD5Object(arg1);
35         default:
36             throw argCountError(1);
37         }
38     }
39 }
40
41 public class MD5Module implements ClassDictInit
42 {
43     public static PyString __doc__ = new PyString(
44         "This module implements the interface to RSA's MD5 message digest\n"+
45         "algorithm (see also Internet RFC 1321). Its use is quite\n"+
46         "straightforward: use the new() to create an md5 object. "+
47             "You can now\n"+
48         "feed this object with arbitrary strings using the update() method, "+
49             "and\n"+
50         "at any point you can ask it for the digest (a strong kind of "+
51             "128-bit\n"+
52         "checksum, a.k.a. ``fingerprint'') of the concatenation of the "+
53             "strings\n"+
54         "fed to it so far using the digest() method.\n"+
55         "\n"+
56         "Functions:\n"+
57         "\n"+
58         "new([arg]) -- return a new md5 object, initialized with arg if "+
59             "provided\n"+
60         "md5([arg]) -- DEPRECATED, same as new, but for compatibility\n"+
61         "\n"+
62         "Special Objects:\n"+
63         "\n"+
64         "MD5Type -- type object for md5 objects\n"
65     );
66
67     public static void classDictInit(PyObject dict) {
68         dict.__setitem__("new", new MD5Functions("new", 0, 0, 1));
69         dict.__setitem__("md5", new MD5Functions("md5", 0, 0, 1));
70         dict.__setitem__("digest_size", Py.newInteger(16));
71         dict.__setitem__("classDictInit", null);
72     }
73 }
74
Popular Tags