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