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