1   /*
2    * Copyright �, Aegeus Technology Limited.
3    * All rights reserved.
4    */
5   package jsdsi.util;
6   
7   import java.util.HashMap;
8   import java.util.Map;
9   
10  import jsdsi.JsdsiRuntimeException;
11  
12  
13  /***
14   * <p>Experimental class and as such may be removed without warning.</p>
15   * Enum class for Key algorithms.
16   * 
17   * @author Sean Radford
18   * @version $Revision: 1.5 $ $Date: 2004/11/12 09:53:49 $
19   */
20  public class KeyEnum extends AlgorithmEnum {
21      
22      /***
23       * @param jdkName
24       * @param spkiName
25       */
26      protected KeyEnum(String jdkName, String spkiName) {
27          super(jdkName, spkiName);
28      }
29      
30      /***
31       * The Digital Signature Algorithm as defined in FIPS PUB 186.
32       */
33      public static final KeyEnum DSA = new KeyEnum("DSA", "dsa");
34      
35      /***
36       * The RSA encryption algorithm as defined in PKCS #1.
37       */
38      public static final KeyEnum RSA = new KeyEnum("RSA", "rsa-pkcs1");
39      
40      
41      private static final Map jdkMap = new HashMap();
42      
43      private static final Map spkiMap = new HashMap();
44      
45      static {
46          jdkMap.put("DSA", DSA);
47          jdkMap.put("RSA", RSA);
48          
49          spkiMap.put("dsa", DSA);
50          spkiMap.put("rsa-pkcs1", RSA);
51      }
52      
53      /***
54       * Given a JDK name for a Key algorythm, return its KeyEnum
55       * @param jdkName JDK name
56       * @return the KeyEnum
57       */
58      public static KeyEnum fromJdk(String jdkName) {
59          KeyEnum e = (KeyEnum) jdkMap.get(jdkName);
60          if (e==null) {
61              throw new JsdsiRuntimeException("KeyEnum not found for JDK name: "+jdkName);
62          }
63          return e;
64      }
65      
66      /***
67       * Given a SPKI name for a Key algorithm, return its KeyEnum
68       * @param spkiName SPKI name
69       * @return the KeyEnum
70       */
71      public static KeyEnum fromSpki(String spkiName) {
72          KeyEnum e = (KeyEnum) spkiMap.get(spkiName);
73          if (e==null) {
74              throw new JsdsiRuntimeException("KeyEnum not found for SPKI name: "+spkiName);
75          }
76          return e;
77      }
78      
79  }
This page was automatically generated by Maven