01: package org.bouncycastle.asn1.cms;
02:
03: import org.bouncycastle.asn1.ASN1Encodable;
04: import org.bouncycastle.asn1.ASN1EncodableVector;
05: import org.bouncycastle.asn1.ASN1Sequence;
06: import org.bouncycastle.asn1.ASN1TaggedObject;
07: import org.bouncycastle.asn1.DERBitString;
08: import org.bouncycastle.asn1.DERObject;
09: import org.bouncycastle.asn1.DERSequence;
10: import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
11:
12: public class OriginatorPublicKey extends ASN1Encodable {
13: private AlgorithmIdentifier algorithm;
14: private DERBitString publicKey;
15:
16: public OriginatorPublicKey(AlgorithmIdentifier algorithm,
17: byte[] publicKey) {
18: this .algorithm = algorithm;
19: this .publicKey = new DERBitString(publicKey);
20: }
21:
22: public OriginatorPublicKey(ASN1Sequence seq) {
23: algorithm = AlgorithmIdentifier.getInstance(seq.getObjectAt(0));
24: publicKey = (DERBitString) seq.getObjectAt(1);
25: }
26:
27: /**
28: * return an OriginatorPublicKey object from a tagged object.
29: *
30: * @param obj the tagged object holding the object we want.
31: * @param explicit true if the object is meant to be explicitly
32: * tagged false otherwise.
33: * @exception IllegalArgumentException if the object held by the
34: * tagged object cannot be converted.
35: */
36: public static OriginatorPublicKey getInstance(ASN1TaggedObject obj,
37: boolean explicit) {
38: return getInstance(ASN1Sequence.getInstance(obj, explicit));
39: }
40:
41: /**
42: * return an OriginatorPublicKey object from the given object.
43: *
44: * @param obj the object we want converted.
45: * @exception IllegalArgumentException if the object cannot be converted.
46: */
47: public static OriginatorPublicKey getInstance(Object obj) {
48: if (obj == null || obj instanceof OriginatorPublicKey) {
49: return (OriginatorPublicKey) obj;
50: }
51:
52: if (obj instanceof ASN1Sequence) {
53: return new OriginatorPublicKey((ASN1Sequence) obj);
54: }
55:
56: throw new IllegalArgumentException(
57: "Invalid OriginatorPublicKey: "
58: + obj.getClass().getName());
59: }
60:
61: public AlgorithmIdentifier getAlgorithm() {
62: return algorithm;
63: }
64:
65: public DERBitString getPublicKey() {
66: return publicKey;
67: }
68:
69: /**
70: * Produce an object suitable for an ASN1OutputStream.
71: * <pre>
72: * OriginatorPublicKey ::= SEQUENCE {
73: * algorithm AlgorithmIdentifier,
74: * publicKey BIT STRING
75: * }
76: * </pre>
77: */
78: public DERObject toASN1Object() {
79: ASN1EncodableVector v = new ASN1EncodableVector();
80:
81: v.add(algorithm);
82: v.add(publicKey);
83:
84: return new DERSequence(v);
85: }
86: }
|