diff options
| author | Raif S. Naffah <raif@swiftdsl.com.au> | 2003-03-09 07:08:32 +0000 |
|---|---|---|
| committer | Raif S. Naffah <raif@swiftdsl.com.au> | 2003-03-09 07:08:32 +0000 |
| commit | 05a3dd045571e4c080d1ad793f2f2dc685aad014 (patch) | |
| tree | ef18dab9f25fd668ea8cf4c993875c5b9ea19b9e /java/security/AlgorithmParameterGenerator.java | |
| parent | 90ea200ae1af086c0dc6564ac0de02d6ec0e4c5f (diff) | |
| download | classpath-05a3dd045571e4c080d1ad793f2f2dc685aad014.tar.gz | |
(getInstance(String)): use new getInstance(String, Provider).
(getInstance(String, String)): ditto.
(getInstance(String, Provider)): new method.
Diffstat (limited to 'java/security/AlgorithmParameterGenerator.java')
| -rw-r--r-- | java/security/AlgorithmParameterGenerator.java | 61 |
1 files changed, 55 insertions, 6 deletions
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 <code>provider</code> + * 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, |
