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.DEREncodable;
08: import org.bouncycastle.asn1.DERObject;
09: import org.bouncycastle.asn1.DERObjectIdentifier;
10: import org.bouncycastle.asn1.DERSequence;
11:
12: public class OtherRecipientInfo extends ASN1Encodable {
13: private DERObjectIdentifier oriType;
14: private DEREncodable oriValue;
15:
16: public OtherRecipientInfo(DERObjectIdentifier oriType,
17: DEREncodable oriValue) {
18: this .oriType = oriType;
19: this .oriValue = oriValue;
20: }
21:
22: public OtherRecipientInfo(ASN1Sequence seq) {
23: oriType = DERObjectIdentifier.getInstance(seq.getObjectAt(0));
24: oriValue = seq.getObjectAt(1);
25: }
26:
27: /**
28: * return a OtherRecipientInfo 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 OtherRecipientInfo getInstance(ASN1TaggedObject obj,
37: boolean explicit) {
38: return getInstance(ASN1Sequence.getInstance(obj, explicit));
39: }
40:
41: /**
42: * return a OtherRecipientInfo 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 OtherRecipientInfo getInstance(Object obj) {
48: if (obj == null || obj instanceof OtherRecipientInfo) {
49: return (OtherRecipientInfo) obj;
50: }
51:
52: if (obj instanceof ASN1Sequence) {
53: return new OtherRecipientInfo((ASN1Sequence) obj);
54: }
55:
56: throw new IllegalArgumentException(
57: "Invalid OtherRecipientInfo: "
58: + obj.getClass().getName());
59: }
60:
61: public DERObjectIdentifier getType() {
62: return oriType;
63: }
64:
65: public DEREncodable getValue() {
66: return oriValue;
67: }
68:
69: /**
70: * Produce an object suitable for an ASN1OutputStream.
71: * <pre>
72: * OtherRecipientInfo ::= SEQUENCE {
73: * oriType OBJECT IDENTIFIER,
74: * oriValue ANY DEFINED BY oriType }
75: * </pre>
76: */
77: public DERObject toASN1Object() {
78: ASN1EncodableVector v = new ASN1EncodableVector();
79:
80: v.add(oriType);
81: v.add(oriValue);
82:
83: return new DERSequence(v);
84: }
85: }
|