diff options
author | Raif S. Naffah <raif@swiftdsl.com.au> | 2006-08-13 00:09:58 +0000 |
---|---|---|
committer | Raif S. Naffah <raif@swiftdsl.com.au> | 2006-08-13 00:09:58 +0000 |
commit | 04f3e82ec5a636855d68f80630d61355cf0560fb (patch) | |
tree | 680f41705bc16d10c63b8aea4c993e826cd14613 /javax/crypto/SecretKeyFactory.java | |
parent | ff16c332b4e181ea6b1e1175f3b504fb4e8e992b (diff) | |
download | classpath-04f3e82ec5a636855d68f80630d61355cf0560fb.tar.gz |
2006-08-13 Raif S. Naffah <raif@swiftdsl.com.au>
PR Classpath/28678
* gnu/java/security/Engine.java (getInstance(String, String, Provider)):
Updated documentation.
Formatting.
(getInstance(String, String, Provider, Object[])): Likewise.
Separate checks for null and empty string arguments.
Include as much information as possible in the exception's message.
Do not swallow original exception; instead use it as the cause of the
resulting exception.
* gnu/javax/security/auth/callback/AbstractCallbackHandler.java
(getInstance(String)): Updated documentation.
Formatting.
Store last exception caught when iterating through all providers.
If no implementation found, raise last exception if one was caught.
(getInstance(String, String)): Updated documentation.
Formatting.
Check for null or empty provider as per RI-5's documentation.
(getInstance(String, Provider)): Updated documentation.
Formatting.
Use as much information as possible in the exception message.
Do not swallow original exception; instead use it as the cause for the
ultimate raised exception(s).
* java/security/cert/CertificateFactory.java: Likewise.
* java/security/cert/CertPathBuilder.java: Likewise.
* java/security/cert/CertPathValidator.java: Likewise.
* java/security/cert/CertStore.java: Likewise.
* java/security/AlgorithmParameterGenerator.java: Likewise.
* java/security/AlgorithmParameters.java: Likewise.
* java/security/KeyFactory.java: Likewise.
* java/security/KeyPairGenerator.java: Likewise.
* java/security/KeyStore.java: Likewise.
* java/security/MessageDigest.java: Likewise.
* java/security/SecureRandom.java: Likewise.
* java/security/Signature.java: Likewise.
* javax/crypto/Cipher.java: Likewise.
* javax/crypto/ExemptionMechanism.java: Likewise.
* javax/crypto/KeyAgreement.java: Likewise.
* javax/crypto/KeyGenerator.java: Likewise.
* javax/crypto/Mac.java: Likewise.
* javax/crypto/SecretKeyFactory.java: Likewise.
* javax/net/ssl/KeyManagerFactory.java: Likewise.
* javax/net/ssl/SSLContext.java: Likewise.
* javax/net/ssl/TrustManagerFactory.java: Likewise.
Diffstat (limited to 'javax/crypto/SecretKeyFactory.java')
-rw-r--r-- | javax/crypto/SecretKeyFactory.java | 108 |
1 files changed, 58 insertions, 50 deletions
diff --git a/javax/crypto/SecretKeyFactory.java b/javax/crypto/SecretKeyFactory.java index 0a63ef067..1c857d274 100644 --- a/javax/crypto/SecretKeyFactory.java +++ b/javax/crypto/SecretKeyFactory.java @@ -94,94 +94,102 @@ public class SecretKeyFactory this.algorithm = algorithm; } - // Class methods. - // ------------------------------------------------------------------------ - /** - * Create a new secret key factory from the first appropriate - * instance. - * + * Create a new secret key factory from the first appropriate instance. + * * @param algorithm The algorithm name. * @return The appropriate key factory, if found. - * @throws java.security.NoSuchAlgorithmException If no provider - * implements the specified algorithm. + * @throws NoSuchAlgorithmException If no provider implements the specified + * algorithm. + * @throws IllegalArgumentException if <code>algorithm</code> is + * <code>null</code> or is an empty string. */ public static final SecretKeyFactory getInstance(String algorithm) - throws NoSuchAlgorithmException + throws NoSuchAlgorithmException { - Provider[] provs = Security.getProviders(); - for (int i = 0; i < provs.length; i++) - { - try - { - return getInstance(algorithm, provs[i]); - } - catch (NoSuchAlgorithmException nsae) - { - } - } - throw new NoSuchAlgorithmException(algorithm); + Provider[] p = Security.getProviders(); + NoSuchAlgorithmException lastException = null; + for (int i = 0; i < p.length; i++) + try + { + return getInstance(algorithm, p[i]); + } + catch (NoSuchAlgorithmException x) + { + lastException = x; + } + if (lastException != null) + throw lastException; + throw new NoSuchAlgorithmException(algorithm); } /** * Create a new secret key factory from the named provider. - * + * * @param algorithm The algorithm name. - * @param provider The provider name. + * @param provider The provider name. * @return The appropriate key factory, if found. - * @throws java.security.NoSuchAlgorithmException If the named - * provider does not implement the algorithm. - * @throws java.security.NoSuchProviderException If the named provider - * does not exist. + * @throws NoSuchAlgorithmException If the named provider does not implement + * the algorithm. + * @throws NoSuchProviderException If the named provider does not exist. + * @throws IllegalArgumentException if either <code>algorithm</code> or + * <code>provider</code> is <code>null</code>, or if + * <code>algorithm</code> is an empty string. */ public static final SecretKeyFactory getInstance(String algorithm, String provider) - throws NoSuchAlgorithmException, NoSuchProviderException + throws NoSuchAlgorithmException, NoSuchProviderException { + if (provider == null) + throw new IllegalArgumentException("provider MUST NOT be null"); Provider p = Security.getProvider(provider); if (p == null) - { - throw new NoSuchProviderException(provider); - } + throw new NoSuchProviderException(provider); return getInstance(algorithm, p); } /** * Create a new secret key factory from the specified provider. - * + * * @param algorithm The algorithm name. - * @param provider The provider. + * @param provider The provider. * @return The appropriate key factory, if found. - * @throws java.security.NoSuchAlgorithmException If the provider - * does not implement the algorithm. + * @throws NoSuchAlgorithmException If the provider does not implement the + * algorithm. + * @throws IllegalArgumentException if either <code>algorithm</code> or + * <code>provider</code> is <code>null</code>, or if + * <code>algorithm</code> is an empty string. */ public static final SecretKeyFactory getInstance(String algorithm, Provider provider) - throws NoSuchAlgorithmException + throws NoSuchAlgorithmException { + StringBuilder sb = new StringBuilder("SecretKeyFactory algorithm [") + .append(algorithm).append("] from provider[") + .append(provider).append("] could not be created"); + Throwable cause; try { - return new SecretKeyFactory((SecretKeyFactorySpi) - Engine.getInstance(SERVICE, algorithm, provider), - provider, algorithm); + Object spi = Engine.getInstance(SERVICE, algorithm, provider); + return new SecretKeyFactory((SecretKeyFactorySpi) spi, provider, algorithm); } - catch (InvocationTargetException ite) + catch (InvocationTargetException x) { - if (ite.getCause() == null) - throw new NoSuchAlgorithmException(algorithm); - if (ite.getCause() instanceof NoSuchAlgorithmException) - throw (NoSuchAlgorithmException) ite.getCause(); - throw new NoSuchAlgorithmException(algorithm); + cause = x.getCause(); + if (cause instanceof NoSuchAlgorithmException) + throw (NoSuchAlgorithmException) cause; + if (cause == null) + cause = x; } - catch (ClassCastException cce) + catch (ClassCastException x) { - throw new NoSuchAlgorithmException(algorithm); + cause = x; } + NoSuchAlgorithmException x = new NoSuchAlgorithmException(sb.toString()); + x.initCause(cause); + throw x; } - // Instance methods. - // ------------------------------------------------------------------------ - /** * Generate a secret key from a key specification, if possible. * |