01: package org.bouncycastle.asn1.cms;
02:
03: import org.bouncycastle.asn1.ASN1Encodable;
04: import org.bouncycastle.asn1.ASN1OctetString;
05: import org.bouncycastle.asn1.ASN1TaggedObject;
06: import org.bouncycastle.asn1.DEREncodable;
07: import org.bouncycastle.asn1.DERObject;
08: import org.bouncycastle.asn1.DERTaggedObject;
09:
10: public class RecipientIdentifier extends ASN1Encodable {
11: private DEREncodable id;
12:
13: public RecipientIdentifier(IssuerAndSerialNumber id) {
14: this .id = id;
15: }
16:
17: public RecipientIdentifier(ASN1OctetString id) {
18: this .id = new DERTaggedObject(false, 0, id);
19: }
20:
21: public RecipientIdentifier(DERObject id) {
22: this .id = id;
23: }
24:
25: /**
26: * return a RecipientIdentifier object from the given object.
27: *
28: * @param o the object we want converted.
29: * @exception IllegalArgumentException if the object cannot be converted.
30: */
31: public static RecipientIdentifier getInstance(Object o) {
32: if (o == null || o instanceof RecipientIdentifier) {
33: return (RecipientIdentifier) o;
34: }
35:
36: if (o instanceof IssuerAndSerialNumber) {
37: return new RecipientIdentifier((IssuerAndSerialNumber) o);
38: }
39:
40: if (o instanceof ASN1OctetString) {
41: return new RecipientIdentifier((ASN1OctetString) o);
42: }
43:
44: if (o instanceof DERObject) {
45: return new RecipientIdentifier((DERObject) o);
46: }
47:
48: throw new IllegalArgumentException(
49: "Illegal object in RecipientIdentifier: "
50: + o.getClass().getName());
51: }
52:
53: public boolean isTagged() {
54: return (id instanceof ASN1TaggedObject);
55: }
56:
57: public DEREncodable getId() {
58: if (id instanceof ASN1TaggedObject) {
59: return ASN1OctetString.getInstance((ASN1TaggedObject) id,
60: false);
61: }
62:
63: return IssuerAndSerialNumber.getInstance(id);
64: }
65:
66: /**
67: * Produce an object suitable for an ASN1OutputStream.
68: * <pre>
69: * RecipientIdentifier ::= CHOICE {
70: * issuerAndSerialNumber IssuerAndSerialNumber,
71: * subjectKeyIdentifier [0] SubjectKeyIdentifier
72: * }
73: *
74: * SubjectKeyIdentifier ::= OCTET STRING
75: * </pre>
76: */
77: public DERObject toASN1Object() {
78: return id.getDERObject();
79: }
80: }
|