Index: src/org/python/modules/sha.java =================================================================== --- src/org/python/modules/sha.java (revision 2973) +++ src/org/python/modules/sha.java (working copy) @@ -2,13 +2,10 @@ package org.python.modules; +import java.io.UnsupportedEncodingException; import org.python.core.*; -public class sha { - public int blocksize = 1; - public int digestsize = 20; - public int digest_size = digestsize; - +public class sha implements ClassDictInit { public static String __doc__ = "* Cryptix General License\n" + "* Copyright (c) 1995, 1996, 1997, 1998, 1999, 2000 The Cryptix"+ @@ -47,8 +44,13 @@ String cp = ap.getString(0, null); SHA1 n = new SHA1(); - if (cp != null) - n.update(cp.getBytes()); + if (cp != null) { + try { + n.update(cp.getBytes("ISO-8859-1")); + } catch (UnsupportedEncodingException exc) { + throw Py.ValueError("encoding not supported"); + } + } return n; } @@ -56,4 +58,11 @@ public static SHA1 sha$(PyObject[] args, String[] kws) { return new$(args, kws); } + + public static void classDictInit(PyObject dict) { + dict.__setitem__("digest_size", Py.newInteger(20)); + dict.__setitem__("digestsize", Py.newInteger(20)); + dict.__setitem__("blocksize", Py.newInteger(1)); + dict.__setitem__("classDictInit", null); + } } Index: src/org/python/modules/MD5Object.java =================================================================== --- src/org/python/modules/MD5Object.java (revision 2973) +++ src/org/python/modules/MD5Object.java (working copy) @@ -9,6 +9,8 @@ { private String data; + public int digest_size = 16; + public MD5Object(String s) { data = s; } Index: src/org/python/modules/SHA1.java =================================================================== --- src/org/python/modules/SHA1.java (revision 2973) +++ src/org/python/modules/SHA1.java (working copy) @@ -43,7 +43,8 @@ package org.python.modules; -import org.python.core.PyString; +import java.io.UnsupportedEncodingException; +import org.python.core.*; /** * This class implements the SHA-1 message digest algorithm. @@ -89,9 +90,9 @@ */ private long count; + public int digest_size = 20; - /** * SPI: Updates the message digest with a byte of new data. * @@ -162,9 +163,6 @@ private byte[] tmp; private int[] w; - private byte[] digestBits; - - /** * Constructs a SHA-1 message digest. */ @@ -242,14 +240,14 @@ protected byte[] engineDigest(byte[] in, int length) { byte b[] = java_digest(in, length); - engineReset(); return b; } private byte[] java_digest(byte[] in, int pos) { + int[] digest_save = (int[]) digest.clone(); if (pos != 0) System.arraycopy(in, 0, tmp, 0, pos); - + tmp[pos++] = (byte)0x80; if (pos > DATA_LENGTH - 8) @@ -287,6 +285,7 @@ buf[off++] = (byte) (d>>>8); buf[off++] = (byte) d; } + digest = digest_save; return buf; } @@ -471,8 +470,7 @@ * to the test vectors. */ public String hexdigest() { - if (digestBits == null) - digestBits = engineDigest(); + byte[] digestBits = engineDigest(); StringBuffer sb = new StringBuffer(); for (int i = 0; i < 20; i++) { @@ -494,9 +492,12 @@ ); public String digest() { - if (digestBits == null) - digestBits = engineDigest(); - return new String(digestBits); + byte[] digestBits = engineDigest(); + try { + return new String(digestBits, "ISO-8859-1"); + } catch (UnsupportedEncodingException exc) { + throw Py.ValueError("encoding not supported"); + } } // XXX should become PyObject and use Py.idstr?