Home | History | Annotate | Download | only in cms
      1 package org.bouncycastle.cms;
      2 
      3 import java.math.BigInteger;
      4 
      5 import org.bouncycastle.asn1.x500.X500Name;
      6 import org.bouncycastle.cert.selector.X509CertificateHolderSelector;
      7 import org.bouncycastle.util.Selector;
      8 
      9 /**
     10  * a basic index for a signer.
     11  */
     12 public class SignerId
     13     implements Selector
     14 {
     15     private X509CertificateHolderSelector baseSelector;
     16 
     17     private SignerId(X509CertificateHolderSelector baseSelector)
     18     {
     19         this.baseSelector = baseSelector;
     20     }
     21 
     22     /**
     23      * Construct a signer ID with the value of a public key's subjectKeyId.
     24      *
     25      * @param subjectKeyId a subjectKeyId
     26      */
     27     public SignerId(byte[] subjectKeyId)
     28     {
     29         this(null, null, subjectKeyId);
     30     }
     31 
     32     /**
     33      * Construct a signer ID based on the issuer and serial number of the signer's associated
     34      * certificate.
     35      *
     36      * @param issuer the issuer of the signer's associated certificate.
     37      * @param serialNumber the serial number of the signer's associated certificate.
     38      */
     39     public SignerId(X500Name issuer, BigInteger serialNumber)
     40     {
     41         this(issuer, serialNumber, null);
     42     }
     43 
     44     /**
     45      * Construct a signer ID based on the issuer and serial number of the signer's associated
     46      * certificate.
     47      *
     48      * @param issuer the issuer of the signer's associated certificate.
     49      * @param serialNumber the serial number of the signer's associated certificate.
     50      * @param subjectKeyId the subject key identifier to use to match the signers associated certificate.
     51      */
     52     public SignerId(X500Name issuer, BigInteger serialNumber, byte[] subjectKeyId)
     53     {
     54         this(new X509CertificateHolderSelector(issuer, serialNumber, subjectKeyId));
     55     }
     56 
     57     public X500Name getIssuer()
     58     {
     59         return baseSelector.getIssuer();
     60     }
     61 
     62     public BigInteger getSerialNumber()
     63     {
     64         return baseSelector.getSerialNumber();
     65     }
     66 
     67     public byte[] getSubjectKeyIdentifier()
     68     {
     69         return baseSelector.getSubjectKeyIdentifier();
     70     }
     71 
     72     public int hashCode()
     73     {
     74         return baseSelector.hashCode();
     75     }
     76 
     77     public boolean equals(
     78         Object  o)
     79     {
     80         if (!(o instanceof SignerId))
     81         {
     82             return false;
     83         }
     84 
     85         SignerId id = (SignerId)o;
     86 
     87         return this.baseSelector.equals(id.baseSelector);
     88     }
     89 
     90     public boolean match(Object obj)
     91     {
     92         if (obj instanceof SignerInformation)
     93         {
     94             return ((SignerInformation)obj).getSID().equals(this);
     95         }
     96 
     97         return baseSelector.match(obj);
     98     }
     99 
    100     public Object clone()
    101     {
    102         return new SignerId(this.baseSelector);
    103     }
    104 }
    105