1 // Tags: JDK1.2 |
|
2 // |
|
3 // Uses: MauveDigest |
|
4 |
|
5 // Copyright (C) 2002 Free Software Foundation, Inc. |
|
6 // Written by Mark Wielaard (mark@klomp.org) |
|
7 |
|
8 // This file is part of Mauve. |
|
9 |
|
10 // Mauve is free software; you can redistribute it and/or modify |
|
11 // it under the terms of the GNU General Public License as published by |
|
12 // the Free Software Foundation; either version 2, or (at your option) |
|
13 // any later version. |
|
14 |
|
15 // Mauve is distributed in the hope that it will be useful, |
|
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
18 // GNU General Public License for more details. |
|
19 |
|
20 // You should have received a copy of the GNU General Public License |
|
21 // along with Mauve; see the file COPYING. If not, write to |
|
22 // the Free Software Foundation, 59 Temple Place - Suite 330, |
|
23 // Boston, MA 02111-1307, USA. */ |
|
24 |
|
25 package gnu.testlet.java.security.MessageDigest; |
|
26 |
|
27 import gnu.testlet.Testlet; |
|
28 import gnu.testlet.TestHarness; |
|
29 |
|
30 import java.security.Security; |
|
31 import java.security.Provider; |
|
32 import java.security.MessageDigest; |
|
33 import java.security.GeneralSecurityException; |
|
34 |
|
35 public class Instance extends Provider implements Testlet |
|
36 { |
|
37 static final String NAME = "Mauve-Test-Provider-Digest"; |
|
38 static final double VERSION = 3.14; |
|
39 static final String INFO = "Mauve Info-Test implements MauveDigest"; |
|
40 |
|
41 TestHarness harness; |
|
42 |
|
43 public Instance() |
|
44 { |
|
45 super(NAME, VERSION, INFO); |
|
46 |
|
47 put("MessageDigest.MauveDigest", |
|
48 "gnu.testlet.java.security.MessageDigest.MauveDigest"); |
|
49 put("Alg.Alias.MessageDigest.MauveAlias", "MauveDigest"); |
|
50 } |
|
51 |
|
52 void checkDigest(String name) |
|
53 { |
|
54 checkDigest(name, null); |
|
55 } |
|
56 |
|
57 void checkDigest(String name, String provider) |
|
58 { |
|
59 String checkPoint = name + (provider == null ? "" : " " + provider); |
|
60 harness.checkPoint(checkPoint); |
|
61 |
|
62 MessageDigest d; |
|
63 try |
|
64 { |
|
65 if (provider == null) |
|
66 d = MessageDigest.getInstance(name); |
|
67 else |
|
68 d = MessageDigest.getInstance(name, provider); |
|
69 } |
|
70 catch (GeneralSecurityException gse) |
|
71 { |
|
72 harness.fail(checkPoint + " caught " + gse); |
|
73 return; |
|
74 } |
|
75 |
|
76 // Just make sure we got the correct MessageDigest |
|
77 harness.check(d.getAlgorithm(), name); |
|
78 harness.check(d.getProvider(), this); |
|
79 |
|
80 // Do some of our dummy operations |
|
81 d.reset(); |
|
82 byte[] digest; |
|
83 digest = d.digest(); |
|
84 harness.check(digest.length, 0); |
|
85 |
|
86 byte[] message = new byte[] {0, 1, 2, 3}; |
|
87 digest = d.digest(message); |
|
88 harness.check(MessageDigest.isEqual(digest, message)); |
|
89 |
|
90 d.update((byte)6); |
|
91 byte[] bs = d.digest(); |
|
92 harness.check(bs[0], (byte)6); |
|
93 } |
|
94 |
|
95 public void test (TestHarness h) |
|
96 { |
|
97 this.harness = h; |
|
98 Security.addProvider(this); |
|
99 |
|
100 checkDigest("MauveDigest"); |
|
101 checkDigest("MAUVEDIGEST"); |
|
102 checkDigest("MauveAlias"); |
|
103 checkDigest("MAUVEALIAS"); |
|
104 |
|
105 checkDigest("MauveDigest", NAME); |
|
106 checkDigest("MAUVEDIGEST", NAME); |
|
107 checkDigest("MauveAlias", NAME); |
|
108 checkDigest("MAUVEALIAS", NAME); |
|
109 } |
|
110 } |
|
111 |
|