1 |
/* AlgorithmParameters.java --- Algorithm Parameters Implementation Class |
/* AlgorithmParameters.java --- Algorithm Parameters Implementation Class |
2 |
Copyright (C) 1999, 2003, Free Software Foundation, Inc. |
Copyright (C) 1999, 2003 Free Software Foundation, Inc. |
3 |
|
|
4 |
This file is part of GNU Classpath. |
This file is part of GNU Classpath. |
5 |
|
|
81 |
*/ |
*/ |
82 |
public class AlgorithmParameters |
public class AlgorithmParameters |
83 |
{ |
{ |
84 |
|
/** Service name for algorithm parameters. */ |
85 |
|
private static final String ALGORITHM_PARAMETERS = "AlgorithmParameters"; |
86 |
|
|
87 |
private AlgorithmParametersSpi paramSpi; |
private AlgorithmParametersSpi paramSpi; |
88 |
private Provider provider; |
private Provider provider; |
89 |
private String algorithm; |
private String algorithm; |
166 |
public static AlgorithmParameters getInstance(String algorithm, String provider) |
public static AlgorithmParameters getInstance(String algorithm, String provider) |
167 |
throws NoSuchAlgorithmException, NoSuchProviderException |
throws NoSuchAlgorithmException, NoSuchProviderException |
168 |
{ |
{ |
169 |
|
if (provider == null || provider.length() == 0) |
170 |
|
throw new IllegalArgumentException("Illegal provider"); |
171 |
|
|
172 |
Provider p = Security.getProvider(provider); |
Provider p = Security.getProvider(provider); |
173 |
if (p == null) |
if (p == null) |
174 |
throw new NoSuchProviderException(); |
throw new NoSuchProviderException(); |
196 |
throws NoSuchAlgorithmException |
throws NoSuchAlgorithmException |
197 |
{ |
{ |
198 |
if (provider == null) |
if (provider == null) |
199 |
throw new IllegalArgumentException(); |
throw new IllegalArgumentException("Illegal provider"); |
|
|
|
|
// 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); |
|
|
} |
|
200 |
|
|
|
private static AlgorithmParameters getInstance(String classname, |
|
|
String algorithm, |
|
|
Provider provider) |
|
|
throws NoSuchAlgorithmException |
|
|
{ |
|
201 |
try |
try |
202 |
{ |
{ |
203 |
return new AlgorithmParameters( |
return new AlgorithmParameters((AlgorithmParametersSpi) |
204 |
(AlgorithmParametersSpi) Class.forName(classname).newInstance(), |
Engine.getInstance(ALGORITHM_PARAMETERS, algorithm, provider), |
205 |
provider, |
provider, algorithm); |
|
algorithm); |
|
|
} |
|
|
catch (ClassNotFoundException cnfe) |
|
|
{ |
|
|
throw new NoSuchAlgorithmException("Class not found"); |
|
|
} |
|
|
catch (InstantiationException ie) |
|
|
{ |
|
|
throw new NoSuchAlgorithmException("Class instantiation failed"); |
|
206 |
} |
} |
207 |
catch (IllegalAccessException iae) |
catch (ClassCastException cce) |
208 |
{ |
{ |
209 |
throw new NoSuchAlgorithmException("Illegal Access"); |
throw new NoSuchAlgorithmException(algorithm); |
210 |
} |
} |
211 |
} |
} |
212 |
|
|