1package org.bouncycastle.jce.provider; 2 3import java.security.InvalidAlgorithmParameterException; 4import java.security.cert.CRL; 5import java.security.cert.CRLSelector; 6import java.security.cert.CertSelector; 7import java.security.cert.CertStoreException; 8import java.security.cert.CertStoreParameters; 9import java.security.cert.CertStoreSpi; 10import java.security.cert.Certificate; 11import java.security.cert.CollectionCertStoreParameters; 12import java.util.Collection; 13import java.util.HashSet; 14import java.util.Iterator; 15import java.util.Set; 16 17public class CertStoreCollectionSpi extends CertStoreSpi 18{ 19 private CollectionCertStoreParameters params; 20 21 public CertStoreCollectionSpi(CertStoreParameters params) 22 throws InvalidAlgorithmParameterException 23 { 24 super(params); 25 26 if (!(params instanceof CollectionCertStoreParameters)) 27 { 28 throw new InvalidAlgorithmParameterException("org.bouncycastle.jce.provider.CertStoreCollectionSpi: parameter must be a CollectionCertStoreParameters object\n" + params.toString()); 29 } 30 31 this.params = (CollectionCertStoreParameters)params; 32 } 33 34 public Collection engineGetCertificates( 35 CertSelector selector) 36 throws CertStoreException 37 { 38 Set col = new HashSet(); 39 Iterator iter = params.getCollection().iterator(); 40 41 if (selector == null) 42 { 43 while (iter.hasNext()) 44 { 45 Object obj = iter.next(); 46 47 if (obj instanceof Certificate) 48 { 49 col.add(obj); 50 } 51 } 52 } 53 else 54 { 55 while (iter.hasNext()) 56 { 57 Object obj = iter.next(); 58 59 if ((obj instanceof Certificate) && selector.match((Certificate)obj)) 60 { 61 col.add(obj); 62 } 63 } 64 } 65 66 return col; 67 } 68 69 70 public Collection engineGetCRLs( 71 CRLSelector selector) 72 throws CertStoreException 73 { 74 Set col = new HashSet(); 75 Iterator iter = params.getCollection().iterator(); 76 77 if (selector == null) 78 { 79 while (iter.hasNext()) 80 { 81 Object obj = iter.next(); 82 83 if (obj instanceof CRL) 84 { 85 col.add(obj); 86 } 87 } 88 } 89 else 90 { 91 while (iter.hasNext()) 92 { 93 Object obj = iter.next(); 94 95 if ((obj instanceof CRL) && selector.match((CRL)obj)) 96 { 97 col.add(obj); 98 } 99 } 100 } 101 102 return col; 103 } 104} 105