-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathBaseTest.java
More file actions
150 lines (131 loc) · 4.58 KB
/
BaseTest.java
File metadata and controls
150 lines (131 loc) · 4.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/*
* Copyright IBM Corp. 2025, 2026
*
* This code is free software; you can redistribute it and/or modify it
* under the terms provided by IBM in the LICENSE file that accompanied
* this code, including the "Classpath" Exception described therein.
*/
package ibm.jceplus.junit.tests;
import java.security.Provider;
abstract public class BaseTest {
private String providerName;
private int keysize = -1;
private String algo = null;
/**
* Sets the provider name that is to be used to execute this test.
*
* @param providerName the provider name associated with this test case for use.
*/
public void setProviderName(String providerName) {
this.providerName = providerName;
}
public void setAndInsertProvider(TestProvider provider) throws Exception {
this.providerName = provider.getProviderName();
loadSupportedProvider(provider);
}
public void setAndInsertInteropProvider(TestProvider interopProvider) throws Exception {
loadSupportedProvider(interopProvider);
}
protected void loadSupportedProvider(TestProvider provider) throws Exception {
switch (provider) {
case BC:
loadProvider(TestProvider.BC);
break;
case SUN:
loadProvider(TestProvider.SUN);
break;
case SunJCE:
loadProvider(TestProvider.SunJCE);
break;
case SunRsaSign:
loadProvider(TestProvider.SunRsaSign);
break;
case SunEC:
loadProvider(TestProvider.SunEC);
break;
case OpenJCEPlus:
loadProvider(TestProvider.OpenJCEPlus);
break;
case OpenJCEPlusFIPS:
loadProvider(TestProvider.OpenJCEPlusFIPS);
break;
default:
throw new Exception("Provider not supported: " + provider.getProviderName());
}
}
private static Provider loadProvider(TestProvider testProvider) throws Exception {
String providerName = testProvider.getProviderName();
String providerClassName = testProvider.getProviderClassName();
Provider provider = java.security.Security.getProvider(providerName);
if (provider == null) {
provider = (Provider) Class.forName(providerClassName).getDeclaredConstructor().newInstance();
java.security.Security.insertProviderAt(provider, 0);
}
return provider;
}
/**
* Gets the provider name that is to be used to execute this test.
*
* @return The provider name associated with this test case for use.
*/
public String getProviderName() {
if (this.providerName == null) {
throw new RuntimeException("Provider name is null.");
}
return this.providerName;
}
/**
* Sets the algorithm associated with this test.
* @param algorithm
*/
public void setAlgorithm(String algorithm) {
this.algo = algorithm;
}
/**
* Gets the algorithm associated with this test.
* @return
*/
public String getAlgorithm() {
if (this.algo == null) {
throw new RuntimeException("Algorithm name is null.");
}
return this.algo;
}
/**
* Sets the key size associated with this test.
* @param keySize
*/
public void setKeySize(int keySize) {
this.keysize = keySize;
}
/**
* Gets the key size associated with this test.
* @return
*/
public int getKeySize() {
if (this.keysize == -1) {
throw new RuntimeException("Key size is not correct.");
}
return this.keysize;
}
/**
* Returns the tags from the -Dgroups system property.
* If no groups property is set, returns an empty array.
* @return String array of tag names from the groups property
*/
public static String[] getTagsPropertyAsArray() {
String groupsProperty = System.getProperty("groups");
if (groupsProperty != null && !groupsProperty.trim().isEmpty()) {
// Parse the comma-delimited list of groups and return as array
String[] groups = groupsProperty.split(",");
String[] trimmedGroups = new String[groups.length];
for (int i = 0; i < groups.length; i++) {
trimmedGroups[i] = groups[i].trim();
}
return trimmedGroups;
} else {
// If no -Dgroups specified, return empty
return new String[0];
}
}
}