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

Diff of /classpath/java/security/Signature.java

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

revision 1.10 by tromey, Wed Mar 12 17:33:06 2003 UTC revision 1.11 by cbj, Thu Mar 27 03:32:08 2003 UTC
# Line 1  Line 1 
1  /* Signature.java --- Signature Class  /* Signature.java --- Signature Class
2     Copyright (C) 1999, 2002, 2003, Free Software Foundation, Inc.     Copyright (C) 1999, 2002, 2003 Free Software Foundation, Inc.
3    
4  This file is part of GNU Classpath.  This file is part of GNU Classpath.
5    
# Line 107  import java.security.spec.AlgorithmParam Line 107  import java.security.spec.AlgorithmParam
107   */   */
108  public abstract class Signature extends SignatureSpi  public abstract class Signature extends SignatureSpi
109  {  {
110      /** Service name for signatures. */
111      private static final String SIGNATURE = "Signature";
112    
113    /**    /**
114     * Possible <code>state</code> value, signifying that this signature object     * Possible <code>state</code> value, signifying that this signature object
115     * has not yet been initialized.     * has not yet been initialized.
116     */     */
117    protected static final int UNINITIALIZED = 0;    protected static final int UNINITIALIZED = 0;
118    
119      // Constructor.
120      // ------------------------------------------------------------------------
121    
122    /**    /**
123     * Possible <code>state</code> value, signifying that this signature object     * Possible <code>state</code> value, signifying that this signature object
124     * has been initialized for signing.     * has been initialized for signing.
# Line 196  public abstract class Signature extends Line 202  public abstract class Signature extends
202    public static Signature getInstance(String algorithm, String provider)    public static Signature getInstance(String algorithm, String provider)
203      throws NoSuchAlgorithmException, NoSuchProviderException      throws NoSuchAlgorithmException, NoSuchProviderException
204    {    {
205        if (provider == null || provider.length() == 0)
206          throw new IllegalArgumentException("Illegal provider");
207        
208      Provider p = Security.getProvider(provider);      Provider p = Security.getProvider(provider);
209      if (p == null)      if (p == null)
210        throw new NoSuchProviderException(provider);        throw new NoSuchProviderException(provider);
# Line 225  public abstract class Signature extends Line 234  public abstract class Signature extends
234      throws NoSuchAlgorithmException      throws NoSuchAlgorithmException
235    {    {
236      if (provider == null)      if (provider == null)
237        throw new IllegalArgumentException();        throw new IllegalArgumentException("Illegal provider");
   
     // try the name as is  
     String className = provider.getProperty("Signature." + algorithm);  
     if (className == null) // try all uppercase  
       {  
         String upper = algorithm.toUpperCase();  
         className = provider.getProperty("Signature." + upper);  
         if (className == null) // try if it's an alias  
           {  
             String alias = provider.getProperty("Alg.Alias.Signature." + algorithm);  
             if (alias == null)  
               {  
                 alias = provider.getProperty("Alg.Alias.Signature." + upper);  
                 if (alias == null) // spit the dummy  
                   throw new NoSuchAlgorithmException(algorithm);  
               }  
             className = provider.getProperty("Signature." + alias);  
             if (className == null)  
               throw new NoSuchAlgorithmException(algorithm);  
           }  
       }  
     return getInstance(className, algorithm, provider);  
   }  
238    
239    private static Signature getInstance(String classname, String algorithm,      Signature result = null;
240                                         Provider provider)      Object o = Engine.getInstance(SIGNATURE, algorithm, provider);
     throws NoSuchAlgorithmException  
   {  
     try  
       {  
         Object o = Class.forName(classname).newInstance();  
         Signature sig;  
         if (o instanceof SignatureSpi)  
           sig = new DummySignature((SignatureSpi) o, algorithm);  
         else  
           {  
             sig = (Signature) o;  
             sig.algorithm = algorithm;  
           }  
241    
242          sig.provider = provider;      if (o instanceof SignatureSpi)
         return sig;  
       }  
     catch (ClassNotFoundException cnfe)  
243        {        {
244          throw new NoSuchAlgorithmException("Class not found");          result = new DummySignature((SignatureSpi) o, algorithm);
245        }        }
246      catch (InstantiationException ie)      else if (o instanceof Signature)
247        {        {
248          throw new NoSuchAlgorithmException("Class instantiation failed");          result = (Signature) o;
249            result.algorithm = algorithm;
250        }        }
251      catch (IllegalAccessException iae)      else
252        {        {
253          throw new NoSuchAlgorithmException("Illegal Access");          throw new NoSuchAlgorithmException(algorithm);
254        }        }
255        result.provider = provider;
256        return result;
257    }    }
258    
259    /**    /**

Legend:
Removed from v.1.10  
changed lines
  Added in v.1.11

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