1b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallampackage org.bouncycastle.x509;
2b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
3b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallamimport org.bouncycastle.asn1.ASN1Encodable;
4b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallamimport org.bouncycastle.asn1.ASN1EncodableVector;
54c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstromimport org.bouncycastle.asn1.ASN1Object;
64c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstromimport org.bouncycastle.asn1.ASN1ObjectIdentifier;
74c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstromimport org.bouncycastle.asn1.ASN1Primitive;
8b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallamimport org.bouncycastle.asn1.ASN1Set;
9b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallamimport org.bouncycastle.asn1.DERSet;
10b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallamimport org.bouncycastle.asn1.x509.Attribute;
11b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
12b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam/**
13b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * Class for carrying the values in an X.509 Attribute.
14b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam */
15b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallampublic class X509Attribute
164c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom    extends ASN1Object
17b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam{
18b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    Attribute    attr;
19b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
20b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    /**
21b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam     * @param at an object representing an attribute.
22b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam     */
23b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    X509Attribute(
24b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        ASN1Encodable   at)
25b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    {
26b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        this.attr = Attribute.getInstance(at);
27b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    }
28b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
29b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    /**
30b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam     * Create an X.509 Attribute with the type given by the passed in oid and
31b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam     * the value represented by an ASN.1 Set containing value.
32b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam     *
33b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam     * @param oid type of the attribute
34b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam     * @param value value object to go into the atribute's value set.
35b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam     */
36b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    public X509Attribute(
37b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        String          oid,
38b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        ASN1Encodable   value)
39b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    {
404c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom        this.attr = new Attribute(new ASN1ObjectIdentifier(oid), new DERSet(value));
41b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    }
42b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
43b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    /**
44b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam     * Create an X.59 Attribute with the type given by the passed in oid and the
45b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam     * value represented by an ASN.1 Set containing the objects in value.
46b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam     *
47b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam     * @param oid type of the attribute
48b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam     * @param value vector of values to go in the attribute's value set.
49b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam     */
50b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    public X509Attribute(
51b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        String              oid,
52b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        ASN1EncodableVector value)
53b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    {
544c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom        this.attr = new Attribute(new ASN1ObjectIdentifier(oid), new DERSet(value));
55b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    }
56b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
57b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    public String getOID()
58b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    {
59b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        return attr.getAttrType().getId();
60b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    }
61b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
62b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    public ASN1Encodable[] getValues()
63b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    {
64b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        ASN1Set         s = attr.getAttrValues();
65b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        ASN1Encodable[] values = new ASN1Encodable[s.size()];
66b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
67b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        for (int i = 0; i != s.size(); i++)
68b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        {
69b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam            values[i] = (ASN1Encodable)s.getObjectAt(i);
70b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        }
71b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
72b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        return values;
73b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    }
74b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
754c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom    public ASN1Primitive toASN1Primitive()
76b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    {
774c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom        return attr.toASN1Primitive();
78b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    }
79b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam}
80