1 20 package com.novosec.pkix.asn1.crmf; 21 22 import org.bouncycastle.asn1.ASN1EncodableVector; 23 import org.bouncycastle.asn1.ASN1Sequence; 24 import org.bouncycastle.asn1.ASN1TaggedObject; 25 import org.bouncycastle.asn1.DEREncodable; 26 import org.bouncycastle.asn1.DERObject; 27 import org.bouncycastle.asn1.DERSequence; 28 import org.bouncycastle.asn1.DERTaggedObject; 29 import org.bouncycastle.asn1.x509.GeneralName; 30 import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo; 31 32 46 public class POPOSigningKeyInput implements DEREncodable 47 { 48 GeneralName sender; 49 PKMACValue publicKeyMAC; 50 SubjectPublicKeyInfo publicKey; 51 52 public static POPOSigningKeyInput getInstance( ASN1TaggedObject obj, boolean explicit ) 53 { 54 return getInstance(ASN1Sequence.getInstance(obj, explicit)); 55 } 56 57 public static POPOSigningKeyInput getInstance( Object obj ) 58 { 59 if (obj instanceof POPOSigningKeyInput) 60 { 61 return (POPOSigningKeyInput)obj; 62 } 63 else if (obj instanceof ASN1Sequence) 64 { 65 return new POPOSigningKeyInput((ASN1Sequence)obj); 66 } 67 68 throw new IllegalArgumentException ("unknown object in factory"); 69 } 70 71 public POPOSigningKeyInput( ASN1Sequence seq ) 72 { 73 Object obj = seq.getObjectAt(0); 74 75 if( obj instanceof ASN1TaggedObject ) 76 { 77 ASN1TaggedObject tagObj = (ASN1TaggedObject)obj; 78 if( tagObj.getTagNo() == 0 ) 79 this.sender = GeneralName.getInstance( (ASN1TaggedObject)tagObj.getObject(), true ); else 81 throw new IllegalArgumentException ("unknown tag: " + tagObj.getTagNo()); 82 } 83 else 84 publicKeyMAC = PKMACValue.getInstance( obj ); 85 86 this.publicKey = SubjectPublicKeyInfo.getInstance( seq.getObjectAt(1) ); 87 } 88 89 public POPOSigningKeyInput( GeneralName sender, SubjectPublicKeyInfo publicKey ) 90 { 91 this.sender = sender; 92 this.publicKey = publicKey; 93 } 94 public POPOSigningKeyInput( PKMACValue publicKeyMAC, SubjectPublicKeyInfo publicKey ) 95 { 96 this.publicKeyMAC = publicKeyMAC; 97 this.publicKey = publicKey; 98 } 99 100 public GeneralName getSender() 101 { 102 return sender; 103 } 104 105 public PKMACValue getPublicKeyMAC() 106 { 107 return publicKeyMAC; 108 } 109 110 public SubjectPublicKeyInfo getPublicKey() 111 { 112 return publicKey; 113 } 114 115 public DERObject getDERObject() 116 { 117 ASN1EncodableVector v = new ASN1EncodableVector(); 118 119 if( sender != null ) 120 v.add( new DERTaggedObject( false, 0, sender ) ); 121 else 122 v.add( publicKeyMAC ); 123 124 v.add( publicKey ); 125 126 return new DERSequence(v); 127 } 128 129 public String toString() 130 { 131 String s = "POPOSigningKeyInput: ("; 132 133 if( this.getSender() != null ) 134 s += "sender: " + this.getSender() + ", "; 135 else 136 s += "publicKeyMAC: " + this.getPublicKeyMAC() + ", "; 137 138 s += "publicKey: " + this.getPublicKey() + ")"; 139 140 return s; 141 } 142 } 143 | Popular Tags |