Home | History | Annotate | Download | only in x509
      1 package org.bouncycastle.x509;
      2 
      3 import org.bouncycastle.util.Selector;
      4 import org.bouncycastle.util.Store;
      5 
      6 import java.security.NoSuchAlgorithmException;
      7 import java.security.NoSuchProviderException;
      8 import java.security.Provider;
      9 import java.util.Collection;
     10 
     11 public class X509Store
     12     implements Store
     13 {
     14     public static X509Store getInstance(String type, X509StoreParameters parameters)
     15         throws NoSuchStoreException
     16     {
     17         try
     18         {
     19             X509Util.Implementation impl = X509Util.getImplementation("X509Store", type);
     20 
     21             return createStore(impl, parameters);
     22         }
     23         catch (NoSuchAlgorithmException e)
     24         {
     25             throw new NoSuchStoreException(e.getMessage());
     26         }
     27     }
     28 
     29     public static X509Store getInstance(String type, X509StoreParameters parameters, String provider)
     30         throws NoSuchStoreException, NoSuchProviderException
     31     {
     32         return getInstance(type, parameters, X509Util.getProvider(provider));
     33     }
     34 
     35     public static X509Store getInstance(String type, X509StoreParameters parameters, Provider provider)
     36         throws NoSuchStoreException
     37     {
     38         try
     39         {
     40             X509Util.Implementation impl = X509Util.getImplementation("X509Store", type, provider);
     41 
     42             return createStore(impl, parameters);
     43         }
     44         catch (NoSuchAlgorithmException e)
     45         {
     46             throw new NoSuchStoreException(e.getMessage());
     47         }
     48     }
     49 
     50     private static X509Store createStore(X509Util.Implementation impl, X509StoreParameters parameters)
     51     {
     52         X509StoreSpi spi = (X509StoreSpi)impl.getEngine();
     53 
     54         spi.engineInit(parameters);
     55 
     56         return new X509Store(impl.getProvider(), spi);
     57     }
     58 
     59     private Provider     _provider;
     60     private X509StoreSpi _spi;
     61 
     62     private X509Store(
     63         Provider provider,
     64         X509StoreSpi spi)
     65     {
     66         _provider = provider;
     67         _spi = spi;
     68     }
     69 
     70     public Provider getProvider()
     71     {
     72        return _provider;
     73     }
     74 
     75     public Collection getMatches(Selector selector)
     76     {
     77         return _spi.engineGetMatches(selector);
     78     }
     79 }
     80