1package org.bouncycastle.asn1.cms; 2 3import org.bouncycastle.asn1.ASN1Encodable; 4import org.bouncycastle.asn1.ASN1OctetString; 5import org.bouncycastle.asn1.ASN1TaggedObject; 6import org.bouncycastle.asn1.DEREncodable; 7import org.bouncycastle.asn1.DERObject; 8import org.bouncycastle.asn1.DERTaggedObject; 9 10public class SignerIdentifier 11 extends ASN1Encodable 12{ 13 private DEREncodable id; 14 15 public SignerIdentifier( 16 IssuerAndSerialNumber id) 17 { 18 this.id = id; 19 } 20 21 public SignerIdentifier( 22 ASN1OctetString id) 23 { 24 this.id = new DERTaggedObject(false, 0, id); 25 } 26 27 public SignerIdentifier( 28 DERObject id) 29 { 30 this.id = id; 31 } 32 33 /** 34 * return a SignerIdentifier object from the given object. 35 * 36 * @param o the object we want converted. 37 * @exception IllegalArgumentException if the object cannot be converted. 38 */ 39 public static SignerIdentifier getInstance( 40 Object o) 41 { 42 if (o == null || o instanceof SignerIdentifier) 43 { 44 return (SignerIdentifier)o; 45 } 46 47 if (o instanceof IssuerAndSerialNumber) 48 { 49 return new SignerIdentifier((IssuerAndSerialNumber)o); 50 } 51 52 if (o instanceof ASN1OctetString) 53 { 54 return new SignerIdentifier((ASN1OctetString)o); 55 } 56 57 if (o instanceof DERObject) 58 { 59 return new SignerIdentifier((DERObject)o); 60 } 61 62 throw new IllegalArgumentException( 63 "Illegal object in SignerIdentifier: " + o.getClass().getName()); 64 } 65 66 public boolean isTagged() 67 { 68 return (id instanceof ASN1TaggedObject); 69 } 70 71 public DEREncodable getId() 72 { 73 if (id instanceof ASN1TaggedObject) 74 { 75 return ASN1OctetString.getInstance((ASN1TaggedObject)id, false); 76 } 77 78 return id; 79 } 80 81 /** 82 * Produce an object suitable for an ASN1OutputStream. 83 * <pre> 84 * SignerIdentifier ::= CHOICE { 85 * issuerAndSerialNumber IssuerAndSerialNumber, 86 * subjectKeyIdentifier [0] SubjectKeyIdentifier 87 * } 88 * 89 * SubjectKeyIdentifier ::= OCTET STRING 90 * </pre> 91 */ 92 public DERObject toASN1Object() 93 { 94 return id.getDERObject(); 95 } 96} 97