summaryrefslogtreecommitdiff
path: root/java/security/KeyFactory.java
diff options
context:
space:
mode:
authorRaif S. Naffah <raif@swiftdsl.com.au>2006-08-13 00:09:58 +0000
committerRaif S. Naffah <raif@swiftdsl.com.au>2006-08-13 00:09:58 +0000
commit04f3e82ec5a636855d68f80630d61355cf0560fb (patch)
tree680f41705bc16d10c63b8aea4c993e826cd14613 /java/security/KeyFactory.java
parentff16c332b4e181ea6b1e1175f3b504fb4e8e992b (diff)
downloadclasspath-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 'java/security/KeyFactory.java')
-rw-r--r--java/security/KeyFactory.java99
1 files changed, 53 insertions, 46 deletions
diff --git a/java/security/KeyFactory.java b/java/security/KeyFactory.java
index edb2a87da..914975d77 100644
--- a/java/security/KeyFactory.java
+++ b/java/security/KeyFactory.java
@@ -40,6 +40,7 @@ package java.security;
import gnu.java.security.Engine;
+import java.lang.reflect.InvocationTargetException;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.KeySpec;
@@ -93,26 +94,29 @@ public class KeyFactory
* Returns a new instance of <code>KeyFactory</code> representing the
* specified key factory.
*
- * @param algorithm
- * the name of algorithm to use.
+ * @param algorithm the name of algorithm to use.
* @return a new instance repesenting the desired algorithm.
- * @throws NoSuchAlgorithmException
- * if the algorithm is not implemented by any provider.
+ * @throws NoSuchAlgorithmException if the algorithm is not implemented by any
+ * provider.
+ * @throws IllegalArgumentException if <code>algorithm</code> is
+ * <code>null</code> or is an empty string.
*/
public static KeyFactory getInstance(String algorithm)
- throws NoSuchAlgorithmException
+ throws NoSuchAlgorithmException
{
Provider[] p = Security.getProviders();
+ NoSuchAlgorithmException lastException = null;
for (int i = 0; i < p.length; i++)
try
{
return getInstance(algorithm, p[i]);
}
- catch (NoSuchAlgorithmException e)
- {
- // Ignore.
- }
-
+ catch (NoSuchAlgorithmException x)
+ {
+ lastException = x;
+ }
+ if (lastException != null)
+ throw lastException;
throw new NoSuchAlgorithmException(algorithm);
}
@@ -120,29 +124,26 @@ public class KeyFactory
* Returns a new instance of <code>KeyFactory</code> representing the
* specified key factory from the specified provider.
*
- * @param algorithm
- * the name of algorithm to use.
- * @param provider
- * the name of the provider to use.
+ * @param algorithm the name of algorithm to use.
+ * @param provider the name of the provider to use.
* @return a new instance repesenting the desired algorithm.
- * @throws IllegalArgumentException
- * if <code>provider</code> is <code>null</code> or is an empty
- * string.
- * @throws NoSuchAlgorithmException
- * if the algorithm is not implemented by the named provider.
- * @throws NoSuchProviderException
- * if the named provider was not found.
+ * @throws NoSuchAlgorithmException if the algorithm is not implemented by the
+ * named provider.
+ * @throws NoSuchProviderException if the named provider was not found.
+ * @throws IllegalArgumentException if either <code>algorithm</code> or
+ * <code>provider</code> is <code>null</code> or empty.
*/
public static KeyFactory getInstance(String algorithm, String provider)
- throws NoSuchAlgorithmException, NoSuchProviderException
+ throws NoSuchAlgorithmException, NoSuchProviderException
{
- if (provider == null || provider.length() == 0)
- throw new IllegalArgumentException("Illegal provider");
-
+ if (provider == null)
+ throw new IllegalArgumentException("provider MUST NOT be null");
+ provider = provider.trim();
+ if (provider.length() == 0)
+ throw new IllegalArgumentException("provider MUST NOT be empty");
Provider p = Security.getProvider(provider);
if (p == null)
throw new NoSuchProviderException(provider);
-
return getInstance(algorithm, p);
}
@@ -150,38 +151,44 @@ public class KeyFactory
* Returns a new instance of <code>KeyFactory</code> representing the
* specified key factory from the designated {@link Provider}.
*
- * @param algorithm
- * the name of algorithm to use.
- * @param provider
- * the {@link Provider} to use.
+ * @param algorithm the name of algorithm to use.
+ * @param provider the {@link Provider} to use.
* @return a new instance repesenting the desired algorithm.
- * @throws IllegalArgumentException
- * if <code>provider</code> is <code>null</code>.
- * @throws NoSuchAlgorithmException
- * if the algorithm is not implemented by {@link Provider}.
+ * @throws NoSuchAlgorithmException if the algorithm is not implemented by
+ * {@link Provider}.
+ * @throws IllegalArgumentException if either <code>algorithm</code> or
+ * <code>provider</code> is <code>null</code>, or if
+ * <code>algorithm</code> is an empty string.
* @since 1.4
* @see Provider
*/
public static KeyFactory getInstance(String algorithm, Provider provider)
- throws NoSuchAlgorithmException
+ throws NoSuchAlgorithmException
{
- if (provider == null)
- throw new IllegalArgumentException("Illegal provider");
-
+ StringBuilder sb = new StringBuilder("KeyFactory for algorithm [")
+ .append(algorithm).append("] from provider[")
+ .append(provider).append("] could not be created");
+ Throwable cause;
try
{
- return new KeyFactory((KeyFactorySpi)
- Engine.getInstance(KEY_FACTORY, algorithm, provider),
- provider, algorithm);
+ Object spi = Engine.getInstance(KEY_FACTORY, algorithm, provider);
+ return new KeyFactory((KeyFactorySpi) spi, provider, algorithm);
}
- catch (java.lang.reflect.InvocationTargetException ite)
+ catch (InvocationTargetException x)
{
- 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;
}
/**