01: package org.bouncycastle.asn1.esf;
02:
03: import org.bouncycastle.asn1.*;
04:
05: public class SignaturePolicyId extends ASN1Encodable {
06: private DERObjectIdentifier sigPolicyId;
07: private OtherHashAlgAndValue sigPolicyHash;
08: private SigPolicyQualifiers sigPolicyQualifiers;
09:
10: public static SignaturePolicyId getInstance(Object obj) {
11: if (obj == null || obj instanceof SignaturePolicyId) {
12: return (SignaturePolicyId) obj;
13: } else if (obj instanceof ASN1Sequence) {
14: return new SignaturePolicyId((ASN1Sequence) obj);
15: }
16:
17: throw new IllegalArgumentException(
18: "Unknown object in 'SignaturePolicyId' factory : "
19: + obj.getClass().getName() + ".");
20: }
21:
22: public SignaturePolicyId(ASN1Sequence seq) {
23: if (seq.size() != 2 && seq.size() != 3) {
24: throw new IllegalArgumentException("Bad sequence size: "
25: + seq.size());
26: }
27:
28: sigPolicyId = DERObjectIdentifier.getInstance(seq
29: .getObjectAt(0));
30: sigPolicyHash = OtherHashAlgAndValue.getInstance(seq
31: .getObjectAt(1));
32:
33: if (seq.size() == 3) {
34: sigPolicyQualifiers = SigPolicyQualifiers.getInstance(seq
35: .getObjectAt(2));
36: }
37: }
38:
39: public SignaturePolicyId(DERObjectIdentifier sigPolicyIdentifier,
40: OtherHashAlgAndValue sigPolicyHash) {
41: this (sigPolicyIdentifier, sigPolicyHash, null);
42: }
43:
44: public SignaturePolicyId(DERObjectIdentifier sigPolicyId,
45: OtherHashAlgAndValue sigPolicyHash,
46: SigPolicyQualifiers sigPolicyQualifiers) {
47: this .sigPolicyId = sigPolicyId;
48: this .sigPolicyHash = sigPolicyHash;
49: this .sigPolicyQualifiers = sigPolicyQualifiers;
50: }
51:
52: public DERObjectIdentifier getSigPolicyId() {
53: return sigPolicyId;
54: }
55:
56: public OtherHashAlgAndValue getSigPolicyHash() {
57: return sigPolicyHash;
58: }
59:
60: public SigPolicyQualifiers getSigPolicyQualifiers() {
61: return sigPolicyQualifiers;
62: }
63:
64: /**
65: * <pre>
66: * SignaturePolicyId ::= SEQUENCE {
67: * sigPolicyId SigPolicyId,
68: * sigPolicyHash SigPolicyHash,
69: * sigPolicyQualifiers SEQUENCE SIZE (1..MAX) OF SigPolicyQualifierInfo OPTIONAL}
70: * </pre>
71: */
72: public DERObject toASN1Object() {
73: ASN1EncodableVector v = new ASN1EncodableVector();
74:
75: v.add(sigPolicyId);
76: v.add(sigPolicyHash);
77: if (sigPolicyQualifiers != null) {
78: v.add(sigPolicyQualifiers);
79: }
80:
81: return new DERSequence(v);
82: }
83: }
|