/// <param name="cert"></param>
        /// <returns></returns>
        public virtual CertificateStatus GetCertificateStatusFromContext(CertificateAndContext
                                                                         cert)
        {
            if (cert.GetCertificateSource() == CertificateSourceType.TRUSTED_LIST)
            {
                CertificateStatus status = new CertificateStatus();
                status.Validity         = CertificateValidity.VALID;
                status.StatusSourceType = ValidatorSourceType.TRUSTED_LIST;
                status.Certificate      = cert.GetCertificate();
                return(status);
            }
            CertificateAndContext issuer = GetIssuerCertificateFromThisContext(cert);

            if (issuer == null)
            {
                return(null);
            }
            IOcspSource ocspSource = new ListOCSPSource(neededOCSPResp);
            ICrlSource  crlSource  = new ListCRLSource(neededCRL);
            OCSPAndCRLCertificateVerifier verifier = new OCSPAndCRLCertificateVerifier();

            verifier.SetCrlSource(crlSource);
            verifier.SetOcspSource(ocspSource);
            return(verifier.Check(cert.GetCertificate(), issuer.GetCertificate(), GetValidationDate
                                      ()));
        }
        /// <summary>Retrieve the parent from the trusted list</summary>
        /// <param name="ctx"></param>
        /// <returns></returns>
        public virtual CertificateAndContext GetParentFromTrustedList(CertificateAndContext
                                                                      ctx)
        {
            CertificateAndContext parent = ctx;

            while (GetIssuerCertificateFromThisContext(parent) != null)
            {
                parent = GetIssuerCertificateFromThisContext(parent);
                if (parent.GetCertificateSource() == CertificateSourceType.TRUSTED_LIST)
                {
                    LOG.Info("Parent from TrustedList found " + parent);
                    return(parent);
                }
            }
            LOG.Warn("No issuer in the TrustedList for this certificate. The parent found is "
                     + parent);
            return(null);
        }
        /// <summary>Build the validation context for the specific date</summary>
        /// <param name="validationDate"></param>
        /// <param name="optionalSource"></param>
        /// <exception cref="System.IO.IOException"></exception>
        public virtual void Validate(DateTime validationDate, CertificateSource optionalSource
                                     , ICrlSource optionalCRLSource, IOcspSource optionalOCPSSource)
        {
            int         previousSize     = revocationInfo.Count;
            int         previousVerified = VerifiedTokenCount();
            SignedToken signedToken      = GetOneNotYetVerifiedToken();

            if (signedToken != null)
            {
                CertificateSource otherSource = optionalSource;
                if (signedToken != null)
                {
                    otherSource = new CompositeCertificateSource(signedToken.GetWrappedCertificateSource
                                                                     (), optionalSource);
                }
                CertificateAndContext issuer = GetIssuerCertificate(signedToken, otherSource, validationDate
                                                                    );
                RevocationData data = null;
                if (issuer == null)
                {
                    LOG.Warn("Don't found any issuer for token " + signedToken);
                    data = new RevocationData(signedToken);
                }
                else
                {
                    AddNotYetVerifiedToken(new CertificateToken(issuer));
                    if (issuer.GetCertificate().SubjectDN.Equals(issuer.GetCertificate
                                                                     ().IssuerDN))
                    {
                        SignedToken    trustedToken     = new CertificateToken(issuer);
                        RevocationData noNeedToValidate = new RevocationData();
                        // noNeedToValidate.setRevocationData(CertificateSourceType.TRUSTED_LIST);
                        Validate(trustedToken, noNeedToValidate);
                    }
                    if (issuer.GetCertificateSource() == CertificateSourceType.TRUSTED_LIST)
                    {
                        SignedToken    trustedToken     = new CertificateToken(issuer);
                        RevocationData noNeedToValidate = new RevocationData();
                        noNeedToValidate.SetRevocationData(CertificateSourceType.TRUSTED_LIST);
                        Validate(trustedToken, noNeedToValidate);
                    }
                    if (signedToken is CertificateToken)
                    {
                        CertificateToken  ct     = (CertificateToken)signedToken;
                        CertificateStatus status = GetCertificateValidity(ct.GetCertificateAndContext(),
                                                                          issuer, validationDate, optionalCRLSource, optionalOCPSSource);
                        data = new RevocationData(signedToken);
                        if (status != null)
                        {
                            data.SetRevocationData(status.StatusSource);
                            if (status.StatusSource is X509Crl)
                            {
                                AddNotYetVerifiedToken(new CRLToken((X509Crl)status.StatusSource));
                            }
                            else
                            {
                                if (status.StatusSource is BasicOcspResp)
                                {
                                    AddNotYetVerifiedToken(new OCSPRespToken((BasicOcspResp)status.StatusSource));
                                }
                            }
                        }
                        else
                        {
                            LOG.Warn("No status for " + signedToken);
                        }
                    }
                    else
                    {
                        if (signedToken is CRLToken || signedToken is OCSPRespToken || signedToken is TimestampToken)
                        {
                            data = new RevocationData(signedToken);
                            data.SetRevocationData(issuer);
                        }
                        else
                        {
                            throw new RuntimeException("Not supported token type " + signedToken.GetType().Name
                                                       );
                        }
                    }
                }
                Validate(signedToken, data);
                LOG.Info(this.ToString());
                int newSize     = revocationInfo.Count;
                int newVerified = VerifiedTokenCount();
                if (newSize != previousSize || newVerified != previousVerified)
                {
                    Validate(validationDate, otherSource, optionalCRLSource, optionalOCPSSource);
                }
            }
        }