01: package org.bouncycastle.asn1.ocsp;
02:
03: import org.bouncycastle.asn1.ASN1EncodableVector;
04: import org.bouncycastle.asn1.ASN1Sequence;
05: import org.bouncycastle.asn1.ASN1TaggedObject;
06: import org.bouncycastle.asn1.ASN1Encodable;
07: import org.bouncycastle.asn1.DERBitString;
08: import org.bouncycastle.asn1.DERObject;
09: import org.bouncycastle.asn1.DERSequence;
10: import org.bouncycastle.asn1.DERTaggedObject;
11: import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
12:
13: public class Signature extends ASN1Encodable {
14: AlgorithmIdentifier signatureAlgorithm;
15: DERBitString signature;
16: ASN1Sequence certs;
17:
18: public Signature(AlgorithmIdentifier signatureAlgorithm,
19: DERBitString signature) {
20: this .signatureAlgorithm = signatureAlgorithm;
21: this .signature = signature;
22: }
23:
24: public Signature(AlgorithmIdentifier signatureAlgorithm,
25: DERBitString signature, ASN1Sequence certs) {
26: this .signatureAlgorithm = signatureAlgorithm;
27: this .signature = signature;
28: this .certs = certs;
29: }
30:
31: public Signature(ASN1Sequence seq) {
32: signatureAlgorithm = AlgorithmIdentifier.getInstance(seq
33: .getObjectAt(0));
34: signature = (DERBitString) seq.getObjectAt(1);
35:
36: if (seq.size() == 3) {
37: certs = ASN1Sequence.getInstance((ASN1TaggedObject) seq
38: .getObjectAt(2), true);
39: }
40: }
41:
42: public static Signature getInstance(ASN1TaggedObject obj,
43: boolean explicit) {
44: return getInstance(ASN1Sequence.getInstance(obj, explicit));
45: }
46:
47: public static Signature getInstance(Object obj) {
48: if (obj == null || obj instanceof Signature) {
49: return (Signature) obj;
50: } else if (obj instanceof ASN1Sequence) {
51: return new Signature((ASN1Sequence) obj);
52: }
53:
54: throw new IllegalArgumentException("unknown object in factory");
55: }
56:
57: public AlgorithmIdentifier getSignatureAlgorithm() {
58: return signatureAlgorithm;
59: }
60:
61: public DERBitString getSignature() {
62: return signature;
63: }
64:
65: public ASN1Sequence getCerts() {
66: return certs;
67: }
68:
69: /**
70: * Produce an object suitable for an ASN1OutputStream.
71: * <pre>
72: * Signature ::= SEQUENCE {
73: * signatureAlgorithm AlgorithmIdentifier,
74: * signature BIT STRING,
75: * certs [0] EXPLICIT SEQUENCE OF Certificate OPTIONAL}
76: * </pre>
77: */
78: public DERObject toASN1Object() {
79: ASN1EncodableVector v = new ASN1EncodableVector();
80:
81: v.add(signatureAlgorithm);
82: v.add(signature);
83:
84: if (certs != null) {
85: v.add(new DERTaggedObject(true, 0, certs));
86: }
87:
88: return new DERSequence(v);
89: }
90: }
|