1 17 18 package org.apache.geronimo.util.asn1.x509; 19 20 import java.util.Enumeration ; 21 import java.util.Hashtable ; 22 import java.util.Vector ; 23 24 import org.apache.geronimo.util.asn1.ASN1Encodable; 25 import org.apache.geronimo.util.asn1.ASN1EncodableVector; 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.DERSequence; 30 31 37 public class ExtendedKeyUsage 38 extends ASN1Encodable 39 { 40 Hashtable usageTable = new Hashtable (); 41 ASN1Sequence seq; 42 43 public static ExtendedKeyUsage getInstance( 44 ASN1TaggedObject obj, 45 boolean explicit) 46 { 47 return getInstance(ASN1Sequence.getInstance(obj, explicit)); 48 } 49 50 public static ExtendedKeyUsage getInstance( 51 Object obj) 52 { 53 if(obj == null || obj instanceof ExtendedKeyUsage) 54 { 55 return (ExtendedKeyUsage)obj; 56 } 57 58 if(obj instanceof ASN1Sequence) 59 { 60 return new ExtendedKeyUsage((ASN1Sequence)obj); 61 } 62 63 throw new IllegalArgumentException ("Invalid ExtendedKeyUsage: " + obj.getClass().getName()); 64 } 65 66 public ExtendedKeyUsage( 67 KeyPurposeId usage) 68 { 69 this.seq = new DERSequence(usage); 70 71 this.usageTable.put(usage, usage); 72 } 73 74 public ExtendedKeyUsage( 75 ASN1Sequence seq) 76 { 77 this.seq = seq; 78 79 Enumeration e = seq.getObjects(); 80 81 while (e.hasMoreElements()) 82 { 83 Object o = e.nextElement(); 84 85 this.usageTable.put(o, o); 86 } 87 } 88 89 public ExtendedKeyUsage( 90 Vector usages) 91 { 92 ASN1EncodableVector v = new ASN1EncodableVector(); 93 Enumeration e = usages.elements(); 94 95 while (e.hasMoreElements()) 96 { 97 DERObject o = (DERObject)e.nextElement(); 98 99 v.add(o); 100 this.usageTable.put(o, o); 101 } 102 103 this.seq = new DERSequence(v); 104 } 105 106 public boolean hasKeyPurposeId( 107 KeyPurposeId keyPurposeId) 108 { 109 return (usageTable.get(keyPurposeId) != null); 110 } 111 112 public int size() 113 { 114 return usageTable.size(); 115 } 116 117 public DERObject toASN1Object() 118 { 119 return seq; 120 } 121 } 122 | Popular Tags |