01: package org.bouncycastle.asn1.mozilla;
02:
03: import org.bouncycastle.asn1.ASN1Encodable;
04: import org.bouncycastle.asn1.DERObject;
05: import org.bouncycastle.asn1.DERIA5String;
06: import org.bouncycastle.asn1.ASN1Sequence;
07: import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo;
08:
09: /**
10: * This is designed to parse
11: * the PublicKeyAndChallenge created by the KEYGEN tag included by
12: * Mozilla based browsers.
13: * <pre>
14: * PublicKeyAndChallenge ::= SEQUENCE {
15: * spki SubjectPublicKeyInfo,
16: * challenge IA5STRING
17: * }
18: *
19: * </pre>
20: */
21: public class PublicKeyAndChallenge extends ASN1Encodable {
22: private ASN1Sequence pkacSeq;
23: private SubjectPublicKeyInfo spki;
24: private DERIA5String challenge;
25:
26: public static PublicKeyAndChallenge getInstance(Object obj) {
27: if (obj instanceof PublicKeyAndChallenge) {
28: return (PublicKeyAndChallenge) obj;
29: } else if (obj instanceof ASN1Sequence) {
30: return new PublicKeyAndChallenge((ASN1Sequence) obj);
31: }
32:
33: throw new IllegalArgumentException("unkown object in factory");
34: }
35:
36: public PublicKeyAndChallenge(ASN1Sequence seq) {
37: pkacSeq = seq;
38: spki = SubjectPublicKeyInfo.getInstance(seq.getObjectAt(0));
39: challenge = DERIA5String.getInstance(seq.getObjectAt(1));
40: }
41:
42: public DERObject toASN1Object() {
43: return pkacSeq;
44: }
45:
46: public SubjectPublicKeyInfo getSubjectPublicKeyInfo() {
47: return spki;
48: }
49:
50: public DERIA5String getChallenge() {
51: return challenge;
52: }
53: }
|