01: package org.bouncycastle.jce.provider;
02:
03: import java.security.InvalidAlgorithmParameterException;
04: import java.security.cert.CRL;
05: import java.security.cert.CRLSelector;
06: import java.security.cert.CertSelector;
07: import java.security.cert.CertStoreException;
08: import java.security.cert.CertStoreParameters;
09: import java.security.cert.CertStoreSpi;
10: import java.security.cert.Certificate;
11: import java.security.cert.CollectionCertStoreParameters;
12: import java.util.ArrayList;
13: import java.util.Collection;
14: import java.util.Iterator;
15: import java.util.List;
16:
17: public class CertStoreCollectionSpi extends CertStoreSpi {
18: private CollectionCertStoreParameters params;
19:
20: public CertStoreCollectionSpi(CertStoreParameters params)
21: throws InvalidAlgorithmParameterException {
22: super (params);
23:
24: if (!(params instanceof CollectionCertStoreParameters)) {
25: throw new InvalidAlgorithmParameterException(
26: "org.bouncycastle.jce.provider.CertStoreCollectionSpi: parameter must be a CollectionCertStoreParameters object\n"
27: + params.toString());
28: }
29:
30: this .params = (CollectionCertStoreParameters) params;
31: }
32:
33: public Collection engineGetCertificates(CertSelector selector)
34: throws CertStoreException {
35: List col = new ArrayList();
36: Iterator iter = params.getCollection().iterator();
37:
38: if (selector == null) {
39: while (iter.hasNext()) {
40: Object obj = iter.next();
41:
42: if (obj instanceof Certificate) {
43: col.add(obj);
44: }
45: }
46: } else {
47: while (iter.hasNext()) {
48: Object obj = iter.next();
49:
50: if ((obj instanceof Certificate)
51: && selector.match((Certificate) obj)) {
52: col.add(obj);
53: }
54: }
55: }
56:
57: return col;
58: }
59:
60: public Collection engineGetCRLs(CRLSelector selector)
61: throws CertStoreException {
62: List col = new ArrayList();
63: Iterator iter = params.getCollection().iterator();
64:
65: if (selector == null) {
66: while (iter.hasNext()) {
67: Object obj = iter.next();
68:
69: if (obj instanceof CRL) {
70: col.add(obj);
71: }
72: }
73: } else {
74: while (iter.hasNext()) {
75: Object obj = iter.next();
76:
77: if ((obj instanceof CRL) && selector.match((CRL) obj)) {
78: col.add(obj);
79: }
80: }
81: }
82:
83: return col;
84: }
85: }
|