01: package org.bouncycastle.x509;
02:
03: import org.bouncycastle.util.Selector;
04: import org.bouncycastle.util.Store;
05:
06: import java.security.NoSuchAlgorithmException;
07: import java.security.NoSuchProviderException;
08: import java.security.Provider;
09: import java.util.Collection;
10:
11: public class X509Store implements Store {
12: public static X509Store getInstance(String type,
13: X509StoreParameters parameters) throws NoSuchStoreException {
14: try {
15: X509Util.Implementation impl = X509Util.getImplementation(
16: "X509Store", type);
17:
18: return createStore(impl, parameters);
19: } catch (NoSuchAlgorithmException e) {
20: throw new NoSuchStoreException(e.getMessage());
21: }
22: }
23:
24: public static X509Store getInstance(String type,
25: X509StoreParameters parameters, String provider)
26: throws NoSuchStoreException, NoSuchProviderException {
27: return getInstance(type, parameters, X509Util
28: .getProvider(provider));
29: }
30:
31: public static X509Store getInstance(String type,
32: X509StoreParameters parameters, Provider provider)
33: throws NoSuchStoreException, NoSuchProviderException {
34: try {
35: X509Util.Implementation impl = X509Util.getImplementation(
36: "X509Store", type, provider);
37:
38: return createStore(impl, parameters);
39: } catch (NoSuchAlgorithmException e) {
40: throw new NoSuchStoreException(e.getMessage());
41: }
42: }
43:
44: private static X509Store createStore(X509Util.Implementation impl,
45: X509StoreParameters parameters) {
46: X509StoreSpi spi = (X509StoreSpi) impl.getEngine();
47:
48: spi.engineInit(parameters);
49:
50: return new X509Store(impl.getProvider(), spi);
51: }
52:
53: private Provider _provider;
54: private X509StoreSpi _spi;
55:
56: private X509Store(Provider provider, X509StoreSpi spi) {
57: _provider = provider;
58: _spi = spi;
59: }
60:
61: public Provider getProvider() {
62: return _provider;
63: }
64:
65: public Collection getMatches(Selector selector) {
66: return _spi.engineGetMatches(selector);
67: }
68: }
|