01: package org.bouncycastle.x509;
02:
03: import org.bouncycastle.asn1.ASN1Encodable;
04: import org.bouncycastle.asn1.ASN1EncodableVector;
05: import org.bouncycastle.asn1.ASN1Set;
06: import org.bouncycastle.asn1.DERObject;
07: import org.bouncycastle.asn1.DERObjectIdentifier;
08: import org.bouncycastle.asn1.DERSet;
09: import org.bouncycastle.asn1.x509.Attribute;
10:
11: /**
12: * Class for carrying the values in an X.509 Attribute.
13: */
14: public class X509Attribute extends ASN1Encodable {
15: Attribute attr;
16:
17: /**
18: * @param at an object representing an attribute.
19: */
20: X509Attribute(ASN1Encodable at) {
21: this .attr = Attribute.getInstance(at);
22: }
23:
24: /**
25: * Create an X.509 Attribute with the type given by the passed in oid and
26: * the value represented by an ASN.1 Set containing value.
27: *
28: * @param oid type of the attribute
29: * @param value value object to go into the atribute's value set.
30: */
31: public X509Attribute(String oid, ASN1Encodable value) {
32: this .attr = new Attribute(new DERObjectIdentifier(oid),
33: new DERSet(value));
34: }
35:
36: /**
37: * Create an X.59 Attribute with the type given by the passed in oid and the
38: * value represented by an ASN.1 Set containing the objects in value.
39: *
40: * @param oid type of the attribute
41: * @param value vector of values to go in the attribute's value set.
42: */
43: public X509Attribute(String oid, ASN1EncodableVector value) {
44: this .attr = new Attribute(new DERObjectIdentifier(oid),
45: new DERSet(value));
46: }
47:
48: public String getOID() {
49: return attr.getAttrType().getId();
50: }
51:
52: public ASN1Encodable[] getValues() {
53: ASN1Set s = attr.getAttrValues();
54: ASN1Encodable[] values = new ASN1Encodable[s.size()];
55:
56: for (int i = 0; i != s.size(); i++) {
57: values[i] = (ASN1Encodable) s.getObjectAt(i);
58: }
59:
60: return values;
61: }
62:
63: public DERObject toASN1Object() {
64: return attr.toASN1Object();
65: }
66: }
|