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