This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
java.security.AlgorithmParameters
- 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 04:56:57 +1100
- Subject: java.security.AlgorithmParameters
- 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.AlgorithmParameters: formatting + dumentation
(getInstance(String)): use new getInstance(String, Provider).
(getInstance(String, String)): ditto.
(getInstance(String, Provider)): new method.
cvs -z9 diff -u -wb -B AlgorithmParameters.java (in directory /data/workspace/cvs/gcc/libjava/java/security/)
Index: AlgorithmParameters.java
===================================================================
RCS file: /cvsroot/gcc/gcc/libjava/java/security/AlgorithmParameters.java,v
retrieving revision 1.2
diff -u -w -b -B -r1.2 AlgorithmParameters.java
--- AlgorithmParameters.java 22 Jan 2002 22:40:30 -0000 1.2
+++ AlgorithmParameters.java 2 Mar 2003 17:45:31 -0000
@@ -46,7 +46,7 @@
provides an interface through which to modify parameters for
classes. This class is used to manage the algorithm parameters.
- @since JDK 1.2
+ @since 1.2
@author Mark Benvenuto
*/
public class AlgorithmParameters
@@ -58,9 +58,9 @@
/**
Creates an instance of AlgorithmParameters
- @param paramSpi A parameters engine to use
- @param provider A provider to use
- @param algorithm The algorithm
+ @param paramSpi A parameters engine to use.
+ @param provider A provider to use.
+ @param algorithm The algorithm.
*/
protected AlgorithmParameters(AlgorithmParametersSpi paramSpi,
Provider provider, String algorithm)
@@ -88,23 +88,21 @@
The returned AlgorithmParameters must still be intialized with
init().
- @param algorithm the name of algorithm to choose
- @return a AlgorithmParameters repesenting the desired algorithm
-
- @throws NoSuchAlgorithmException if the algorithm is not implemented by providers
+ @param algorithm the name of algorithm to choose.
+ @return a AlgorithmParameters repesenting the desired algorithm.
+ @throws NoSuchAlgorithmException if the algorithm is not implemented by
+ providers.
*/
- public static AlgorithmParameters getInstance(String algorithm) throws
- NoSuchAlgorithmException
+ public static AlgorithmParameters getInstance(String algorithm)
+ throws NoSuchAlgorithmException
{
Provider[] p = Security.getProviders();
-
for (int i = 0; i < p.length; i++)
+ try
{
- String classname =
- p[i].getProperty("AlgorithmParameters." + algorithm);
- if (classname != null)
- return getInstance(classname, algorithm, p[i]);
+ return getInstance(algorithm, p[i]);
}
+ catch (NoSuchAlgorithmException ignored) {}
throw new NoSuchAlgorithmException(algorithm);
}
@@ -122,20 +120,64 @@
@param algorithm the name of algorithm to choose
@param provider the name of the provider to find the algorithm in
@return a AlgorithmParameters repesenting the desired algorithm
-
- @throws NoSuchAlgorithmException if the algorithm is not implemented by the provider
+ @throws NoSuchAlgorithmException if the algorithm is not implemented by
+ the provider
@throws NoSuchProviderException if the provider is not found
*/
public static AlgorithmParameters getInstance(String algorithm,
- String provider) throws
- NoSuchAlgorithmException, NoSuchProviderException
+ String provider)
+ throws NoSuchAlgorithmException, NoSuchProviderException
{
Provider p = Security.getProvider(provider);
if (p == null)
throw new NoSuchProviderException();
- return getInstance(p.getProperty("AlgorithmParameters." + 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 <code>provider</code> is null.
+ * @since 1.4
+ */
+ public static AlgorithmParameters getInstance(String algorithm,
+ Provider provider)
+ throws NoSuchAlgorithmException
+ {
+ if (provider == null)
+ throw new IllegalArgumentException();
+
+ // try the name as is
+ String className = provider.getProperty("AlgorithmParameters." + algorithm);
+ if (className == null) // try all uppercase
+ {
+ String upper = algorithm.toUpperCase();
+ className = provider.getProperty("AlgorithmParameters." + upper);
+ if (className == null) // try if it's an alias
+ {
+ String alias =
+ provider.getProperty("Alg.Alias.AlgorithmParameters." + algorithm);
+ if (alias == null) // try all-uppercase alias name
+ {
+ alias = provider.getProperty("Alg.Alias.AlgorithmParameters." + upper);
+ if (alias == null) // spit the dummy
+ throw new NoSuchAlgorithmException(algorithm);
+ }
+ className = provider.getProperty("AlgorithmParameters." + alias);
+ if (className == null)
+ throw new NoSuchAlgorithmException(algorithm);
+ }
+ }
+ return getInstance(className, algorithm, provider);
}
private static AlgorithmParameters getInstance(String classname,
@@ -167,7 +209,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()
{
@@ -178,9 +220,9 @@
Initializes the engine with the specified
AlgorithmParameterSpec class.
- @param paramSpec A AlgorithmParameterSpec to initialize with
-
- @throws InvalidParameterSpecException For an inapporiate ParameterSpec class
+ @param paramSpec A AlgorithmParameterSpec to initialize with.
+ @throws InvalidParameterSpecException For an inapporiate ParameterSpec
+ class.
*/
public final void init(AlgorithmParameterSpec paramSpec) throws
InvalidParameterSpecException
@@ -195,9 +237,8 @@
specification exists then it succeeds or else it throws
IOException.
- @param params Parameters to initialize with
-
- @throws IOException Decoding Error
+ @param params Parameters to initialize with.
+ @throws IOException Decoding Error.
*/
public final void init(byte[]params) throws IOException
{
@@ -212,10 +253,9 @@
specification if it exists or else it throws
IOException.
- @param params Parameters to initialize with
- @param format Name of decoding format to use
-
- @throws IOException Decoding Error
+ @param params Parameters to initialize with.
+ @param format Name of decoding format to use.
+ @throws IOException Decoding Error.
*/
public final void init(byte[]params, String format) throws IOException
{
@@ -227,11 +267,10 @@
paramSpec identifies the class to return the AlgortihmParameters
in.
- @param paramSpec Class to return AlgorithmParameters in
-
- @return the parameter specification
-
- @throws InvalidParameterSpecException if the paramSpec is an invalid parameter class
+ @param paramSpec Class to return AlgorithmParameters in.
+ @return the parameter specification.
+ @throws InvalidParameterSpecException if the paramSpec is an invalid
+ parameter class.
*/
public final AlgorithmParameterSpec getParameterSpec(Class paramSpec) throws
InvalidParameterSpecException
@@ -244,7 +283,7 @@
The primary encoding format is ASN.1 format if it exists
for the specified type.
- @return byte array representing the parameters
+ @return byte array representing the parameters.
*/
public final byte[] getEncoded() throws IOException
{
@@ -257,7 +296,7 @@
primary encoding format is used, the ASN.1 format,
if it exists for the specified type.
- @return byte array representing the parameters
+ @return byte array representing the parameters.
*/
public final byte[] getEncoded(String format) throws IOException
{
@@ -267,7 +306,7 @@
/**
Returns a string representation of the encoding format
- @return a string containing the string representation
+ @return a string containing the string representation.
*/
public final String toString()
{