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