01: package org.bouncycastle.jce.provider;
02:
03: import org.bouncycastle.jce.MultiCertStoreParameters;
04:
05: import java.security.InvalidAlgorithmParameterException;
06: import java.security.cert.CRLSelector;
07: import java.security.cert.CertSelector;
08: import java.security.cert.CertStore;
09: import java.security.cert.CertStoreException;
10: import java.security.cert.CertStoreParameters;
11: import java.security.cert.CertStoreSpi;
12: import java.util.ArrayList;
13: import java.util.Collection;
14: import java.util.Collections;
15: import java.util.Iterator;
16: import java.util.List;
17:
18: public class MultiCertStoreSpi extends CertStoreSpi {
19: private MultiCertStoreParameters params;
20:
21: public MultiCertStoreSpi(CertStoreParameters params)
22: throws InvalidAlgorithmParameterException {
23: super (params);
24:
25: if (!(params instanceof MultiCertStoreParameters)) {
26: throw new InvalidAlgorithmParameterException(
27: "org.bouncycastle.jce.provider.MultiCertStoreSpi: parameter must be a MultiCertStoreParameters object\n"
28: + params.toString());
29: }
30:
31: this .params = (MultiCertStoreParameters) params;
32: }
33:
34: public Collection engineGetCertificates(CertSelector certSelector)
35: throws CertStoreException {
36: boolean searchAllStores = params.getSearchAllStores();
37: Iterator iter = params.getCertStores().iterator();
38: List allCerts = searchAllStores ? new ArrayList()
39: : Collections.EMPTY_LIST;
40:
41: while (iter.hasNext()) {
42: CertStore store = (CertStore) iter.next();
43: Collection certs = store.getCertificates(certSelector);
44:
45: if (searchAllStores) {
46: allCerts.addAll(certs);
47: } else if (!certs.isEmpty()) {
48: return certs;
49: }
50: }
51:
52: return allCerts;
53: }
54:
55: public Collection engineGetCRLs(CRLSelector crlSelector)
56: throws CertStoreException {
57: boolean searchAllStores = params.getSearchAllStores();
58: Iterator iter = params.getCertStores().iterator();
59: List allCRLs = searchAllStores ? new ArrayList()
60: : Collections.EMPTY_LIST;
61:
62: while (iter.hasNext()) {
63: CertStore store = (CertStore) iter.next();
64: Collection crls = store.getCRLs(crlSelector);
65:
66: if (searchAllStores) {
67: allCRLs.addAll(crls);
68: } else if (!crls.isEmpty()) {
69: return crls;
70: }
71: }
72:
73: return allCRLs;
74: }
75: }
|