diff options
author | andreast <andreast@138bc75d-0d04-0410-961f-82ee72b054a4> | 2004-10-12 10:13:39 +0000 |
---|---|---|
committer | andreast <andreast@138bc75d-0d04-0410-961f-82ee72b054a4> | 2004-10-12 10:13:39 +0000 |
commit | 0f92c147c6e8331155d95f149e0780e4a90c5d41 (patch) | |
tree | 079b5f6d184f15fefb94d0456d0e92bd03a90688 /libjava/testsuite | |
parent | 7b2e65559c99e26c92a57385a8f61adef9206297 (diff) | |
download | gcc-0f92c147c6e8331155d95f149e0780e4a90c5d41.tar.gz |
2004-10-12 Rutger Ovidius <ovidr@users.sourceforge.net>
PR libgcj/17903:
* testsuite/libjava.lang/md5test.java: New file.
* testsuite/libjava.lang/md5test.out: Likewise.
* testsuite/libjava.lang/shatest.java: Likewise.
* testsuite/libjava.lang/shatest.out: Likewise.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@88922 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/testsuite')
-rw-r--r-- | libjava/testsuite/libjava.lang/md5test.java | 63 | ||||
-rw-r--r-- | libjava/testsuite/libjava.lang/md5test.out | 12 | ||||
-rw-r--r-- | libjava/testsuite/libjava.lang/shatest.java | 39 | ||||
-rw-r--r-- | libjava/testsuite/libjava.lang/shatest.out | 2 |
4 files changed, 116 insertions, 0 deletions
diff --git a/libjava/testsuite/libjava.lang/md5test.java b/libjava/testsuite/libjava.lang/md5test.java new file mode 100644 index 00000000000..ffd0a93cf75 --- /dev/null +++ b/libjava/testsuite/libjava.lang/md5test.java @@ -0,0 +1,63 @@ +import java.security.*; + +class md5test { + + + // gnu-crypto/source/gnu/testlet/gnu/crypto/hash/TestOfMD5.java + + public static void main(String[] argv) { + String[] strings = { + "a", + "abc", + "message digest", + "abcdefghijklmnopqrstuvwxyz", + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", + "12345678901234567890123456789012345678901234567890123456789012345678901234567890" + }; + + String[] expected = { + "0CC175B9C0F1B6A831C399E269772661", + "900150983CD24FB0D6963F7D28E17F72", + "F96B697D7CB7938D525A2F31AAF161D0", + "C3FCD3D76192E4007DFB496CCA67E13B", + "D174AB98D277D9F5A5611C2C9F419D9F", + "57EDF4A22BE3C955AC49DA2E2107B67A" + }; + + for (int i = 0; i < strings.length; i++) + testString(strings[i], expected[i]); + + } + + public static void testString(String string, String expected) { + + MessageDigest md=null; + try { + md = MessageDigest.getInstance("MD5"); + md.update(string.getBytes(), 0, string.length()); + String result = toString(md.digest()); + System.out.println(expected); + System.out.println(result); + if (!expected.equals(result)) + System.out.println("NOT EQUAL!"); + } catch (Exception x) { + x.printStackTrace(); + } + } + + public static String toString(byte[] ba) { + return toString(ba, 0, ba.length); + } + public static final String toString(byte[] ba, int offset, int length) { + char[] buf = new char[length * 2]; + for (int i = 0, j = 0, k; i < length; ) { + k = ba[offset + i++]; + buf[j++] = HEX_DIGITS[(k >>> 4) & 0x0F]; + buf[j++] = HEX_DIGITS[ k & 0x0F]; + } + return new String(buf); + } + + private static final char[] HEX_DIGITS = "0123456789ABCDEF".toCharArray(); + +} diff --git a/libjava/testsuite/libjava.lang/md5test.out b/libjava/testsuite/libjava.lang/md5test.out new file mode 100644 index 00000000000..0dd90c39da4 --- /dev/null +++ b/libjava/testsuite/libjava.lang/md5test.out @@ -0,0 +1,12 @@ +0CC175B9C0F1B6A831C399E269772661 +0CC175B9C0F1B6A831C399E269772661 +900150983CD24FB0D6963F7D28E17F72 +900150983CD24FB0D6963F7D28E17F72 +F96B697D7CB7938D525A2F31AAF161D0 +F96B697D7CB7938D525A2F31AAF161D0 +C3FCD3D76192E4007DFB496CCA67E13B +C3FCD3D76192E4007DFB496CCA67E13B +D174AB98D277D9F5A5611C2C9F419D9F +D174AB98D277D9F5A5611C2C9F419D9F +57EDF4A22BE3C955AC49DA2E2107B67A +57EDF4A22BE3C955AC49DA2E2107B67A diff --git a/libjava/testsuite/libjava.lang/shatest.java b/libjava/testsuite/libjava.lang/shatest.java new file mode 100644 index 00000000000..4cc6d4f4182 --- /dev/null +++ b/libjava/testsuite/libjava.lang/shatest.java @@ -0,0 +1,39 @@ +import java.security.*; + +class shatest { + + // gnu-crypto/source/gnu/testlet/gnu/crypto/hash/TestOfSha160.java + + public static void main(String[] argv) { + MessageDigest md=null; + try { + md = MessageDigest.getInstance("SHA-1"); + } catch (Exception e) { + e.printStackTrace(); + } + md.update("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq".getBytes(), 0, 56); + String exp = "84983E441C3BD26EBAAE4AA1F95129E5E54670F1"; + String result = toString(md.digest()); + System.out.println(exp); + System.out.println(result); + if (!exp.equals(result)) + System.out.println("NOT EQUAL!"); + + } + + public static String toString(byte[] ba) { + return toString(ba, 0, ba.length); + } + public static final String toString(byte[] ba, int offset, int length) { + char[] buf = new char[length * 2]; + for (int i = 0, j = 0, k; i < length; ) { + k = ba[offset + i++]; + buf[j++] = HEX_DIGITS[(k >>> 4) & 0x0F]; + buf[j++] = HEX_DIGITS[ k & 0x0F]; + } + return new String(buf); + } + + private static final char[] HEX_DIGITS = "0123456789ABCDEF".toCharArray(); + +} diff --git a/libjava/testsuite/libjava.lang/shatest.out b/libjava/testsuite/libjava.lang/shatest.out new file mode 100644 index 00000000000..3c19286fab6 --- /dev/null +++ b/libjava/testsuite/libjava.lang/shatest.out @@ -0,0 +1,2 @@ +84983E441C3BD26EBAAE4AA1F95129E5E54670F1 +84983E441C3BD26EBAAE4AA1F95129E5E54670F1 |