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 32 40 public class GenRepContent implements DEREncodable 41 { 42 Vector infoTypesAndValues = new Vector (); 43 44 public static GenRepContent getInstance( ASN1TaggedObject obj, boolean explicit ) 45 { 46 return getInstance(ASN1Sequence.getInstance(obj, explicit)); 47 } 48 49 public static GenRepContent getInstance( Object obj ) 50 { 51 if (obj instanceof GenRepContent) 52 { 53 return (GenRepContent)obj; 54 } 55 else if (obj instanceof ASN1Sequence) 56 { 57 return new GenRepContent((ASN1Sequence)obj); 58 } 59 60 throw new IllegalArgumentException ("unknown object in factory"); 61 } 62 63 public GenRepContent( ASN1Sequence seq ) 64 { 65 Enumeration e = seq.getObjects(); 66 while (e.hasMoreElements()) 67 { 68 InfoTypeAndValue s = InfoTypeAndValue.getInstance(e.nextElement()); 69 infoTypesAndValues.addElement(s); 70 } 71 } 72 73 public GenRepContent( InfoTypeAndValue infoTypeAndValue ) 74 { 75 infoTypesAndValues.addElement( infoTypeAndValue ); 76 } 77 78 public void addInfoTypeAndValue( InfoTypeAndValue infoTypeAndValue ) 79 { 80 infoTypesAndValues.addElement( infoTypeAndValue ); 81 } 82 83 public InfoTypeAndValue getInfoTypeAndValue(int nr) 84 { 85 if (infoTypesAndValues.size() > nr) 86 return (InfoTypeAndValue)infoTypesAndValues.elementAt(nr); 87 88 return null; 89 } 90 91 public DERObject getDERObject() 92 { 93 ASN1EncodableVector v = new ASN1EncodableVector(); 94 95 for (int i=0;i<infoTypesAndValues.size();i++) 96 { 97 v.add((InfoTypeAndValue)infoTypesAndValues.elementAt(i)); 98 } 99 100 return new DERSequence(v); 101 } 102 103 public String toString() 104 { 105 String p = null; 106 for (int i=0;i<infoTypesAndValues.size();i++) 107 { 108 if( p == null ) 109 p = ((InfoTypeAndValue)infoTypesAndValues.elementAt(i)).toString(); 110 else 111 p += (InfoTypeAndValue)infoTypesAndValues.elementAt(i); 112 } 113 return "GenRepContent: "+p; 114 } 115 } 116 | Popular Tags |