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.ASN1Sequence; 26 import org.apache.geronimo.util.asn1.ASN1TaggedObject; 27 import org.apache.geronimo.util.asn1.DERObject; 28 import org.apache.geronimo.util.asn1.DERObjectIdentifier; 29 import org.apache.geronimo.util.asn1.DERSequence; 30 31 public class CertificatePolicies 32 extends ASN1Encodable 33 { 34 static final DERObjectIdentifier anyPolicy = new DERObjectIdentifier("2.5.29.32.0"); 35 36 Vector policies = new Vector (); 37 38 41 public static CertificatePolicies getInstance( 42 ASN1TaggedObject obj, 43 boolean explicit) 44 { 45 return getInstance(ASN1Sequence.getInstance(obj, explicit)); 46 } 47 48 51 public static CertificatePolicies getInstance( 52 Object obj) 53 { 54 if (obj instanceof CertificatePolicies) 55 { 56 return (CertificatePolicies)obj; 57 } 58 else if (obj instanceof ASN1Sequence) 59 { 60 return new CertificatePolicies((ASN1Sequence)obj); 61 } 62 63 throw new IllegalArgumentException ("unknown object in factory"); 64 } 65 66 69 public CertificatePolicies( 70 ASN1Sequence seq) 71 { 72 Enumeration e = seq.getObjects(); 73 while (e.hasMoreElements()) 74 { 75 ASN1Sequence s = (ASN1Sequence)e.nextElement(); 76 policies.addElement(s.getObjectAt(0)); 77 } 78 } 80 81 85 public CertificatePolicies( 86 DERObjectIdentifier p) 87 { 88 policies.addElement(p); 89 } 90 91 96 public CertificatePolicies( 97 String p) 98 { 99 this(new DERObjectIdentifier(p)); 100 } 101 102 public void addPolicy( 103 String p) 104 { 105 policies.addElement(new DERObjectIdentifier(p)); 106 } 107 108 public String getPolicy(int nr) 109 { 110 if (policies.size() > nr) 111 return ((DERObjectIdentifier)policies.elementAt(nr)).getId(); 112 113 return null; 114 } 115 116 136 public DERObject toASN1Object() 137 { 138 ASN1EncodableVector v = new ASN1EncodableVector(); 139 140 for (int i=0;i<policies.size();i++) 142 { 143 v.add(new DERSequence((DERObjectIdentifier)policies.elementAt(i))); 144 } 145 146 return new DERSequence(v); 147 } 148 149 public String toString() 150 { 151 String p = null; 152 for (int i=0;i<policies.size();i++) 153 { 154 if (p != null) 155 p += ", "; 156 p += ((DERObjectIdentifier)policies.elementAt(i)).getId(); 157 } 158 return "CertificatePolicies: "+p; 159 } 160 } 161 | Popular Tags |