Home | History | Annotate | Download | only in cms
      1 package org.bouncycastle.cms;
      2 
      3 import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
      4 import org.bouncycastle.cert.X509CertificateHolder;
      5 import org.bouncycastle.operator.ContentVerifier;
      6 import org.bouncycastle.operator.ContentVerifierProvider;
      7 import org.bouncycastle.operator.DigestCalculator;
      8 import org.bouncycastle.operator.DigestCalculatorProvider;
      9 import org.bouncycastle.operator.OperatorCreationException;
     10 import org.bouncycastle.operator.SignatureAlgorithmIdentifierFinder;
     11 
     12 public class SignerInformationVerifier
     13 {
     14     private ContentVerifierProvider verifierProvider;
     15     private DigestCalculatorProvider digestProvider;
     16     private SignatureAlgorithmIdentifierFinder sigAlgorithmFinder;
     17     private CMSSignatureAlgorithmNameGenerator sigNameGenerator;
     18 
     19     public SignerInformationVerifier(CMSSignatureAlgorithmNameGenerator sigNameGenerator, SignatureAlgorithmIdentifierFinder sigAlgorithmFinder, ContentVerifierProvider verifierProvider, DigestCalculatorProvider digestProvider)
     20     {
     21         this.sigNameGenerator = sigNameGenerator;
     22         this.sigAlgorithmFinder = sigAlgorithmFinder;
     23         this.verifierProvider = verifierProvider;
     24         this.digestProvider = digestProvider;
     25     }
     26 
     27     public boolean hasAssociatedCertificate()
     28     {
     29         return verifierProvider.hasAssociatedCertificate();
     30     }
     31 
     32     public X509CertificateHolder getAssociatedCertificate()
     33     {
     34         return verifierProvider.getAssociatedCertificate();
     35     }
     36 
     37     public ContentVerifier getContentVerifier(AlgorithmIdentifier signingAlgorithm, AlgorithmIdentifier digestAlgorithm)
     38         throws OperatorCreationException
     39     {
     40         String              signatureName = sigNameGenerator.getSignatureName(digestAlgorithm, signingAlgorithm);
     41         AlgorithmIdentifier baseAlgID = sigAlgorithmFinder.find(signatureName);
     42 
     43         return verifierProvider.get(new AlgorithmIdentifier(baseAlgID.getAlgorithm(), signingAlgorithm.getParameters()));
     44     }
     45 
     46     public DigestCalculator getDigestCalculator(AlgorithmIdentifier algorithmIdentifier)
     47         throws OperatorCreationException
     48     {
     49         return digestProvider.get(algorithmIdentifier);
     50     }
     51 }
     52