1 20 package com.novosec.pkix.asn1.crmf; 21 22 import org.bouncycastle.asn1.ASN1TaggedObject; 23 import org.bouncycastle.asn1.DERBoolean; 24 import org.bouncycastle.asn1.DEREncodable; 25 import org.bouncycastle.asn1.DERObject; 26 import org.bouncycastle.asn1.DEROctetString; 27 import org.bouncycastle.asn1.DERTaggedObject; 28 29 41 public class PKIArchiveOptions implements DEREncodable 42 { 43 DEREncodable obj; 44 int tag; 45 46 public PKIArchiveOptions( DEREncodable obj, int tag ) 47 { 48 this.obj = obj; 49 this.tag = tag; 50 } 51 52 public EncryptedKey getEncryptedKey() 53 { 54 if( this.tag != 0 ) 55 return null; 56 return (EncryptedKey)this.obj; 57 } 58 59 public DEROctetString getKeyGenParameters() 60 { 61 if( this.tag != 1 ) 62 return null; 63 return (DEROctetString)this.obj; 64 } 65 66 public DERBoolean getArchiveRemGenPrivKey() 67 { 68 if( this.tag != 2 ) 69 return null; 70 return (DERBoolean)this.obj; 71 } 72 73 public static PKIArchiveOptions getInstance( DERObject obj ) 74 { 75 return getInstance( (ASN1TaggedObject)obj, true ); 76 } 77 78 public static PKIArchiveOptions getInstance( ASN1TaggedObject tagObj, boolean explicit ) 79 { 80 int tag = tagObj.getTagNo(); 81 82 switch (tag) 83 { 84 case 0: return new PKIArchiveOptions(EncryptedKey.getInstance(tagObj.getObject()), 0); 85 case 1: return new PKIArchiveOptions(DEROctetString.getInstance(tagObj.getObject()), 1); 86 case 2: return new PKIArchiveOptions(DERBoolean.getInstance(tagObj.getObject()), 2); 87 } 88 89 throw new IllegalArgumentException ("unknown tag: " + tag); 90 } 91 92 public DERObject getDERObject() 93 { 94 return new DERTaggedObject(true, tag, obj); 95 } 96 97 public String toString() 98 { 99 return "PKIArchiveOptions: (" + obj + ")"; 100 } 101 } 102 | Popular Tags |