// 
// Decompiled by Procyon v0.6.0
// 

package org.bouncycastle.x509;

import java.util.Iterator;
import java.security.cert.CertStoreException;
import java.util.Collection;
import java.security.cert.CRLSelector;
import java.security.cert.CertStore;
import org.bouncycastle.util.StoreException;
import org.bouncycastle.util.Selector;
import org.bouncycastle.jce.provider.AnnotatedException;
import java.util.List;
import java.util.HashSet;
import java.util.Set;
import java.security.cert.PKIXParameters;

abstract class PKIXCRLUtil
{
    static Set findCRLs(final X509CRLStoreSelector x509CRLStoreSelector, final PKIXParameters pkixParameters) throws AnnotatedException {
        final HashSet set = new HashSet();
        try {
            findCRLs(set, x509CRLStoreSelector, pkixParameters.getCertStores());
        }
        catch (final AnnotatedException ex) {
            throw new AnnotatedException("Exception obtaining complete CRLs.", ex);
        }
        return set;
    }
    
    private static void findCRLs(final Set set, final X509CRLStoreSelector selector, final List list) throws AnnotatedException {
        Object o = null;
        boolean b = false;
        for (final Object next : list) {
            if (next instanceof X509Store) {
                final X509Store x509Store = (X509Store)next;
                try {
                    set.addAll(x509Store.getMatches(selector));
                    b = true;
                }
                catch (final StoreException ex) {
                    o = new AnnotatedException("Exception searching in X.509 CRL store.", ex);
                }
            }
            else {
                final CertStore certStore = (CertStore)next;
                try {
                    set.addAll(certStore.getCRLs(selector));
                    b = true;
                }
                catch (final CertStoreException ex2) {
                    o = new AnnotatedException("Exception searching in X.509 CRL store.", ex2);
                }
            }
        }
        if (!b && o != null) {
            throw o;
        }
    }
}
