01: package org.bouncycastle.asn1.crmf;
02:
03: import org.bouncycastle.asn1.ASN1Encodable;
04: import org.bouncycastle.asn1.ASN1EncodableVector;
05: import org.bouncycastle.asn1.ASN1Sequence;
06: import org.bouncycastle.asn1.DERObject;
07: import org.bouncycastle.asn1.DERObjectIdentifier;
08: import org.bouncycastle.asn1.DERSequence;
09:
10: public class AttributeTypeAndValue extends ASN1Encodable {
11: private DERObjectIdentifier type;
12: private ASN1Encodable value;
13:
14: private AttributeTypeAndValue(ASN1Sequence seq) {
15: type = (DERObjectIdentifier) seq.getObjectAt(0);
16: value = (ASN1Encodable) seq.getObjectAt(1);
17: }
18:
19: public static AttributeTypeAndValue getInstance(Object o) {
20: if (o instanceof AttributeTypeAndValue) {
21: return (AttributeTypeAndValue) o;
22: }
23:
24: if (o instanceof ASN1Sequence) {
25: return new AttributeTypeAndValue((ASN1Sequence) o);
26: }
27:
28: throw new IllegalArgumentException("Invalid object: "
29: + o.getClass().getName());
30: }
31:
32: public DERObjectIdentifier getType() {
33: return type;
34: }
35:
36: public ASN1Encodable getValue() {
37: return value;
38: }
39:
40: /**
41: * <pre>
42: * AttributeTypeAndValue ::= SEQUENCE {
43: * type OBJECT IDENTIFIER,
44: * value ANY DEFINED BY type }
45: * </pre>
46: * @return a basic ASN.1 object representation.
47: */
48: public DERObject toASN1Object() {
49: ASN1EncodableVector v = new ASN1EncodableVector();
50:
51: v.add(type);
52: v.add(value);
53:
54: return new DERSequence(v);
55: }
56: }
|