From 05a3dd045571e4c080d1ad793f2f2dc685aad014 Mon Sep 17 00:00:00 2001 From: "Raif S. Naffah" Date: Sun, 9 Mar 2003 07:08:32 +0000 Subject: (getInstance(String)): use new getInstance(String, Provider). (getInstance(String, String)): ditto. (getInstance(String, Provider)): new method. --- java/security/AlgorithmParameterGenerator.java | 61 +++++++++++++++++++++++--- 1 file changed, 55 insertions(+), 6 deletions(-) (limited to 'java/security/AlgorithmParameterGenerator.java') diff --git a/java/security/AlgorithmParameterGenerator.java b/java/security/AlgorithmParameterGenerator.java index 77c9e1afd..bbc3b90a5 100644 --- a/java/security/AlgorithmParameterGenerator.java +++ b/java/security/AlgorithmParameterGenerator.java @@ -130,11 +130,11 @@ public class AlgorithmParameterGenerator { Provider[] p = Security.getProviders(); for (int i = 0; i < p.length; i++) - { - String classname = p[i].getProperty("AlgorithmParameterGenerator." + algorithm); - if (classname != null) - return getInstance(classname, algorithm, p[i]); - } + try + { + getInstance(algorithm, p[i]); + } + catch (NoSuchAlgorithmException ignored) {} throw new NoSuchAlgorithmException(algorithm); } @@ -163,7 +163,56 @@ public class AlgorithmParameterGenerator if (p == null) throw new NoSuchProviderException(); - return getInstance(p.getProperty("AlgorithmParameterGenerator." + algorithm), algorithm, p); + return getInstance(algorithm, p); + } + + /** + * Generates an AlgorithmParameterGenerator object for the requested + * algorithm, as supplied from the specified provider, if such a parameter + * generator is available from the provider. Note: the provider + * doesn't have to be registered. + * + * @param algorithm the string name of the algorithm. + * @param provider the provider. + * @return the new AlgorithmParameterGenerator object. + * @throws NoSuchAlgorithmException if the algorithm is not available from + * the provider. + * @throws IllegalArgumentException if the provider is null. + * @since 1.4 + * @see Provider + */ + public static AlgorithmParameterGenerator getInstance(String algorithm, + Provider provider) + throws NoSuchAlgorithmException + { + if (provider == null) + throw new IllegalArgumentException(); + + // try the name as is + String className = provider.getProperty( + "AlgorithmParameterGenerator." + algorithm); + if (className == null) // try all uppercase + { + String upper = algorithm.toUpperCase(); + className = provider.getProperty("AlgorithmParameterGenerator." + upper); + if (className == null) // try if it's an alias + { + String alias = provider.getProperty( + "Alg.Alias.AlgorithmParameterGenerator." + algorithm); + if (alias == null) // try all-uppercase alias name + { + alias = provider.getProperty( + "Alg.Alias.AlgorithmParameterGenerator." + upper); + if (alias == null) // spit the dummy + throw new NoSuchAlgorithmException(algorithm); + } + className = provider.getProperty( + "AlgorithmParameterGenerator." + alias); + if (className == null) + throw new NoSuchAlgorithmException(algorithm); + } + } + return getInstance(className, algorithm, provider); } private static AlgorithmParameterGenerator getInstance(String classname, -- cgit v1.2.1