1package org.bouncycastle.cert.jcajce; 2 3import java.io.IOException; 4import java.security.cert.CertificateEncodingException; 5import java.security.cert.X509Certificate; 6import java.util.ArrayList; 7import java.util.Collection; 8import java.util.Iterator; 9import java.util.List; 10 11import org.bouncycastle.cert.X509CertificateHolder; 12import org.bouncycastle.util.CollectionStore; 13 14/** 15 * Class for storing Certificates for later lookup. 16 * <p> 17 * The class will convert X509Certificate objects into X509CertificateHolder objects. 18 * </p> 19 */ 20public class JcaCertStore 21 extends CollectionStore 22{ 23 /** 24 * Basic constructor. 25 * 26 * @param collection - initial contents for the store, this is copied. 27 */ 28 public JcaCertStore(Collection collection) 29 throws CertificateEncodingException 30 { 31 super(convertCerts(collection)); 32 } 33 34 private static Collection convertCerts(Collection collection) 35 throws CertificateEncodingException 36 { 37 List list = new ArrayList(collection.size()); 38 39 for (Iterator it = collection.iterator(); it.hasNext();) 40 { 41 Object o = it.next(); 42 43 if (o instanceof X509Certificate) 44 { 45 X509Certificate cert = (X509Certificate)o; 46 47 try 48 { 49 list.add(new X509CertificateHolder(cert.getEncoded())); 50 } 51 catch (IOException e) 52 { 53 throw new CertificateEncodingException("unable to read encoding: " + e.getMessage()); 54 } 55 } 56 else 57 { 58 list.add((X509CertificateHolder)o); 59 } 60 } 61 62 return list; 63 } 64} 65