1 17 18 package org.apache.geronimo.util.asn1.x509; 19 20 import java.util.Enumeration ; 21 import java.util.Vector ; 22 23 import org.apache.geronimo.util.asn1.ASN1Encodable; 24 import org.apache.geronimo.util.asn1.ASN1EncodableVector; 25 import org.apache.geronimo.util.asn1.ASN1OctetString; 26 import org.apache.geronimo.util.asn1.ASN1Sequence; 27 import org.apache.geronimo.util.asn1.ASN1TaggedObject; 28 import org.apache.geronimo.util.asn1.DERObject; 29 import org.apache.geronimo.util.asn1.DERObjectIdentifier; 30 import org.apache.geronimo.util.asn1.DEROctetString; 31 import org.apache.geronimo.util.asn1.DERSequence; 32 import org.apache.geronimo.util.asn1.DERTaggedObject; 33 import org.apache.geronimo.util.asn1.DERUTF8String; 34 35 38 public class IetfAttrSyntax 39 extends ASN1Encodable 40 { 41 public static final int VALUE_OCTETS = 1; 42 public static final int VALUE_OID = 2; 43 public static final int VALUE_UTF8 = 3; 44 GeneralNames policyAuthority = null; 45 Vector values = new Vector (); 46 int valueChoice = -1; 47 48 51 public IetfAttrSyntax(ASN1Sequence seq) 52 { 53 int i = 0; 54 55 if (seq.getObjectAt(0) instanceof ASN1TaggedObject) 56 { 57 policyAuthority = GeneralNames.getInstance(((ASN1TaggedObject)seq.getObjectAt(0)), false); 58 i++; 59 } 60 else if (seq.size() == 2) 61 { policyAuthority = GeneralNames.getInstance(seq.getObjectAt(0)); 63 i++; 64 } 65 66 if (!(seq.getObjectAt(i) instanceof ASN1Sequence)) 67 { 68 throw new IllegalArgumentException ("Non-IetfAttrSyntax encoding"); 69 } 70 71 seq = (ASN1Sequence)seq.getObjectAt(i); 72 73 for (Enumeration e = seq.getObjects(); e.hasMoreElements();) 74 { 75 DERObject obj = (DERObject)e.nextElement(); 76 int type; 77 78 if (obj instanceof DERObjectIdentifier) 79 { 80 type = VALUE_OID; 81 } 82 else if (obj instanceof DERUTF8String) 83 { 84 type = VALUE_UTF8; 85 } 86 else if (obj instanceof DEROctetString) 87 { 88 type = VALUE_OCTETS; 89 } 90 else 91 { 92 throw new IllegalArgumentException ("Bad value type encoding IetfAttrSyntax"); 93 } 94 95 if (valueChoice < 0) 96 { 97 valueChoice = type; 98 } 99 100 if (type != valueChoice) 101 { 102 throw new IllegalArgumentException ("Mix of value types in IetfAttrSyntax"); 103 } 104 105 values.addElement(obj); 106 } 107 } 108 109 public GeneralNames getPolicyAuthority() 110 { 111 return policyAuthority; 112 } 113 114 public int getValueType() 115 { 116 return valueChoice; 117 } 118 119 public Object [] getValues() 120 { 121 if (this.getValueType() == VALUE_OCTETS) 122 { 123 ASN1OctetString[] tmp = new ASN1OctetString[values.size()]; 124 125 for (int i = 0; i != tmp.length; i++) 126 { 127 tmp[i] = (ASN1OctetString)values.elementAt(i); 128 } 129 130 return tmp; 131 } 132 else if (this.getValueType() == VALUE_OID) 133 { 134 DERObjectIdentifier[] tmp = new DERObjectIdentifier[values.size()]; 135 136 for (int i = 0; i != tmp.length; i++) 137 { 138 tmp[i] = (DERObjectIdentifier)values.elementAt(i); 139 } 140 141 return tmp; 142 } 143 else 144 { 145 DERUTF8String[] tmp = new DERUTF8String[values.size()]; 146 147 for (int i = 0; i != tmp.length; i++) 148 { 149 tmp[i] = (DERUTF8String)values.elementAt(i); 150 } 151 152 return tmp; 153 } 154 } 155 156 171 public DERObject toASN1Object() 172 { 173 ASN1EncodableVector v = new ASN1EncodableVector(); 174 175 if (policyAuthority != null) 176 { 177 v.add(new DERTaggedObject(0, policyAuthority)); 178 } 179 180 ASN1EncodableVector v2 = new ASN1EncodableVector(); 181 182 for (Enumeration i = values.elements(); i.hasMoreElements();) 183 { 184 v2.add((ASN1Encodable)i.nextElement()); 185 } 186 187 v.add(new DERSequence(v2)); 188 189 return new DERSequence(v); 190 } 191 } 192 | Popular Tags |