01: package org.bouncycastle.asn1.pkcs;
02:
03: import org.bouncycastle.asn1.ASN1Encodable;
04: import org.bouncycastle.asn1.ASN1EncodableVector;
05: import org.bouncycastle.asn1.ASN1Sequence;
06: import org.bouncycastle.asn1.ASN1Set;
07: import org.bouncycastle.asn1.DERObject;
08: import org.bouncycastle.asn1.DERObjectIdentifier;
09: import org.bouncycastle.asn1.DERSequence;
10:
11: public class Attribute extends ASN1Encodable {
12: private DERObjectIdentifier attrType;
13: private ASN1Set attrValues;
14:
15: /**
16: * return an Attribute 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 Attribute getInstance(Object o) {
22: if (o == null || o instanceof Attribute) {
23: return (Attribute) o;
24: }
25:
26: if (o instanceof ASN1Sequence) {
27: return new Attribute((ASN1Sequence) o);
28: }
29:
30: throw new IllegalArgumentException("unknown object in factory");
31: }
32:
33: public Attribute(ASN1Sequence seq) {
34: attrType = (DERObjectIdentifier) seq.getObjectAt(0);
35: attrValues = (ASN1Set) seq.getObjectAt(1);
36: }
37:
38: public Attribute(DERObjectIdentifier attrType, ASN1Set attrValues) {
39: this .attrType = attrType;
40: this .attrValues = attrValues;
41: }
42:
43: public DERObjectIdentifier getAttrType() {
44: return attrType;
45: }
46:
47: public ASN1Set getAttrValues() {
48: return attrValues;
49: }
50:
51: /**
52: * Produce an object suitable for an ASN1OutputStream.
53: * <pre>
54: * Attribute ::= SEQUENCE {
55: * attrType OBJECT IDENTIFIER,
56: * attrValues SET OF AttributeValue
57: * }
58: * </pre>
59: */
60: public DERObject toASN1Object() {
61: ASN1EncodableVector v = new ASN1EncodableVector();
62:
63: v.add(attrType);
64: v.add(attrValues);
65:
66: return new DERSequence(v);
67: }
68: }
|