01: package org.bouncycastle.x509;
02:
03: import org.bouncycastle.util.Selector;
04:
05: import java.io.IOException;
06: import java.security.cert.Certificate;
07: import java.security.cert.X509CertSelector;
08: import java.security.cert.X509Certificate;
09:
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 extends X509CertSelector implements
18: Selector {
19: public boolean match(Object obj) {
20: if (!(obj instanceof X509Certificate)) {
21: return false;
22: }
23:
24: X509Certificate other = (X509Certificate) obj;
25:
26: return super .match(other);
27: }
28:
29: public boolean match(Certificate cert) {
30: return match((Object) cert);
31: }
32:
33: public Object clone() {
34: X509CertStoreSelector selector = (X509CertStoreSelector) super
35: .clone();
36:
37: return selector;
38: }
39:
40: /**
41: * Returns an instance of this from a <code>X509CertSelector</code>.
42: *
43: * @param selector A <code>X509CertSelector</code> instance.
44: * @return An instance of an <code>X509CertStoreSelector</code>.
45: * @exception IllegalArgumentException if selector is null or creation fails.
46: */
47: public static X509CertStoreSelector getInstance(
48: X509CertSelector selector) {
49: if (selector == null) {
50: throw new IllegalArgumentException(
51: "cannot create from null selector");
52: }
53: X509CertStoreSelector cs = new X509CertStoreSelector();
54: cs.setAuthorityKeyIdentifier(selector
55: .getAuthorityKeyIdentifier());
56: cs.setBasicConstraints(selector.getBasicConstraints());
57: cs.setCertificate(selector.getCertificate());
58: cs.setCertificateValid(selector.getCertificateValid());
59: cs.setMatchAllSubjectAltNames(selector
60: .getMatchAllSubjectAltNames());
61: try {
62: cs.setPathToNames(selector.getPathToNames());
63: cs.setExtendedKeyUsage(selector.getExtendedKeyUsage());
64: cs.setNameConstraints(selector.getNameConstraints());
65: cs.setPolicy(selector.getPolicy());
66: cs.setSubjectPublicKeyAlgID(selector
67: .getSubjectPublicKeyAlgID());
68: } catch (IOException e) {
69: throw new IllegalArgumentException(
70: "error in passed in selector: " + e);
71: }
72: cs.setIssuer(selector.getIssuer());
73: cs.setKeyUsage(selector.getKeyUsage());
74: cs.setPrivateKeyValid(selector.getPrivateKeyValid());
75: cs.setSerialNumber(selector.getSerialNumber());
76: cs.setSubject(selector.getSubject());
77: cs.setSubjectKeyIdentifier(selector.getSubjectKeyIdentifier());
78: cs.setSubjectPublicKey(selector.getSubjectPublicKey());
79: return cs;
80: }
81:
82: }
|