1package org.bouncycastle.asn1.x500; 2 3import org.bouncycastle.asn1.ASN1Encodable; 4import org.bouncycastle.asn1.ASN1EncodableVector; 5import org.bouncycastle.asn1.ASN1Object; 6import org.bouncycastle.asn1.ASN1ObjectIdentifier; 7import org.bouncycastle.asn1.ASN1Primitive; 8import org.bouncycastle.asn1.ASN1Sequence; 9import org.bouncycastle.asn1.DERSequence; 10 11public class AttributeTypeAndValue 12 extends ASN1Object 13{ 14 private ASN1ObjectIdentifier type; 15 private ASN1Encodable value; 16 17 private AttributeTypeAndValue(ASN1Sequence seq) 18 { 19 type = (ASN1ObjectIdentifier)seq.getObjectAt(0); 20 value = (ASN1Encodable)seq.getObjectAt(1); 21 } 22 23 public static AttributeTypeAndValue getInstance(Object o) 24 { 25 if (o instanceof AttributeTypeAndValue) 26 { 27 return (AttributeTypeAndValue)o; 28 } 29 else if (o != null) 30 { 31 return new AttributeTypeAndValue(ASN1Sequence.getInstance(o)); 32 } 33 34 throw new IllegalArgumentException("null value in getInstance()"); 35 } 36 37 public AttributeTypeAndValue( 38 ASN1ObjectIdentifier type, 39 ASN1Encodable value) 40 { 41 this.type = type; 42 this.value = value; 43 } 44 45 public ASN1ObjectIdentifier getType() 46 { 47 return type; 48 } 49 50 public ASN1Encodable getValue() 51 { 52 return value; 53 } 54 55 /** 56 * <pre> 57 * AttributeTypeAndValue ::= SEQUENCE { 58 * type OBJECT IDENTIFIER, 59 * value ANY DEFINED BY type } 60 * </pre> 61 * @return a basic ASN.1 object representation. 62 */ 63 public ASN1Primitive toASN1Primitive() 64 { 65 ASN1EncodableVector v = new ASN1EncodableVector(); 66 67 v.add(type); 68 v.add(value); 69 70 return new DERSequence(v); 71 } 72} 73