220 }
221
222
223 private static class SupportedSignatureAlgorithmConstraints
224 implements AlgorithmConstraints {
225 // supported signature algorithms
226 private String[] supportedAlgorithms;
227
228 SupportedSignatureAlgorithmConstraints(String[] supportedAlgorithms) {
229 if (supportedAlgorithms != null) {
230 this.supportedAlgorithms = supportedAlgorithms.clone();
231 } else {
232 this.supportedAlgorithms = null;
233 }
234 }
235
236 @Override
237 public boolean permits(Set<CryptoPrimitive> primitives,
238 String algorithm, AlgorithmParameters parameters) {
239
240 if (algorithm == null || algorithm.length() == 0) {
241 throw new IllegalArgumentException(
242 "No algorithm name specified");
243 }
244
245 if (primitives == null || primitives.isEmpty()) {
246 throw new IllegalArgumentException(
247 "No cryptographic primitive specified");
248 }
249
250 if (supportedAlgorithms == null ||
251 supportedAlgorithms.length == 0) {
252 return false;
253 }
254
255 // trim the MGF part: <digest>with<encryption>and<mgf>
256 int position = algorithm.indexOf("and");
257 if (position > 0) {
258 algorithm = algorithm.substring(0, position);
259 }
260
261 for (String supportedAlgorithm : supportedAlgorithms) {
262 if (algorithm.equalsIgnoreCase(supportedAlgorithm)) {
263 return true;
264 }
265 }
266
267 return false;
268 }
269
270 @Override
271 public final boolean permits(Set<CryptoPrimitive> primitives, Key key) {
272 return true;
273 }
274
275 @Override
276 public final boolean permits(Set<CryptoPrimitive> primitives,
277 String algorithm, Key key, AlgorithmParameters parameters) {
278
279 if (algorithm == null || algorithm.length() == 0) {
280 throw new IllegalArgumentException(
281 "No algorithm name specified");
282 }
283
284 return permits(primitives, algorithm, parameters);
285 }
286 }
287 }
|
220 }
221
222
223 private static class SupportedSignatureAlgorithmConstraints
224 implements AlgorithmConstraints {
225 // supported signature algorithms
226 private String[] supportedAlgorithms;
227
228 SupportedSignatureAlgorithmConstraints(String[] supportedAlgorithms) {
229 if (supportedAlgorithms != null) {
230 this.supportedAlgorithms = supportedAlgorithms.clone();
231 } else {
232 this.supportedAlgorithms = null;
233 }
234 }
235
236 @Override
237 public boolean permits(Set<CryptoPrimitive> primitives,
238 String algorithm, AlgorithmParameters parameters) {
239
240 if (algorithm == null || algorithm.isEmpty()) {
241 throw new IllegalArgumentException(
242 "No algorithm name specified");
243 }
244
245 if (primitives == null || primitives.isEmpty()) {
246 throw new IllegalArgumentException(
247 "No cryptographic primitive specified");
248 }
249
250 if (supportedAlgorithms == null ||
251 supportedAlgorithms.length == 0) {
252 return false;
253 }
254
255 // trim the MGF part: <digest>with<encryption>and<mgf>
256 int position = algorithm.indexOf("and");
257 if (position > 0) {
258 algorithm = algorithm.substring(0, position);
259 }
260
261 for (String supportedAlgorithm : supportedAlgorithms) {
262 if (algorithm.equalsIgnoreCase(supportedAlgorithm)) {
263 return true;
264 }
265 }
266
267 return false;
268 }
269
270 @Override
271 public final boolean permits(Set<CryptoPrimitive> primitives, Key key) {
272 return true;
273 }
274
275 @Override
276 public final boolean permits(Set<CryptoPrimitive> primitives,
277 String algorithm, Key key, AlgorithmParameters parameters) {
278
279 if (algorithm == null || algorithm.isEmpty()) {
280 throw new IllegalArgumentException(
281 "No algorithm name specified");
282 }
283
284 return permits(primitives, algorithm, parameters);
285 }
286 }
287 }
|