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

package org.bouncycastle.pkix.jcajce;

import java.security.cert.CertStoreException;
import java.security.cert.CRL;
import java.security.cert.CertStore;
import org.bouncycastle.util.StoreException;
import java.util.Collection;
import org.bouncycastle.util.Selector;
import org.bouncycastle.util.Store;
import java.security.cert.X509Certificate;
import java.util.Iterator;
import java.security.cert.X509CRL;
import java.util.Date;
import java.util.List;
import java.util.HashSet;
import java.security.cert.CRLSelector;
import org.bouncycastle.jcajce.PKIXCRLStoreSelector;
import java.util.Set;
import java.security.cert.PKIXParameters;

abstract class PKIXCRLUtil
{
    static Set findCRLs(final X509CRLStoreSelector x509CRLStoreSelector, final PKIXParameters pkixParameters) throws AnnotatedException {
        return findCRLs(new PKIXCRLStoreSelector.Builder(x509CRLStoreSelector).build(), pkixParameters);
    }
    
    static Set findCRLs(final PKIXCRLStoreSelector pkixcrlStoreSelector, final PKIXParameters pkixParameters) throws AnnotatedException {
        final HashSet set = new HashSet();
        try {
            findCRLs(set, pkixcrlStoreSelector, pkixParameters.getCertStores());
        }
        catch (final AnnotatedException ex) {
            throw new AnnotatedException("Exception obtaining complete CRLs.", ex);
        }
        return set;
    }
    
    static Set findCRLs(final PKIXCRLStoreSelector pkixcrlStoreSelector, final Date when, final List list, final List list2) throws AnnotatedException {
        final HashSet set = new HashSet();
        try {
            findCRLs(set, pkixcrlStoreSelector, list2);
            findCRLs(set, pkixcrlStoreSelector, list);
        }
        catch (final AnnotatedException ex) {
            throw new AnnotatedException("Exception obtaining complete CRLs.", ex);
        }
        final HashSet set2 = new HashSet();
        for (final X509CRL x509CRL : set) {
            final Date nextUpdate = x509CRL.getNextUpdate();
            if (nextUpdate == null || nextUpdate.after(when)) {
                final X509Certificate certificateChecking = pkixcrlStoreSelector.getCertificateChecking();
                if (null != certificateChecking && !x509CRL.getThisUpdate().before(certificateChecking.getNotAfter())) {
                    continue;
                }
                set2.add(x509CRL);
            }
        }
        return set2;
    }
    
    private static void findCRLs(final Set set, final PKIXCRLStoreSelector pkixcrlStoreSelector, final List list) throws AnnotatedException {
        Object o = null;
        boolean b = false;
        for (final Object next : list) {
            if (next instanceof Store) {
                final Store store = (Store)next;
                try {
                    set.addAll(store.getMatches(pkixcrlStoreSelector));
                    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(PKIXCRLStoreSelector.getCRLs(pkixcrlStoreSelector, certStore));
                    b = true;
                }
                catch (final CertStoreException ex2) {
                    o = new AnnotatedException("Exception searching in X.509 CRL store.", ex2);
                }
            }
        }
        if (!b && o != null) {
            throw o;
        }
    }
}
