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