/[classpath]/classpath/java/security/KeyPairGenerator.java
ViewVC logotype

Diff of /classpath/java/security/KeyPairGenerator.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.5 by mark, Tue Jan 22 22:27:00 2002 UTC revision 1.6 by mark, Sat Nov 16 23:28:25 2002 UTC
# Line 1  Line 1 
1  /* KeyPairGenerator.java --- Key Pair Generator Class  /* KeyPairGenerator.java --- Key Pair Generator Class
2     Copyright (C) 1999 Free Software Foundation, Inc.     Copyright (C) 1999, 2002 Free Software Foundation, Inc.
3    
4  This file is part of GNU Classpath.  This file is part of GNU Classpath.
5    
# Line 36  obligated to do so.  If you do not wish Line 36  obligated to do so.  If you do not wish
36  exception statement from your version. */  exception statement from your version. */
37    
38  package java.security;  package java.security;
39    
40  import java.security.spec.AlgorithmParameterSpec;  import java.security.spec.AlgorithmParameterSpec;
41    
42  /**  /**
# Line 51  import java.security.spec.AlgorithmParam Line 52  import java.security.spec.AlgorithmParam
52   */   */
53  public abstract class KeyPairGenerator extends KeyPairGeneratorSpi  public abstract class KeyPairGenerator extends KeyPairGeneratorSpi
54  {  {
55    private Provider provider;    Provider provider;
56    private String algorithm;    private String algorithm;
57    
58    /**    /**
# Line 83  public abstract class KeyPairGenerator e Line 84  public abstract class KeyPairGenerator e
84       @param algorithm the name of algorithm to choose       @param algorithm the name of algorithm to choose
85       @return a AlgorithmParameterGenerator repesenting the desired algorithm       @return a AlgorithmParameterGenerator repesenting the desired algorithm
86    
87       @throws NoSuchAlgorithmException if the algorithm is not implemented by providers       @throws NoSuchAlgorithmException if the algorithm is not implemented by
88                                          providers
89     */     */
90    public static KeyPairGenerator getInstance(String algorithm) throws    public static KeyPairGenerator getInstance(String algorithm) throws
91      NoSuchAlgorithmException      NoSuchAlgorithmException
92    {    {
93      Provider[] p = Security.getProviders();      Provider[] p = Security.getProviders();
94    
     String name = "KeyPairGenerator." + algorithm;  
95      for (int i = 0; i < p.length; i++)      for (int i = 0; i < p.length; i++)
96        {        {
97          String classname = p[i].getProperty(name);          try
98          if (classname != null)            {
99            return getInstance(classname, algorithm, p[i]);              return getInstance(algorithm, p[i]);
100              }
101            catch (NoSuchAlgorithmException ignored) {}
102        }        }
103    
104      throw new NoSuchAlgorithmException(algorithm);      throw new NoSuchAlgorithmException(algorithm);
# Line 110  public abstract class KeyPairGenerator e Line 113  public abstract class KeyPairGenerator e
113       @param provider the name of the provider to find the algorithm in       @param provider the name of the provider to find the algorithm in
114       @return a AlgorithmParameterGenerator repesenting the desired algorithm       @return a AlgorithmParameterGenerator repesenting the desired algorithm
115    
116       @throws NoSuchAlgorithmException if the algorithm is not implemented by the provider       @throws NoSuchAlgorithmException if the algorithm is not implemented by
117                                          the provider
118       @throws NoSuchProviderException if the provider is not found       @throws NoSuchProviderException if the provider is not found
119     */     */
120    public static KeyPairGenerator getInstance(String algorithm, String provider)    public static KeyPairGenerator getInstance(String algorithm, String provider)
# Line 118  public abstract class KeyPairGenerator e Line 122  public abstract class KeyPairGenerator e
122    {    {
123      Provider p = Security.getProvider(provider);      Provider p = Security.getProvider(provider);
124      if (p == null)      if (p == null)
125        throw new NoSuchProviderException();        throw new NoSuchProviderException(provider);
126    
127        return getInstance(algorithm, p);
128      }
129    
130      return getInstance(p.getProperty("KeyPairGenerator." + algorithm),    private static KeyPairGenerator getInstance(String algorithm, Provider p)
131                         algorithm, p);      throws NoSuchAlgorithmException
132      {
133        // try the name as is
134        String className = p.getProperty("KeyPairGenerator." + algorithm);
135        if (className == null) { // try all uppercase
136          String upper = algorithm.toUpperCase();
137          className = p.getProperty("KeyPairGenerator." + upper);
138          if (className == null) { // try if it's an alias
139            String alias = p.getProperty("Alg.Alias.KeyPairGenerator." + algorithm);
140            if (alias == null) { // try all-uppercase alias name
141              alias = p.getProperty("Alg.Alias.KeyPairGenerator." + upper);
142              if (alias == null) { // spit the dummy
143                throw new NoSuchAlgorithmException(algorithm);
144              }
145            }
146            className = p.getProperty("KeyPairGenerator." + alias);
147            if (className == null) {
148              throw new NoSuchAlgorithmException(algorithm);
149            }
150          }
151        }
152        return getInstance(className, algorithm, p);
153    }    }
154    
155    private static KeyPairGenerator getInstance(String classname,    private static KeyPairGenerator getInstance(String classname,
# Line 134  public abstract class KeyPairGenerator e Line 162  public abstract class KeyPairGenerator e
162          Object o = Class.forName(classname).newInstance();          Object o = Class.forName(classname).newInstance();
163          KeyPairGenerator kpg;          KeyPairGenerator kpg;
164          if (o instanceof KeyPairGeneratorSpi)          if (o instanceof KeyPairGeneratorSpi)
165            kpg =            kpg = new DummyKeyPairGenerator((KeyPairGeneratorSpi) o, algorithm);
             (KeyPairGenerator) (new  
                                 DummyKeyPairGenerator((KeyPairGeneratorSpi) o,  
                                                       algorithm));  
166          else          else
167            {            {
168              kpg = (KeyPairGenerator) o;              kpg = (KeyPairGenerator) o;

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.6

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26