1 package org.bouncycastle.x509; 2 3 import org.bouncycastle.util.Selector; 4 5 import java.io.IOException; 6 import java.security.cert.Certificate; 7 import java.security.cert.X509CertSelector; 8 import java.security.cert.X509Certificate; 9 10 /** 11 * This class is a Selector implementation for X.509 certificates. 12 * 13 * @see org.bouncycastle.util.Selector 14 * @see org.bouncycastle.x509.X509Store 15 * @see org.bouncycastle.jce.provider.X509StoreCertCollection 16 */ 17 public class X509CertStoreSelector 18 extends X509CertSelector 19 implements Selector 20 { match(Object obj)21 public boolean match(Object obj) 22 { 23 if (!(obj instanceof X509Certificate)) 24 { 25 return false; 26 } 27 28 X509Certificate other = (X509Certificate)obj; 29 30 return super.match(other); 31 } 32 match(Certificate cert)33 public boolean match(Certificate cert) 34 { 35 return match((Object)cert); 36 } 37 clone()38 public Object clone() 39 { 40 X509CertStoreSelector selector = (X509CertStoreSelector)super.clone(); 41 42 return selector; 43 } 44 45 /** 46 * Returns an instance of this from a <code>X509CertSelector</code>. 47 * 48 * @param selector A <code>X509CertSelector</code> instance. 49 * @return An instance of an <code>X509CertStoreSelector</code>. 50 * @exception IllegalArgumentException if selector is null or creation fails. 51 */ getInstance(X509CertSelector selector)52 public static X509CertStoreSelector getInstance(X509CertSelector selector) 53 { 54 if (selector == null) 55 { 56 throw new IllegalArgumentException("cannot create from null selector"); 57 } 58 X509CertStoreSelector cs = new X509CertStoreSelector(); 59 cs.setAuthorityKeyIdentifier(selector.getAuthorityKeyIdentifier()); 60 cs.setBasicConstraints(selector.getBasicConstraints()); 61 cs.setCertificate(selector.getCertificate()); 62 cs.setCertificateValid(selector.getCertificateValid()); 63 cs.setMatchAllSubjectAltNames(selector.getMatchAllSubjectAltNames()); 64 try 65 { 66 cs.setPathToNames(selector.getPathToNames()); 67 cs.setExtendedKeyUsage(selector.getExtendedKeyUsage()); 68 cs.setNameConstraints(selector.getNameConstraints()); 69 cs.setPolicy(selector.getPolicy()); 70 cs.setSubjectPublicKeyAlgID(selector.getSubjectPublicKeyAlgID()); 71 cs.setSubjectAlternativeNames(selector.getSubjectAlternativeNames()); 72 } 73 catch (IOException e) 74 { 75 throw new IllegalArgumentException("error in passed in selector: " + e); 76 } 77 cs.setIssuer(selector.getIssuer()); 78 cs.setKeyUsage(selector.getKeyUsage()); 79 cs.setPrivateKeyValid(selector.getPrivateKeyValid()); 80 cs.setSerialNumber(selector.getSerialNumber()); 81 cs.setSubject(selector.getSubject()); 82 cs.setSubjectKeyIdentifier(selector.getSubjectKeyIdentifier()); 83 cs.setSubjectPublicKey(selector.getSubjectPublicKey()); 84 return cs; 85 } 86 87 } 88