01: package org.bouncycastle.asn1.x509;
02:
03: import org.bouncycastle.asn1.ASN1EncodableVector;
04: import org.bouncycastle.asn1.ASN1Sequence;
05: import org.bouncycastle.asn1.ASN1Encodable;
06: import org.bouncycastle.asn1.DERObject;
07: import org.bouncycastle.asn1.DERObjectIdentifier;
08: import org.bouncycastle.asn1.DERSequence;
09:
10: public class PolicyInformation extends ASN1Encodable {
11: private DERObjectIdentifier policyIdentifier;
12: private ASN1Sequence policyQualifiers;
13:
14: public PolicyInformation(ASN1Sequence seq) {
15: if (seq.size() < 1 || seq.size() > 2) {
16: throw new IllegalArgumentException("Bad sequence size: "
17: + seq.size());
18: }
19:
20: policyIdentifier = DERObjectIdentifier.getInstance(seq
21: .getObjectAt(0));
22:
23: if (seq.size() > 1) {
24: policyQualifiers = ASN1Sequence.getInstance(seq
25: .getObjectAt(1));
26: }
27: }
28:
29: public PolicyInformation(DERObjectIdentifier policyIdentifier) {
30: this .policyIdentifier = policyIdentifier;
31: }
32:
33: public PolicyInformation(DERObjectIdentifier policyIdentifier,
34: ASN1Sequence policyQualifiers) {
35: this .policyIdentifier = policyIdentifier;
36: this .policyQualifiers = policyQualifiers;
37: }
38:
39: public static PolicyInformation getInstance(Object obj) {
40: if (obj == null || obj instanceof PolicyInformation) {
41: return (PolicyInformation) obj;
42: }
43:
44: return new PolicyInformation(ASN1Sequence.getInstance(obj));
45: }
46:
47: public DERObjectIdentifier getPolicyIdentifier() {
48: return policyIdentifier;
49: }
50:
51: public ASN1Sequence getPolicyQualifiers() {
52: return policyQualifiers;
53: }
54:
55: /*
56: * PolicyInformation ::= SEQUENCE {
57: * policyIdentifier CertPolicyId,
58: * policyQualifiers SEQUENCE SIZE (1..MAX) OF
59: * PolicyQualifierInfo OPTIONAL }
60: */
61: public DERObject toASN1Object() {
62: ASN1EncodableVector v = new ASN1EncodableVector();
63:
64: v.add(policyIdentifier);
65:
66: if (policyQualifiers != null) {
67: v.add(policyQualifiers);
68: }
69:
70: return new DERSequence(v);
71: }
72: }
|