1 /*
2 * Copyright �, Aegeus Technology Limited.
3 * All rights reserved.
4 */
5 package jsdsi.util;
6
7
8 import jsdsi.JsdsiRuntimeException;
9
10
11 /***
12 * <p>Experimental class and as such may be removed without warning.</p>
13 * Enum class for Signature Algorythms.
14 *
15 * @author Sean Radford
16 * @version $Revision: 1.2 $ $Date: 2004/11/08 12:08:08 $
17 */
18 public class SignatureAlgoEnum extends AlgorithmEnum {
19
20 private DigestAlgoEnum digest;
21
22 private KeyEnum key;
23
24 /***
25 * @param jdkName
26 * @param spkiName
27 */
28 protected SignatureAlgoEnum(DigestAlgoEnum digest, KeyEnum key) {
29 super(Algorithms.jdkSignatureName(digest,
30 key),
31 Algorithms.spkiSignatureName(digest, key));
32 this.digest = digest;
33 this.key = key;
34 }
35
36 /***
37 * Return the DigestAlgoEnum for this SignatureAlgoEnum
38 * @return the DigestAlgoEnum
39 */
40 public DigestAlgoEnum getDigestEnum() {
41 return this.digest;
42 }
43
44 /***
45 * Return the KeyEnum for this SignatureAlgoEnum
46 * @return the KeyEnum
47 */
48 public KeyEnum getKeyEnum() {
49 return this.key;
50 }
51
52 /***
53 * Create a SignatureAlgoEnum
54 * @param digest the DigestAlgoEnum
55 * @param key the KeyEnum
56 * @return the SignatureAlgoEnum
57 */
58 public static SignatureAlgoEnum create(DigestAlgoEnum digest, KeyEnum key) {
59 return new SignatureAlgoEnum(digest, key);
60 }
61
62 /***
63 * Given a JDK name for a Signature algorythm, return its SignatureAlgoEnum
64 * @param jdkName JDK name
65 * @return the SignatureAlgoEnum
66 * @throws JsdsiRuntimeException on error
67 */
68 public static SignatureAlgoEnum fromJdk(String jdkName) {
69 String[] bits = jdkName.split("with");
70 if (bits.length!=2) {
71 throw new JsdsiRuntimeException("Illegal JDK SignatureAlgo: "+jdkName);
72 }
73 DigestAlgoEnum digest = DigestAlgoEnum.fromJdkSignature( bits[0] );
74 KeyEnum key = KeyEnum.fromJdk( bits[1] );
75 return new SignatureAlgoEnum(digest, key);
76 }
77
78 /***
79 * Given a SPKI name for a Signature algorythm, return its SignatureAlgoEnum
80 * @param spkiName SPKI name
81 * @return the SignatureAlgoEnum
82 * @throws JsdsiRuntimeException on error
83 */
84 public static SignatureAlgoEnum fromSpki(String spkiName) {
85 int pos = spkiName.lastIndexOf("-");
86 if (pos==-1) {
87 throw new JsdsiRuntimeException("Illegal SPKI SignatureAlgo: "+spkiName);
88 }
89 String s = spkiName.substring(pos+1);
90 DigestAlgoEnum digest = DigestAlgoEnum.fromSpki( s );
91 s = spkiName.substring(0, pos);
92 KeyEnum key = KeyEnum.fromSpki( s );
93 return new SignatureAlgoEnum(digest, key);
94 }
95
96 }
This page was automatically generated by Maven