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.DEREncodable;
07: import org.bouncycastle.asn1.DERObject;
08: import org.bouncycastle.asn1.DERObjectIdentifier;
09: import org.bouncycastle.asn1.DERSequence;
10:
11: public class OtherKeyAttribute extends ASN1Encodable {
12: private DERObjectIdentifier keyAttrId;
13: private DEREncodable keyAttr;
14:
15: /**
16: * return an OtherKeyAttribute object from the given object.
17: *
18: * @param o the object we want converted.
19: * @exception IllegalArgumentException if the object cannot be converted.
20: */
21: public static OtherKeyAttribute getInstance(Object o) {
22: if (o == null || o instanceof OtherKeyAttribute) {
23: return (OtherKeyAttribute) o;
24: }
25:
26: if (o instanceof ASN1Sequence) {
27: return new OtherKeyAttribute((ASN1Sequence) o);
28: }
29:
30: throw new IllegalArgumentException("unknown object in factory");
31: }
32:
33: public OtherKeyAttribute(ASN1Sequence seq) {
34: keyAttrId = (DERObjectIdentifier) seq.getObjectAt(0);
35: keyAttr = seq.getObjectAt(1);
36: }
37:
38: public OtherKeyAttribute(DERObjectIdentifier keyAttrId,
39: DEREncodable keyAttr) {
40: this .keyAttrId = keyAttrId;
41: this .keyAttr = keyAttr;
42: }
43:
44: public DERObjectIdentifier getKeyAttrId() {
45: return keyAttrId;
46: }
47:
48: public DEREncodable getKeyAttr() {
49: return keyAttr;
50: }
51:
52: /**
53: * Produce an object suitable for an ASN1OutputStream.
54: * <pre>
55: * OtherKeyAttribute ::= SEQUENCE {
56: * keyAttrId OBJECT IDENTIFIER,
57: * keyAttr ANY DEFINED BY keyAttrId OPTIONAL
58: * }
59: * </pre>
60: */
61: public DERObject toASN1Object() {
62: ASN1EncodableVector v = new ASN1EncodableVector();
63:
64: v.add(keyAttrId);
65: v.add(keyAttr);
66:
67: return new DERSequence(v);
68: }
69: }
|