1 20 package com.novosec.pkix.asn1.cmp; 21 22 import java.util.Enumeration ; 23 import java.util.Vector ; 24 25 import org.bouncycastle.asn1.ASN1EncodableVector; 26 import org.bouncycastle.asn1.ASN1Sequence; 27 import org.bouncycastle.asn1.ASN1TaggedObject; 28 import org.bouncycastle.asn1.DEREncodable; 29 import org.bouncycastle.asn1.DERObject; 30 import org.bouncycastle.asn1.DERSequence; 31 import org.bouncycastle.asn1.DERUTF8String; 32 33 41 public class PKIFreeText implements DEREncodable 42 { 43 Vector freeTextStrings = new Vector (); 44 45 public static PKIFreeText getInstance( ASN1TaggedObject obj, boolean explicit ) 46 { 47 return getInstance(ASN1Sequence.getInstance(obj, explicit)); 48 } 49 50 public static PKIFreeText getInstance( Object obj ) 51 { 52 if (obj instanceof PKIFreeText) 53 { 54 return (PKIFreeText)obj; 55 } 56 else if (obj instanceof ASN1Sequence) 57 { 58 return new PKIFreeText((ASN1Sequence)obj); 59 } 60 61 throw new IllegalArgumentException ("unknown object in factory"); 62 } 63 64 public PKIFreeText( ASN1Sequence seq ) 65 { 66 Enumeration e = seq.getObjects(); 67 while (e.hasMoreElements()) 68 freeTextStrings.addElement(e.nextElement()); 69 } 70 71 public PKIFreeText( DERUTF8String p ) 72 { 73 freeTextStrings.addElement(p); 74 } 75 76 public void addString( DERUTF8String p ) 77 { 78 freeTextStrings.addElement(p); 79 } 80 81 public DERUTF8String getString(int nr) 82 { 83 if (freeTextStrings.size() > nr) 84 return (DERUTF8String)freeTextStrings.elementAt(nr); 85 86 return null; 87 } 88 89 public DERObject getDERObject() 90 { 91 ASN1EncodableVector v = new ASN1EncodableVector(); 92 93 for (int i=0;i<freeTextStrings.size();i++) 94 v.add((DERUTF8String)freeTextStrings.elementAt(i)); 95 96 return new DERSequence(v); 97 } 98 99 public String toString() 100 { 101 String s = "PKIFreeText: "; 102 103 for (int i=0;i<freeTextStrings.size();i++) 104 s += (DERUTF8String)freeTextStrings.elementAt(i); 105 106 return s; 107 } 108 } 109 | Popular Tags |