01: package org.bouncycastle.asn1.x509;
02:
03: import org.bouncycastle.asn1.ASN1Encodable;
04: import org.bouncycastle.asn1.ASN1EncodableVector;
05: import org.bouncycastle.asn1.ASN1Sequence;
06: import org.bouncycastle.asn1.DEREncodable;
07: import org.bouncycastle.asn1.DERObject;
08: import org.bouncycastle.asn1.DERIA5String;
09: import org.bouncycastle.asn1.DERObjectIdentifier;
10: import org.bouncycastle.asn1.DERSequence;
11:
12: /**
13: * Policy qualifiers, used in the X509V3 CertificatePolicies
14: * extension.
15: *
16: * <pre>
17: * PolicyQualifierInfo ::= SEQUENCE {
18: * policyQualifierId PolicyQualifierId,
19: * qualifier ANY DEFINED BY policyQualifierId }
20: * </pre>
21: */
22: public class PolicyQualifierInfo extends ASN1Encodable {
23: private DERObjectIdentifier policyQualifierId;
24: private DEREncodable qualifier;
25:
26: /**
27: * Creates a new <code>PolicyQualifierInfo</code> instance.
28: *
29: * @param policyQualifierId a <code>PolicyQualifierId</code> value
30: * @param qualifier the qualifier, defined by the above field.
31: */
32: public PolicyQualifierInfo(DERObjectIdentifier policyQualifierId,
33: DEREncodable qualifier) {
34: this .policyQualifierId = policyQualifierId;
35: this .qualifier = qualifier;
36: }
37:
38: /**
39: * Creates a new <code>PolicyQualifierInfo</code> containing a
40: * cPSuri qualifier.
41: *
42: * @param cps the CPS (certification practice statement) uri as a
43: * <code>String</code>.
44: */
45: public PolicyQualifierInfo(String cps) {
46: policyQualifierId = PolicyQualifierId.id_qt_cps;
47: qualifier = new DERIA5String(cps);
48: }
49:
50: /**
51: * Creates a new <code>PolicyQualifierInfo</code> instance.
52: *
53: * @param as <code>PolicyQualifierInfo</code> X509 structure
54: * encoded as an ASN1Sequence.
55: */
56: public PolicyQualifierInfo(ASN1Sequence as) {
57: if (as.size() != 2) {
58: throw new IllegalArgumentException("Bad sequence size: "
59: + as.size());
60: }
61:
62: policyQualifierId = DERObjectIdentifier.getInstance(as
63: .getObjectAt(0));
64: qualifier = as.getObjectAt(1);
65: }
66:
67: public static PolicyQualifierInfo getInstance(Object as) {
68: if (as instanceof PolicyQualifierInfo) {
69: return (PolicyQualifierInfo) as;
70: } else if (as instanceof ASN1Sequence) {
71: return new PolicyQualifierInfo((ASN1Sequence) as);
72: }
73:
74: throw new IllegalArgumentException(
75: "unknown object in getInstance.");
76: }
77:
78: public DERObjectIdentifier getPolicyQualifierId() {
79: return policyQualifierId;
80: }
81:
82: public DEREncodable getQualifier() {
83: return qualifier;
84: }
85:
86: /**
87: * Returns a DER-encodable representation of this instance.
88: *
89: * @return a <code>DERObject</code> value
90: */
91: public DERObject toASN1Object() {
92: ASN1EncodableVector dev = new ASN1EncodableVector();
93: dev.add(policyQualifierId);
94: dev.add(qualifier);
95:
96: return new DERSequence(dev);
97: }
98: }
|