01: /*
02: * Created on 6/05/2006
03: *
04: * To change the template for this generated file go to
05: * Window>Preferences>Java>Code Generation>Code and Comments
06: */
07: package org.bouncycastle.crypto.test;
08:
09: import org.bouncycastle.crypto.ExtendedDigest;
10: import org.bouncycastle.crypto.digests.SHA1Digest;
11: import org.bouncycastle.crypto.digests.SHA512Digest;
12: import org.bouncycastle.crypto.digests.ShortenedDigest;
13: import org.bouncycastle.util.test.SimpleTest;
14:
15: public class ShortenedDigestTest extends SimpleTest {
16: public void performTest() {
17: ExtendedDigest d = new SHA1Digest();
18: ShortenedDigest sd = new ShortenedDigest(new SHA1Digest(), 10);
19:
20: if (sd.getDigestSize() != 10) {
21: fail("size check wrong for SHA-1");
22: }
23:
24: if (sd.getByteLength() != d.getByteLength()) {
25: fail("byte length check wrong for SHA-1");
26: }
27:
28: //
29: // check output fits
30: //
31: sd.doFinal(new byte[10], 0);
32:
33: d = new SHA512Digest();
34: sd = new ShortenedDigest(new SHA512Digest(), 20);
35:
36: if (sd.getDigestSize() != 20) {
37: fail("size check wrong for SHA-512");
38: }
39:
40: if (sd.getByteLength() != d.getByteLength()) {
41: fail("byte length check wrong for SHA-512");
42: }
43:
44: //
45: // check output fits
46: //
47: sd.doFinal(new byte[20], 0);
48:
49: try {
50: new ShortenedDigest(null, 20);
51:
52: fail("null parameter not caught");
53: } catch (IllegalArgumentException e) {
54: // expected
55: }
56:
57: try {
58: new ShortenedDigest(new SHA1Digest(), 50);
59:
60: fail("short digest not caught");
61: } catch (IllegalArgumentException e) {
62: // expected
63: }
64: }
65:
66: public String getName() {
67: return "ShortenedDigest";
68: }
69:
70: public static void main(String[] args) {
71: runTest(new ShortenedDigestTest());
72: }
73: }
|