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.DERBitString;
07: import org.bouncycastle.asn1.DERObject;
08: import org.bouncycastle.asn1.DERSequence;
09:
10: public class AttributeCertificate extends ASN1Encodable {
11: AttributeCertificateInfo acinfo;
12: AlgorithmIdentifier signatureAlgorithm;
13: DERBitString signatureValue;
14:
15: /**
16: * @param obj
17: * @return an AttributeCertificate object
18: */
19: public static AttributeCertificate getInstance(Object obj) {
20: if (obj instanceof AttributeCertificate) {
21: return (AttributeCertificate) obj;
22: } else if (obj instanceof ASN1Sequence) {
23: return new AttributeCertificate((ASN1Sequence) obj);
24: }
25:
26: throw new IllegalArgumentException("unknown object in factory");
27: }
28:
29: public AttributeCertificate(AttributeCertificateInfo acinfo,
30: AlgorithmIdentifier signatureAlgorithm,
31: DERBitString signatureValue) {
32: this .acinfo = acinfo;
33: this .signatureAlgorithm = signatureAlgorithm;
34: this .signatureValue = signatureValue;
35: }
36:
37: public AttributeCertificate(ASN1Sequence seq) {
38: if (seq.size() != 3) {
39: throw new IllegalArgumentException("Bad sequence size: "
40: + seq.size());
41: }
42:
43: this .acinfo = AttributeCertificateInfo.getInstance(seq
44: .getObjectAt(0));
45: this .signatureAlgorithm = AlgorithmIdentifier.getInstance(seq
46: .getObjectAt(1));
47: this .signatureValue = DERBitString.getInstance(seq
48: .getObjectAt(2));
49: }
50:
51: public AttributeCertificateInfo getAcinfo() {
52: return acinfo;
53: }
54:
55: public AlgorithmIdentifier getSignatureAlgorithm() {
56: return signatureAlgorithm;
57: }
58:
59: public DERBitString getSignatureValue() {
60: return signatureValue;
61: }
62:
63: /**
64: * Produce an object suitable for an ASN1OutputStream.
65: * <pre>
66: * AttributeCertificate ::= SEQUENCE {
67: * acinfo AttributeCertificateInfo,
68: * signatureAlgorithm AlgorithmIdentifier,
69: * signatureValue BIT STRING
70: * }
71: * </pre>
72: */
73: public DERObject toASN1Object() {
74: ASN1EncodableVector v = new ASN1EncodableVector();
75:
76: v.add(acinfo);
77: v.add(signatureAlgorithm);
78: v.add(signatureValue);
79:
80: return new DERSequence(v);
81: }
82: }
|