1b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallampackage org.bouncycastle.asn1.x509; 2b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 3b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallamimport org.bouncycastle.asn1.ASN1Encodable; 4b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallamimport org.bouncycastle.asn1.ASN1EncodableVector; 5b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallamimport org.bouncycastle.asn1.ASN1Sequence; 6b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallamimport org.bouncycastle.asn1.ASN1TaggedObject; 7b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallamimport org.bouncycastle.asn1.DERBitString; 8b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallamimport org.bouncycastle.asn1.DERInteger; 9b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallamimport org.bouncycastle.asn1.DERObject; 10b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallamimport org.bouncycastle.asn1.DERSequence; 11b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 12b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallampublic class IssuerSerial 13b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam extends ASN1Encodable 14b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam{ 15b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam GeneralNames issuer; 16b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam DERInteger serial; 17b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam DERBitString issuerUID; 18b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 19b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam public static IssuerSerial getInstance( 20b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam Object obj) 21b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 22b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam if (obj == null || obj instanceof IssuerSerial) 23b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 24b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam return (IssuerSerial)obj; 25b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 26b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 27b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam if (obj instanceof ASN1Sequence) 28b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 29b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam return new IssuerSerial((ASN1Sequence)obj); 30b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 31b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 32b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam throw new IllegalArgumentException("illegal object in getInstance: " + obj.getClass().getName()); 33b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 34b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 35b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam public static IssuerSerial getInstance( 36b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam ASN1TaggedObject obj, 37b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam boolean explicit) 38b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 39b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam return getInstance(ASN1Sequence.getInstance(obj, explicit)); 40b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 41b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 42b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam public IssuerSerial( 43b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam ASN1Sequence seq) 44b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 45b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam if (seq.size() != 2 && seq.size() != 3) 46b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 47b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam throw new IllegalArgumentException("Bad sequence size: " + seq.size()); 48b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 49b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 50b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam issuer = GeneralNames.getInstance(seq.getObjectAt(0)); 51b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam serial = DERInteger.getInstance(seq.getObjectAt(1)); 52b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 53b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam if (seq.size() == 3) 54b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 55b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam issuerUID = DERBitString.getInstance(seq.getObjectAt(2)); 56b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 57b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 58b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 59b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam public IssuerSerial( 60b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam GeneralNames issuer, 61b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam DERInteger serial) 62b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 63b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam this.issuer = issuer; 64b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam this.serial = serial; 65b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 66b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 67b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam public GeneralNames getIssuer() 68b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 69b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam return issuer; 70b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 71b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 72b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam public DERInteger getSerial() 73b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 74b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam return serial; 75b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 76b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 77b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam public DERBitString getIssuerUID() 78b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 79b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam return issuerUID; 80b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 81b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 82b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam /** 83b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * Produce an object suitable for an ASN1OutputStream. 84b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * <pre> 85b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * IssuerSerial ::= SEQUENCE { 86b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * issuer GeneralNames, 87b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * serial CertificateSerialNumber, 88b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * issuerUID UniqueIdentifier OPTIONAL 89b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * } 90b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * </pre> 91b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam */ 92b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam public DERObject toASN1Object() 93b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 94b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam ASN1EncodableVector v = new ASN1EncodableVector(); 95b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 96b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam v.add(issuer); 97b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam v.add(serial); 98b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 99b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam if (issuerUID != null) 100b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 101b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam v.add(issuerUID); 102b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 103b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 104b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam return new DERSequence(v); 105b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 106b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam} 107