PkixCrlUtilities
using Org.BouncyCastle.Utilities.Collections;
using Org.BouncyCastle.X509;
using Org.BouncyCastle.X509.Store;
using System;
using System.Collections.Generic;
namespace Org.BouncyCastle.Pkix
{
public class PkixCrlUtilities
{
public virtual ISet<X509Crl> FindCrls(X509CrlStoreSelector crlSelector, PkixParameters paramsPkix)
{
return ImplFindCrls(crlSelector, paramsPkix);
}
public virtual ISet<X509Crl> FindCrls(ISelector<X509Crl> crlSelector, PkixParameters paramsPkix)
{
return ImplFindCrls(crlSelector, paramsPkix);
}
public virtual ISet<X509Crl> FindCrls(X509CrlStoreSelector crlSelector, PkixParameters paramsPkix, DateTime currentDate)
{
return ImplFindCrls(crlSelector, paramsPkix, currentDate);
}
public virtual ISet<X509Crl> FindCrls(ISelector<X509Crl> crlSelector, PkixParameters paramsPkix, DateTime currentDate)
{
return ImplFindCrls(crlSelector, paramsPkix, currentDate);
}
internal static HashSet<X509Crl> ImplFindCrls(ISelector<X509Crl> crlSelector, PkixParameters paramsPkix)
{
try {
return ImplFindCrls(crlSelector, paramsPkix.GetStoresCrl());
} catch (Exception innerException) {
throw new Exception("Exception obtaining complete CRLs.", innerException);
}
}
internal static HashSet<X509Crl> ImplFindCrls(ISelector<X509Crl> crlSelector, PkixParameters paramsPkix, DateTime currentDate)
{
HashSet<X509Crl> hashSet = ImplFindCrls(crlSelector, paramsPkix);
HashSet<X509Crl> hashSet2 = new HashSet<X509Crl>();
DateTime value = currentDate;
if (paramsPkix.Date.HasValue)
value = paramsPkix.Date.Value;
X509Certificate x509Certificate = null;
ICheckingCertificate checkingCertificate = crlSelector as ICheckingCertificate;
if (checkingCertificate != null)
x509Certificate = checkingCertificate.CertificateChecking;
foreach (X509Crl item in hashSet) {
DateTime? nextUpdate = item.NextUpdate;
DateTime dateTime;
if (nextUpdate.HasValue) {
dateTime = nextUpdate.Value;
if (dateTime.CompareTo(value) <= 0)
continue;
}
if (x509Certificate != null) {
dateTime = item.ThisUpdate;
if (dateTime.CompareTo(x509Certificate.NotAfter) >= 0)
continue;
}
hashSet2.Add(item);
}
return hashSet2;
}
internal static HashSet<X509Crl> ImplFindCrls(ISelector<X509Crl> crlSelector, IEnumerable<IStore<X509Crl>> crlStores)
{
HashSet<X509Crl> hashSet = new HashSet<X509Crl>();
Exception ex = null;
bool flag = false;
foreach (IStore<X509Crl> crlStore in crlStores) {
try {
hashSet.UnionWith(crlStore.EnumerateMatches(crlSelector));
flag = true;
} catch (Exception ex2) {
ex = ex2;
}
}
if (!flag && ex != null)
throw new Exception("Exception searching in X.509 CRL store.", ex);
return hashSet;
}
}
}