This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
java.security.KeyFactory
- From: "Raif S. Naffah" <raif at fl dot net dot au>
- To: GCC libjava patches <java-patches at gcc dot gnu dot org>
- Date: Mon, 3 Mar 2003 05:20:52 +1100
- Subject: java.security.KeyFactory
- Reply-to: raif at fl dot net dot au
hello there,
this patch addresses JDK 1.4 compatibility.
cheers;
rsn
in ChangeLog (in libjava), add:
2003-03-03 Raif S. Naffah <raif at fl dot net dot au>
* java.security.KeyFactory: formatting + documentation
(getInstance(String)): use new getInstance(String, Provider).
(getInstance(String, String)): ditto.
(getInstance(String, Provider)): new method.
cvs -z9 diff -u -wb -B KeyFactory.java (in directory /data/workspace/cvs/gcc/libjava/java/security/)
Index: KeyFactory.java
===================================================================
RCS file: /cvsroot/gcc/gcc/libjava/java/security/KeyFactory.java,v
retrieving revision 1.2
diff -u -w -b -B -r1.2 KeyFactory.java
--- KeyFactory.java 22 Jan 2002 22:40:30 -0000 1.2
+++ KeyFactory.java 2 Mar 2003 18:12:30 -0000
@@ -52,7 +52,7 @@
DSAPublicKeySpec or X509EncodedKeySpec. The key factory
translate these key specifications.
- @since JDK 1.2
+ @since 1.2
@author Mark Benvenuto
*/
public class KeyFactory
@@ -64,9 +64,9 @@
/**
Constructs a new keyFactory with the specified parameters.
- @param keyFacSpi Key Factory SPI to use
- @param provider the provider of the Key Factory SPI
- @param algorithm the name of the key algorithm for this key factory
+ @param keyFacSpi Key Factory SPI to use.
+ @param provider the provider of the Key Factory SPI.
+ @param algorithm the name of the key algorithm for this key factory.
*/
protected KeyFactory(KeyFactorySpi keyFacSpi, Provider provider,
String algorithm)
@@ -77,14 +77,14 @@
}
/**
- Gets an instance of the KeyFactory class representing
- the specified key factory. If the algorithm is not
- found then, it throws NoSuchAlgorithmException.
-
- @param algorithm the name of algorithm to choose
- @return a KeyFactory repesenting the desired algorithm
-
- @throws NoSuchAlgorithmException if the algorithm is not implemented by providers
+ Gets an instance of the KeyFactory class representing the specified key
+ factory. If the algorithm is not found then, it throws
+ NoSuchAlgorithmException.
+
+ @param algorithm the name of algorithm to choose.
+ @return a KeyFactory repesenting the desired algorithm.
+ @throws NoSuchAlgorithmException if the algorithm is not implemented by
+ providers
*/
public static KeyFactory getInstance(String algorithm)
throws NoSuchAlgorithmException
@@ -92,28 +92,27 @@
Provider[] p = Security.getProviders();
for (int i = 0; i < p.length; i++)
+ try
{
- String classname = p[i].getProperty("KeyFactory." + algorithm);
- if (classname != null)
- return getInstance(classname, algorithm, p[i]);
+ return getInstance(algorithm, p[i]);
}
+ catch (NoSuchAlgorithmException ignored) {}
throw new NoSuchAlgorithmException(algorithm);
}
/**
- Gets an instance of the KeyFactory class representing
- the specified key factory from the specified provider.
- If the algorithm is not found then, it throws
- NoSuchAlgorithmException. If the provider is not found, then
+ Gets an instance of the KeyFactory class representing the specified key
+ factory from the specified provider. If the algorithm is not found then,
+ it throws NoSuchAlgorithmException. If the provider is not found, then
it throws NoSuchProviderException.
- @param algorithm the name of algorithm to choose
- @param provider the name of the provider to find the algorithm in
- @return a KeyFactory repesenting the desired algorithm
-
- @throws NoSuchAlgorithmException if the algorithm is not implemented by the provider
- @throws NoSuchProviderException if the provider is not found
+ @param algorithm the name of algorithm to choose.
+ @param provider the name of the provider to find the algorithm in.
+ @return a KeyFactory repesenting the desired algorithm.
+ @throws NoSuchAlgorithmException if the algorithm is not implemented by
+ the provider.
+ @throws NoSuchProviderException if the provider is not found.
*/
public static KeyFactory getInstance(String algorithm, String provider)
throws NoSuchAlgorithmException, NoSuchProviderException
@@ -122,8 +121,53 @@
if (p == null)
throw new NoSuchProviderException();
- return getInstance(p.getProperty("KeyFactory." + algorithm),
- algorithm, p);
+ return getInstance(algorithm, p);
+ }
+
+ /**
+ * Generates a KeyFactory object for the specified algorithm from the
+ * specified provider. Note: the <code>provider</code> doesn't have to be
+ * registered.
+ *
+ * @param algorithm the name of the requested key algorithm. See Appendix A
+ * in the Java Cryptography Architecture API Specification & Reference for
+ * information about standard algorithm names.
+ * @param provider the provider.
+ * @return a KeyFactory object for the specified algorithm.
+ * @throws NoSuchAlgorithmException if the algorithm is not available from
+ * the specified provider.
+ * @throws IllegalArgumentException if the <code>provider</code> is null.
+ * @since 1.4
+ * @see { at link Provider}
+ */
+ public static KeyFactory getInstance(String algorithm, Provider provider)
+ throws NoSuchAlgorithmException
+ {
+ if (provider == null)
+ throw new IllegalArgumentException();
+
+ // try the name as is
+ String className = provider.getProperty("KeyFactory." + algorithm);
+ if (className == null) // try all uppercase
+ {
+ String upper = algorithm.toUpperCase();
+ className = provider.getProperty("KeyFactory." + upper);
+ if (className == null) // try if it's an alias
+ {
+ String alias =
+ provider.getProperty("Alg.Alias.KeyFactory." + algorithm);
+ if (alias == null) // try all-uppercase alias name
+ {
+ alias = provider.getProperty("Alg.Alias.KeyFactory." + upper);
+ if (alias == null) // spit the dummy
+ throw new NoSuchAlgorithmException(algorithm);
+ }
+ className = provider.getProperty("KeyFactory." + alias);
+ if (className == null)
+ throw new NoSuchAlgorithmException(algorithm);
+ }
+ }
+ return getInstance(className, algorithm, provider);
}
private static KeyFactory getInstance(String classname,
@@ -154,7 +198,7 @@
/**
Gets the provider that the class is from.
- @return the provider of this class
+ @return the provider of this class.
*/
public final Provider getProvider()
{
@@ -164,7 +208,7 @@
/**
Returns the name of the algorithm used
- @return A string with the name of the algorithm
+ @return A string with the name of the algorithm.
*/
public final String getAlgorithm()
{
@@ -174,12 +218,10 @@
/**
Generates a public key from the provided key specification.
- @param keySpec key specification
-
- @return the public key
-
+ @param keySpec key specification.
+ @return the public key.
@throws InvalidKeySpecException invalid key specification for
- this key factory to produce a public key
+ this key factory to produce a public key.
*/
public final PublicKey generatePublic(KeySpec keySpec) throws
InvalidKeySpecException
@@ -190,12 +232,10 @@
/**
Generates a private key from the provided key specification.
- @param keySpec key specification
-
- @return the private key
-
+ @param keySpec key specification.
+ @return the private key.
@throws InvalidKeySpecException invalid key specification for
- this key factory to produce a private key
+ this key factory to produce a private key.
*/
public final PrivateKey generatePrivate(KeySpec keySpec) throws
InvalidKeySpecException
@@ -204,20 +244,15 @@
}
/**
- Returns a key specification for the given key. keySpec
- identifies the specification class to return the key
- material in.
-
- @param key the key
- @param keySpec the specification class to return the
- key material in.
+ Returns a key specification for the given key. keySpec identifies the
+ specification class to return the key material in.
+ @param key the key.
+ @param keySpec the specification class to return the key material in.
@return the key specification in an instance of the requested
- specification class
-
+ specification class.
@throws InvalidKeySpecException the requested key specification
- is inappropriate for this key or the key is
- unrecognized.
+ is inappropriate for this key or the key is unrecognized.
*/
public final KeySpec getKeySpec(Key key, Class keySpec)
throws InvalidKeySpecException
@@ -226,15 +261,13 @@
}
/**
- Translates the key from an unknown or untrusted provider
- into a key for this key factory.
-
- @param the key from an unknown or untrusted provider
-
- @return the translated key
+ Translates the key from an unknown or untrusted provider into a key for
+ this key factory.
- @throws InvalidKeySpecException if the key cannot be
- processed by this key factory
+ @param key the key from an unknown or untrusted provider.
+ @return the translated key.
+ @throws InvalidKeyException if the key cannot be processed by this key
+ factory.
*/
public final Key translateKey(Key key) throws InvalidKeyException
{