bcpkix-jdk15on-147

lic CMSSignedDataParser(InputStream paramInputStream)
    throws CMSException
  {
    this(createDefaultDigestProvider(), null, paramInputStream);
  }
  
  public CMSSignedDataParser(DigestCalculatorProvider paramDigestCalculatorProvider, InputStream paramInputStream)
    throws CMSException
  {
    this(paramDigestCalculatorProvider, null, paramInputStream);
  }
  
  /**
   * @deprecated
   */
  public CMSSignedDataParser(CMSTypedStream paramCMSTypedStream, InputStream paramInputStream)
    throws CMSException
  {
    this(createDefaultDigestProvider(), paramCMSTypedStream, paramInputStream);
  }
  
  public CMSSignedDataParser(DigestCalculatorProvider paramDigestCalculatorProvider, CMSTypedStream paramCMSTypedStream, InputStream paramInputStream)
    throws CMSException
  {
    super(paramInputStream);
    try
    {
      _signedContent = paramCMSTypedStream;
      _signedData = SignedDataParser.getInstance(_contentInfo.getContent(16));
      digests = new HashMap();
      ASN1SetParser localASN1SetParser = _signedData.getDigestAlgorithms();
      ASN1Encodable localASN1Encodable;
      while ((localASN1Encodable = localASN1SetParser.readObject()) != null)
      {
        localObject = AlgorithmIdentifier.getInstance(localASN1Encodable);
        try
        {
          DigestCalculator localDigestCalculator = paramDigestCalculatorProvider.get((AlgorithmIdentifier)localObject);
          if (localDigestCalculator != null) {
            digests.put(((AlgorithmIdentifier)localObject).getAlgorithm(), localDigestCalculator);
          }
        }
        catch (OperatorCreationException localOperatorCreationException) {}
      }
      Object localObject = _signedData.getEncapContentInfo();
      ASN1OctetStringParser localASN1OctetStringParser = (ASN1OctetStringParser)((ContentInfoParser)localObject).getContent(4);
      if (localASN1OctetStringParser != null)
      {
        CMSTypedStream localCMSTypedStream = new CMSTypedStream(((ContentInfoParser)localObject).getContentType().getId(), localASN1OctetStringParser.getOctetStream());
        if (_signedContent == null) {
          _signedContent = localCMSTypedStream;
        } else {
          localCMSTypedStream.drain();
        }
      }
      if (paramCMSTypedStream == null) {
        _signedContentType = ((ContentInfoParser)localObject).getContentType();
      } else {
        _signedContentType = _signedContent.getContentType();
      }
    }
    catch (IOException localIOException)
    {
      throw new CMSException("io exception: " + localIOException.getMessage(), localIOException);
    }
    if (digests.isEmpty()) {
      throw new CMSException("no digests could be created for message.");
    }
  }
  
  public int getVersion()
  {
    return _signedData.getVersion().getValue().intValue();
  }
  
  public SignerInformationStore getSignerInfos()
    throws CMSException
  {
    if (_signerInfoStore == null)
    {
      populateCertCrlSets();
      ArrayList localArrayList = new ArrayList();
      HashMap localHashMap = new HashMap();
      Iterator localIterator = digests.keySet().iterator();
      Object localObject;
      while (localIterator.hasNext())
      {
        localObject = localIterator.next();
        localHashMap.put(localObject, ((DigestCalculator)digests.get(localObject)).getDigest());
      }
      try
      {
        localObject = _signedData.getSignerInfos();
        ASN1Encodable localASN1Encodable;
        while ((localASN1Encodable = ((ASN1SetParser)localObject).readObject()) != null)
        {
          SignerInfo localSignerInfo = SignerInfo.getInstance(localASN1Encodable.toASN1Primitive());
          byte[] arrayOfByte = (byte[])localHashMap.get(localSignerInfo.getDigestAlgorithm().getAlgorithm());
          localArrayList.add(new SignerInformation(localSignerInfo, _signedContentType, null, arrayOfByte));
        }
      }
      catch (IOException localIOException)
      {
        throw new CMSException("io exception: " + localIOException.getMessage(), localIOException);
      }
      _signerInfoStore = new SignerInformationStore(localArrayList);
    }
    return _signerInfoStore;
  }
  
  public X509Store getAttributeCertificates(String paramString1, String paramString2)
    throws NoSuchStoreException, NoSuchProviderException, CMSException
  {
    return getAttributeCertificates(paramString1, CMSUtils.getProvider(paramString2));
  }
  
  public X509Store getAttributeCertificates(String paramString, Provider paramProvider)
    throws NoSuchStoreException, CMSException
  {
    if (_attributeStore == null)
    {
      populateCertCrlSets();
      _attributeStore = HELPER.createAttributeStore(paramString, paramProvider, _certSet);
    }
    return _attributeStore;
  }
  
  /**
   * @deprecated
   */
  public X509Store getCertificates(String paramString1, String paramString2)
    throws NoSuchStoreException, NoSuchProviderException, CMSException
  {
    return getCertificates(paramString1, CMSUtils.getProvider(paramString2));
  }
  
  /**
   * @deprecated
   */
  public X509Store getCertificates(String paramString, Provider paramProvider)
    throws NoSuchStoreException, CMSException
  {
    if (_certificateStore == null)
    {
      populateCertCrlSets();
      _certificateStore = HELPER.createCertificateStore(paramString, paramProvider, _certSet);
    }
    return _certificateStore;
  }
  
  /**
   * @deprecated
   */
  public X509Store getCRLs(String paramString1, String paramString2)
    throws NoSuchStoreException, NoSuchProviderException, CMSException
  {
    return getCRLs(paramString1, CMSUtils.getProvider(paramString2));
  }
  
  /**
   * @deprecated
   */
  public X509Store getCRLs(String paramString, Provider paramProvider)
    throws NoSuchStoreException, CMSException
  {
    if (_crlStore == null)
    {
      populateCertCrlSets();
      _crlStore = HELPER.createCRLsStore(paramString, paramProvider, _crlSet);
    }
    return _crlStore;
  }
  
  /**
   * @deprecated
   */
  public CertStore getCertificatesAndCRLs(String paramString1, String paramString2)
    throws NoSuchAlgorithmException, NoSuchProviderException, CMSException
  {
    return getCertificatesAndCRLs(paramString1, CMSUtils.getProvider(paramString2));
  }
  
  /**
   * @deprecated
   */
  public CertStore getCertificatesAndCRLs(String paramString, Provider paramProvider)
    throws NoSuchAlgorithmException, NoSuchProviderException, CMSException
  {
    populateCertCrlSets();
    return HELPER.createCertStore(paramString, paramProvider, _certSet, _crlSet);
  }
  
  public Store getCertificates()
    throws CMSException
  {
    populateCertCrlSets();
    ASN1Set localASN1Set = _certSet;
    if (localASN1Set != null)
    {
      ArrayList localArrayList = new ArrayList(localASN1Set.size());
      Enumeration localEnumeration = localASN1Set.getObjects();
      while (localEnumeration.hasMoreElements())
      {
        ASN1Primitive localASN1Primitive = ((ASN1Encodable)localEnumeration.nextElement()).toASN1Primitive();
        if ((localASN1Primitive instanceof ASN1Sequence)) {
          localArrayList.add(new X509CertificateHolder(Certificate.getInstance(localASN1Primitive)));
        }
      }
      return new CollectionStore(localArrayList);
    }
    return new CollectionStore(new ArrayList());
  }
  
  public Store getCRLs()
    throws CMSException
  {
    populateCertCrlSets();
    ASN1Set localASN1Set = _crlSet;
    if (localASN1Set != null)
    {
      ArrayList localArrayList = new ArrayList(localASN1Set.size());
      Enumeration localEnumeration = localASN1Set.getObjects();
      while (localEnumeration.hasMoreElements())
      {
        ASN1Primitive localASN1Primitive = ((ASN1Encodable)localEnumeration.nextElement()).toASN1Primitive();
        if ((localASN1Primitive instanceof ASN1Sequence)) {
          localArrayList.add(new X509CRLHolder(CertificateList.getInstance(localASN1Primitive)));
        }
      }
      return new CollectionStore(localArrayList);
    }
    return new CollectionStore(new ArrayList());
  }
  
  public Store getAttributeCertificates()
    throws CMSException
  {
    populateCertCrlSets();
    ASN1Set localASN1Set = _certSet;
    if (localASN1Set != null)
    {
      ArrayList localArrayList = new ArrayList(localASN1Set.size());
      Enumeration localEnumeration = localASN1Set.getObjects();
      while (localEnumeration.hasMoreElements())
      {
        ASN1Primitive localASN1Primitive = ((ASN1Encodable)localEnumeration.nextElement()).toASN1Primitive();
        if ((localASN1Primitive instanceof ASN1TaggedObject))
        {
          ASN1TaggedObject localASN1TaggedObject = (ASN1TaggedObject)localASN1Primitive;
          if (localASN1TaggedObject.getTagNo() == 2) {
            localArrayList.add(new X509AttributeCertificateHolder(AttributeCertificate.getInstance(ASN1Sequence.getInstance(localASN1TaggedObject, false))));
          }
        }
      }
      return new CollectionStore(localArrayList);
    }
    return new CollectionStore(new ArrayList());
  }
  
  private void populateCertCrlSets()
    throws CMSException
  {
    if (_isCertCrlParsed) {
      return;
    }
    _isCertCrlParsed = true;
    try
    {
      _certSet = getASN1Set(_signedData.getCertificates());
      _crlSet = getASN1Set(_signedData.getCrls());
    }
    catch (IOException localIOException)
    {
      throw new CMSException("problem parsing cert/crl sets", localIOException);
    }
  }
  
  public String getSignedContentTypeOID()
  {
    return _signedContentType.getId();
  }
  
  public CMSTypedStream getSignedContent()
  {
    if (_signedContent == null) {
      return null;
    }
    InputStream localInputStream = CMSUtils.attachDigestsToInputStream(digests.values(), _signedContent.getContentStream());
    return new CMSTypedStream(_signedContent.getContentType(), localInputStream);
  }
  
  public static OutputStream replaceSigners(InputStream paramInputStream, SignerInformationStore paramSignerInformationStore, OutputStream paramOutputStream)
    throws CMSException, IOException
  {
    ASN1StreamParser localASN1StreamParser = new ASN1StreamParser(paramInputStream);
    ContentInfoParser localContentInfoParser = new ContentInfoParser((ASN1SequenceParser)localASN1StreamParser.readObject());
    SignedDataParser localSignedDataParser = SignedDataParser.getInstance(localContentInfoParser.getContent(16));
    BERSequenceGenerator localBERSequenceGenerator1 = new BERSequenceGenerator(paramOutputStream);
    localBERSequenceGenerator1.addObject(CMSObjectIdentifiers.signedData);
    BERSequenceGenerator localBERSequenceGenerator2 = new BERSequenceGenerator(localBERSequenceGenerator1.getRawOutputStream(), 0, true);
    localBERSequenceGenerator2.addObject(localSignedDataParser.getVersion());
    localSignedDataParser.getDigestAlgorithms().toASN1Primitive();
    ASN1EncodableVector localASN1EncodableVector1 = new ASN1EncodableVector();
    Object localObject1 = paramSignerInformationStore.getSigners().iterator();
    while (((Iterator)localObject1).hasNext())
    {
      localObject2 = (SignerInformation)((Iterator)localObject1).next();
      localASN1EncodableVector1.add(CMSSignedHelper.INSTANCE.fixAlgID(((SignerInformation)localObject2).getDigestAlgorithmID()));
    }
    localBERSequenceGenerator2.getRawOutputStream().write(new DERSet(localASN1EncodableVector1).getEncoded());
    localObject1 = localSignedDataParser.getEncapContentInfo();
    Object localObject2 = new BERSequenceGenerator(localBERSequenceGenerator2.getRawOutputStream());
    ((BERSequenceGenerator)localObject2).addObject(((ContentInfoParser)localObject1).getContentType());
    pipeEncapsulatedOctetString((ContentInfoParser)localObject1, ((BERSequenceGenerator)localObject2).getRawOutputStream());
    ((BERSequenceGenerator)localObject2).close();
    writeSetToGeneratorTagged(localBERSequenceGenerator2, localSignedDataParser.getCertificates(), 0);
    writeSetToGeneratorTagged(localBERSequenceGenerator2, localSignedDataParser.getCrls(), 1);
    ASN1EncodableVector localASN1EncodableVector2 = new ASN1EncodableVector();
    Iterator localIterator = paramSignerInformationStore.getSigners().iterator();
    while (localIterator.hasNext())
    {
      SignerInformation localSignerInformation = (SignerInformation)localIterator.next();
      localASN1EncodableVector2.add(localSignerInformation.toASN1Structure());
    }
    localBERSequenceGenerator2.getRawOutputStream().write(new DERSet(localASN1EncodableVector2).getEncoded());
    localBERSequenceGenerator2.close();
    localBERSequenceGenerator1.close();
    return paramOutputStream;
  }
  
  /**
   * @deprecated
   */
  public static OutputStream replaceCertificatesAndCRLs(InputStream paramInputStream, CertStore paramCertStore, OutputStream paramOutputStream)
    throws CMSException, IOException
  {
    ASN1StreamParser localASN1StreamParser = new ASN1StreamParser(paramInputStream);
    ContentInfoParser localContentInfoParser1 = new ContentInfoParser((ASN1SequenceParser)localASN1StreamParser.readObject());
    SignedDataParser localSignedDataParser = SignedDataParser.getInstance(localContentInfoParser1.getContent(16));
    BERSequenceGenerator localBERSequenceGenerator1 = new BERSequenceGenerator(paramOutputStream);
    localBERSequenceGenerator1.addObject(CMSObjectIdentifiers.signedData);
    BERSequenceGenerator localBERSequenceGenerator2 = new BERSequenceGenerator(localBERSequenceGenerator1.getRawOutputStream(), 0, true);
    localBERSequenceGenerator2.addObject(localSignedDataParser.getVersion());
    localBERSequenceGenerator2.getRawOutputStream().write(localSignedDataParser.getDigestAlgorithms().toASN1Primitive().getEncoded());
    ContentInfoParser localContentInfoParser2 = localSignedDataParser.getEncapContentInfo();
    BERSequenceGenerator localBERSequenceGenerator3 = new BERSequenceGenerator(localBERSequenceGenerator2.getRawOutputStream());
    localBERSequenceGenerator3.addObject(localContentInfoParser2.getContentType());
    pipeEncapsulatedOctetString(localContentInfoParser2, localBERSequenceGenerator3.getRawOutputStream());
    localBERSequenceGenerator3.close();
    getASN1Set(localSignedDataParser.getCertificates());
    getASN1Set(localSignedDataParser.getCrls());
    ASN1Set localASN1Set1;
    try
    {
      localASN1Set1 = CMSUtils.createBerSetFromList(CMSUtils.getCertificatesFromStore(paramCertStore));
    }
    catch (CertStoreException localCertStoreException1)
    {
      throw new CMSException("error getting certs from certStore", localCertStoreException1);
    }
    if (localASN1Set1.size() > 0) {
      localBERSequenceGenerator2.getRawOutputStream().write(new DERTaggedObject(false, 0, localASN1Set1).getEncoded());
    }
    ASN1Set localASN1Set2;
    try
    {
      localASN1Set2 = CMSUtils.createBerSetFromList(CMSUtils.getCRLsFromStore(paramCertStore));
    }
    catch (CertStoreException localCertStoreException2)
    {
      throw new CMSException("error getting crls from certStore", localCertStoreException2);
    }
    if (localASN1Set2.size() > 0) {
      localBERSequenceGenerator2.getRawOutputStream().write(new DERTaggedObject(false, 1, localASN1Set2).getEncoded());
    }
    localBERSequenceGenerator2.getRawOutputStream().write(localSignedDataParser.getSignerInfos().toASN1Primitive().getEncoded());
    localBERSequenceGenerator2.close();
    localBERSequenceGenerator1.close();
    return paramOutputStream;
  }
  
  public static OutputStream replaceCertificatesAndCRLs(InputStream paramInputStream, Store paramStore1, Store paramStore2, Store paramStore3, OutputStream paramOutputStream)
    throws CMSException, IOException
  {
    ASN1StreamParser localASN1StreamParser = new ASN1StreamParser(paramInputStream);
    ContentInfoParser localContentInfoParser1 = new ContentInfoParser((ASN1SequenceParser)localASN1StreamParser.readObject());
    SignedDataParser localSignedDataParser = SignedDataParser.getInstance(localContentInfoParser1.getContent(16));
    BERSequenceGenerator localBERSequenceGenerator1 = new BERSequenceGenerator(paramOutputStream);
    localBERSequenceGenerator1.addObject(CMSObjectIdentifiers.signedData);
    BERSequenceGenerator localBERSequenceGenerator2 = new BERSequenceGenerator(localBERSequenceGenerator1.getRawOutputStream(), 0, true);
    localBERSequenceGenerator2.addObject(localSignedDataParser.getVersion());
    localBERSequenceGenerator2.getRawOutputStream().write(localSignedDataParser.getDigestAlgorithms().toASN1Primitive().getEncoded());
    ContentInfoParser localContentInfoParser2 = localSignedDataParser.getEncapContentInfo();
    BERSequenceGenerator localBERSequenceGenerator3 = new BERSequenceGenerator(localBERSequenceGenerator2.getRawOutputStream());
    localBERSequenceGenerator3.addObject(localContentInfoParser2.getContentType());
    pipeEncapsulatedOctetString(localContentInfoParser2, localBERSequenceGenerator3.getRawOutputStream());
    localBERSequenceGenerator3.close();
    getASN1Set(localSignedDataParser.getCertificates());
    getASN1Set(localSignedDataParser.getCrls());
    Object localObject;
    if ((paramStore1 != null) || (paramStore3 != null))
    {
      localObject = new ArrayList();
      if (paramStore1 != null) {
        ((List)localObject).addAll(CMSUtils.getCertificatesFromStore(paramStore1));
      }
      if (paramStore3 != null) {
        ((List)localObject).addAll(CMSUtils.getAttributeCertificatesFromStore(paramStore3));
      }
      ASN1Set localASN1Set = CMSUtils.createBerSetFromList((List)localObject);
      if (localASN1Set.size() > 0) {
        localBERSequenceGenerator2.getRawOutputStream().write(new DERTaggedObject(false, 0, localASN1Set).getEncoded());
      }
    }
    if (paramStore2 != null)
    {
      localObject = CMSUtils.createBerSetFromList(CMSUtils.getCRLsFromStore(paramStore2));
      if (((ASN1Set)localObject).size() > 0) {
        localBERSequenceGenerator2.getRawOutputStream().write(new DERTaggedObject(false, 1, (ASN1Encodable)localObject).getEncoded());
      }
    }
    localBERSequenceGenerator2.getRawOutputStream().write(localSignedDataParser.getSignerInfos().toASN1Primitive().getEncoded());
    localBERSequenceGenerator2.close();
    localBERSequenceGenerator1.close();
    return paramOutputStream;
  }
  
  private static void writeSetToGeneratorTagged(ASN1Generator paramASN1Generator, ASN1SetParser paramASN1SetParser, int paramInt)
    throws IOException
  {
    ASN1Set localASN1Set = getASN1Set(paramASN1SetParser);
    if (localASN1Set != null) {
      if ((paramASN1SetParser instanceof BERSetParser)) {
        paramASN1Generator.getRawOutputStream().write(new BERTaggedObject(false, paramInt, localASN1Set).getEncoded());
      } else {
        paramASN1Generator.getRawOutputStream().write(new DERTaggedObject(false, paramInt, localASN1Set).getEncoded());
      }
    }
  }
  
  private static ASN1Set getASN1Set(ASN1SetParser paramASN1SetParser)
  {
    return paramASN1SetParser == null ? null : ASN1Set.getInstance(paramASN1SetParser.toASN1Primitive());
  }
  
  private static void pipeEncapsulatedOctetString(ContentInfoParser paramContentInfoParser, OutputStream paramOutputStream)
    throws IOException
  {
    ASN1OctetStringParser localASN1OctetStringParser = (ASN1OctetStringParser)paramContentInfoParser.getContent(4);
    if (localASN1OctetStringParser != null) {
      pipeOctetString(localASN1OctetStringParser, paramOutputStream);
    }
  }
  
  private static void pipeOctetString(ASN1OctetStringParser paramASN1OctetStringParser, OutputStream paramOutputStream)
    throws IOException
  {
    OutputStream localOutputStream = CMSUtils.createBEROctetOutputStream(paramOutputStream, 0, true, 0);
    Streams.pipeAll(paramASN1OctetStringParser.getOctetStream(), localOutputStream);
    localOutputStream.close();
  }
}

/* Location:
 * Qualified Name:     org.bouncycastle.cms.CMSSignedDataParser
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.bouncycastle.cms;

import java.io.IOException;
import java.io.OutputStream;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.bouncycastle.asn1.ASN1Encodable;
import org.bouncycastle.asn1.ASN1EncodableVector;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.asn1.BERSequenceGenerator;
import org.bouncycastle.asn1.BERTaggedObject;
import org.bouncycastle.asn1.DERSet;
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;

class CMSSignedDataStreamGenerator$CmsSignedDataOutputStream
  extends OutputStream
{
  private OutputStream _out;
  private ASN1ObjectIdentifier _contentOID;
  private BERSequenceGenerator _sGen;
  private BERSequenceGenerator _sigGen;
  private BERSequenceGenerator _eiGen;
  
  public CMSSignedDataStreamGenerator$CmsSignedDataOutputStream(CMSSignedDataStreamGenerator paramCMSSignedDataStreamGenerator, OutputStream paramOutputStream, ASN1ObjectIdentifier paramASN1ObjectIdentifier, BERSequenceGenerator paramBERSequenceGenerator1, BERSequenceGenerator paramBERSequenceGenerator2, BERSequenceGenerator paramBERSequenceGenerator3)
  {
    _out = paramOutputStream;
    _contentOID = paramASN1ObjectIdentifier;
    _sGen = paramBERSequenceGenerator1;
    _sigGen = paramBERSequenceGenerator2;
    _eiGen = paramBERSequenceGenerator3;
  }
  
  public void write(int paramInt)
    throws IOException
  {
    _out.write(paramInt);
  }
  
  public void write(byte[] paramArrayOfByte, int paramInt1, int paramInt2)
    throws IOException
  {
    _out.write(paramArrayOfByte, paramInt1, paramInt2);
  }
  
  public void write(byte[] paramArrayOfByte)
    throws IOException
  {
    _out.write(paramArrayOfByte);
  }
  
  public void close()
    throws IOException
  {
    _out.close();
    _eiGen.close();
    this$0.digests.clear();
    if (this$0.certs.size() != 0)
    {
      localObject1 = CMSUtils.createBerSetFromList(this$0.certs);
      _sigGen.getRawOutputStream().write(new BERTaggedObject(false, 0, (ASN1Encodable)localObject1).getEncoded());
    }
    if (this$0.crls.size() != 0)
    {
      localObject1 = CMSUtils.createBerSetFromList(this$0.crls);
      _sigGen.getRawOutputStream().write(new BERTaggedObject(false, 1, (ASN1Encodable)localObject1).getEncoded());
    }
    Object localObject1 = new ASN1EncodableVector();
    Iterator localIterator = this$0.signerGens.iterator();
    Object localObject2;
    while (localIterator.hasNext())
    {
      localObject2 = (SignerInfoGenerator)localIterator.next();
      try
      {
        ((ASN1EncodableVector)localObject1).add(((SignerInfoGenerator)localObject2).generate(_contentOID));
        byte[] arrayOfByte = ((SignerInfoGenerator)localObject2).getCalculatedDigest();
        this$0.digests.put(((SignerInfoGenerator)localObject2).getDigestAlgorithm().getAlgorithm().getId(), arrayOfByte);
      }
      catch (CMSException localCMSException)
      {
        throw new CMSStreamException("exception generating signers: " + localCMSException.getMessage(), localCMSException);
      }
    }
    localIterator = this$0._signers.iterator();
    while (localIterator.hasNext())
    {
      localObject2 = (SignerInformation)localIterator.next();
      ((ASN1EncodableVector)localObject1).add(((SignerInformation)localObject2).toASN1Structure());
    }
    _sigGen.getRawOutputStream().write(new DERSet((ASN1EncodableVector)localObject1).getEncoded());
    _sigGen.close();
    _sGen.close();
  }
}

/* Location:
 * Qualified Name:     org.bouncycastle.cms.CMSSignedDataStreamGenerator.CmsSignedDataOutputStream
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.bouncycastle.cms;

import java.io.IOException;
import java.io.OutputStream;
import java.math.BigInteger;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.PrivateKey;
import java.security.Provider;
import java.security.SecureRandom;
import java.security.cert.CertificateEncodingException;
import java.security.cert.X509Certificate;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.bouncycastle.asn1.ASN1Encodable;
import org.bouncycastle.asn1.ASN1EncodableVector;
import org.bouncycastle.asn1.ASN1Integer;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.asn1.ASN1TaggedObject;
import org.bouncycastle.asn1.BERSequenceGenerator;
import org.bouncycastle.asn1.BERTaggedObject;
import org.bouncycastle.asn1.DERInteger;
import org.bouncycastle.asn1.DERSet;
import org.bouncycastle.asn1.cms.AttributeTable;
import org.bouncycastle.asn1.cms.CMSObjectIdentifiers;
import org.bouncycastle.asn1.cms.SignerInfo;
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
import org.bouncycastle.cms.jcajce.JcaSignerInfoGeneratorBuilder;
import org.bouncycastle.operator.ContentSigner;
import org.bouncycastle.operator.OperatorCreationException;
import org.bouncycastle.operator.jcajce.JcaContentSignerBuilder;
import org.bouncycastle.operator.jcajce.JcaDigestCalculatorProviderBuilder;

public class CMSSignedDataStreamGenerator
  extends CMSSignedGenerator
{
  private int _bufferSize;
  
  public CMSSignedDataStreamGenerator() {}
  
  /**
   * @deprecated
   */
  public CMSSignedDataStreamGenerator(SecureRandom paramSecureRandom)
  {
    super(paramSecureRandom);
  }
  
  public void setBufferSize(int paramInt)
  {
    _bufferSize = paramInt;
  }
  
  /**
   * @deprecated
   */
  public void addSigner(PrivateKey paramPrivateKey, X509Certificate paramX509Certificate, String paramString1, String paramString2)
    throws NoSuchAlgorithmException, NoSuchProviderException, InvalidKeyException
  {
    addSigner(paramPrivateKey, paramX509Certificate, paramString1, CMSUtils.getProvider(paramString2));
  }
  
  /**
   * @deprecated
   */
  public void addSigner(PrivateKey paramPrivateKey, X509Certificate paramX509Certificate, String paramString, Provider paramProvider)
    throws NoSuchAlgorithmException, NoSuchProviderException, InvalidKeyException
  {
    addSigner(paramPrivateKey, paramX509Certificate, paramString, new DefaultSignedAttributeTableGenerator(), (CMSAttributeTableGenerator)null, paramProvider);
  }
  
  /**
   * @deprecated
   */
  public void addSigner(PrivateKey paramPrivateKey, X509Certificate paramX509Certificate, String paramString1, String paramString2, String paramString3)
    throws NoSuchAlgorithmException, NoSuchProviderException, InvalidKeyException
  {
    addSigner(paramPrivateKey, paramX509Certificate, paramString1, paramString2, CMSUtils.getProvider(paramString3));
  }
  
  /**
   * @deprecated
   */
  public void addSigner(PrivateKey paramPrivateKey, X509Certificate paramX509Certificate, String paramString1, String paramString2, Provider paramProvider)
    throws NoSuchAlgorithmException, NoSuchProviderException, InvalidKeyException
  {
    addSigner(paramPrivateKey, paramX509Certificate, paramString1, paramString2, new DefaultSignedAttributeTableGenerator(), (CMSAttributeTableGenerator)null, paramProvider);
  }
  
  /**
   * @deprecated
   */
  public void addSigner(PrivateKey paramPrivateKey, X509Certificate paramX509Certificate, String paramString1, AttributeTable paramAttributeTable1, AttributeTable paramAttributeTable2, String paramString2)
    throws NoSuchAlgorithmException, NoSuchProviderException, InvalidKeyException
  {
    addSigner(paramPrivateKey, paramX509Certificate, paramString1, paramAttributeTable1, paramAttributeTable2, CMSUtils.getProvider(paramString2));
  }
  
  /**
   * @deprecated
   */
  public void addSigner(PrivateKey paramPrivateKey, X509Certificate paramX509Certificate, String paramString, AttributeTable paramAttributeTable1, AttributeTable paramAttributeTable2, Provider paramProvider)
    throws NoSuchAlgorithmException, InvalidKeyException
  {
    addSigner(paramPrivateKey, paramX509Certificate, paramString, new DefaultSignedAttributeTableGenerator(paramAttributeTable1), new SimpleAttributeTableGenerator(paramAttributeTable2), paramProvider);
  }
  
  /**
   * @deprecated
   */
  public void addSigner(PrivateKey paramPrivateKey, X509Certificate paramX509Certificate, String paramString1, String paramString2, AttributeTable paramAttributeTable1, AttributeTable paramAttributeTable2, String paramString3)
    throws NoSuchAlgorithmException, NoSuchProviderException, InvalidKeyException
  {
    addSigner(paramPrivateKey, paramX509Certificate, paramString1, paramString2, paramAttributeTable1, paramAttributeTable2, CMSUtils.getProvider(paramString3));
  }
  
  /**
   * @deprecated
   */
  public void addSigner(PrivateKey paramPrivateKey, X509Certificate paramX509Certificate, String paramString1, String paramString2, AttributeTable paramAttributeTable1, AttributeTable paramAttributeTable2, Provider paramProvider)
    throws NoSuchAlgorithmException, InvalidKeyException
  {
    addSigner(paramPrivateKey, paramX509Certificate, paramString1, paramString2, new DefaultSignedAttributeTableGenerator(paramAttributeTable1), new SimpleAttributeTableGenerator(paramAttributeTable2), paramProvider);
  }
  
  /**
   * @deprecated
   */
  public void addSigner(PrivateKey paramPrivateKey, X509Certificate paramX509Certificate, String paramString1, CMSAttributeTableGenerator paramCMSAttributeTableGenerator1, CMSAttributeTableGenerator paramCMSAttributeTableGenerator2, String paramString2)
    throws NoSuchAlgorithmException, NoSuchProviderException, InvalidKeyException
  {
    addSigner(paramPrivateKey, paramX509Certificate, paramString1, paramCMSAttributeTableGenerator1, paramCMSAttributeTableGenerator2, CMSUtils.getProvider(paramString2));
  }
  
  /**
   * @deprecated
   */
  public void addSigner(PrivateKey paramPrivateKey, X509Certificate paramX509Certificate, String paramString, CMSAttributeTableGenerator paramCMSAttributeTableGenerator1, CMSAttributeTableGenerator paramCMSAttributeTableGenerator2, Provider paramProvider)
    throws NoSuchAlgorithmException, InvalidKeyException
  {
    addSigner(paramPrivateKey, paramX509Certificate, getEncOID(paramPrivateKey, paramString), paramString, paramCMSAttributeTableGenerator1, paramCMSAttributeTableGenerator2, paramProvider);
  }
  
  /**
   * @deprecated
   */
  public void addSigner(PrivateKey paramPrivateKey, X509Certificate paramX509Certificate, String paramString1, String paramString2, CMSAttributeTableGenerator paramCMSAttributeTableGenerator1, CMSAttributeTableGenerator paramCMSAttributeTableGenerator2, String paramString3)
    throws NoSuchAlgorithmException, NoSuchProviderException, InvalidKeyException
  {
    addSigner(paramPrivateKey, paramX509Certificate, paramString1, paramString2, paramCMSAttributeTableGenerator1, paramCMSAttributeTableGenerator2, CMSUtils.getProvider(paramString3));
  }
  
  /**
   * @deprecated
   */
  public void addSigner(PrivateKey paramPrivateKey, X509Certificate paramX509Certificate, String paramString1, String paramString2, CMSAttributeTableGenerator paramCMSAttributeTableGenerator1, CMSAttributeTableGenerator paramCMSAttributeTableGenerator2, Provider paramProvider)
    throws NoSuchAlgorithmException, InvalidKeyException
  {
    addSigner(paramPrivateKey, paramX509Certificate, paramString1, paramString2, paramCMSAttributeTableGenerator1, paramCMSAttributeTableGenerator2, paramProvider, paramProvider);
  }
  
  /**
   * @deprecated
   */
  public void addSigner(PrivateKey paramPrivateKey, byte[] paramArrayOfByte, String paramString1, String paramString2)
    throws NoSuchAlgorithmException, NoSuchProviderException, InvalidKeyException
  {
    addSigner(paramPrivateKey, paramArrayOfByte, paramString1, CMSUtils.getProvider(paramString2));
  }
  
  /**
   * @deprecated
   */
  public void addSigner(PrivateKey paramPrivateKey, byte[] paramArrayOfByte, String paramString, Provider paramProvider)
    throws NoSuchAlgorithmException, NoSuchProviderException, InvalidKeyException
  {
    addSigner(paramPrivateKey, paramArrayOfByte, paramString, new DefaultSignedAttributeTableGenerator(), (CMSAttributeTableGenerator)null, paramProvider);
  }
  
  /**
   * @deprecated
   */
  public void addSigner(PrivateKey paramPrivateKey, byte[] paramArrayOfByte, String paramString1, String paramString2, String paramString3)
    throws NoSuchAlgorithmException, NoSuchProviderException, InvalidKeyException
  {
    addSigner(paramPrivateKey, paramArrayOfByte, paramString1, paramString2, CMSUtils.getProvider(paramString3));
  }
  
  /**
   * @deprecated
   */
  public void addSigner(PrivateKey paramPrivateKey, byte[] paramArrayOfByte, String paramString1, String paramString2, Provider paramProvider)
    throws NoSuchAlgorithmException, NoSuchProviderException, InvalidKeyException
  {
    addSigner(paramPrivateKey, paramArrayOfByte, paramString1, paramString2, new DefaultSignedAttributeTableGenerator(), (CMSAttributeTableGenerator)null, paramProvider);
  }
  
  /**
   * @deprecated
   */
  public void addSigner(PrivateKey paramPrivateKey, byte[] paramArrayOfByte, String paramString1, AttributeTable paramAttributeTable1, AttributeTable paramAttributeTable2, String paramString2)
    throws NoSuchAlgorithmException, NoSuchProviderException, InvalidKeyException
  {
    addSigner(paramPrivateKey, paramArrayOfByte, paramString1, paramAttributeTable1, paramAttributeTable2, CMSUtils.getProvider(paramString2));
  }
  
  /**
   * @deprecated
   */
  public void addSigner(PrivateKey paramPrivateKey, byte[] paramArrayOfByte, String paramString, AttributeTable paramAttributeTable1, AttributeTable paramAttributeTable2, Provider paramProvider)
    throws NoSuchAlgorithmException, InvalidKeyException
  {
    addSigner(paramPrivateKey, paramArrayOfByte, paramString, new DefaultSignedAttributeTableGenerator(paramAttributeTable1), new SimpleAttributeTableGenerator(paramAttributeTable2), paramProvider);
  }
  
  /**
   * @deprecated
   */
  public void addSigner(PrivateKey paramPrivateKey, byte[] paramArrayOfByte, String paramString1, CMSAttributeTableGenerator paramCMSAttributeTableGenerator1, CMSAttributeTableGenerator paramCMSAttributeTableGenerator2, String paramString2)
    throws NoSuchAlgorithmException, NoSuchProviderException, InvalidKeyException
  {
    addSigner(paramPrivateKey, paramArrayOfByte, paramString1, paramCMSAttributeTableGenerator1, paramCMSAttributeTableGenerator2, CMSUtils.getProvider(paramString2));
  }
  
  /**
   * @deprecated
   */
  public void addSigner(PrivateKey paramPrivateKey, byte[] paramArrayOfByte, String paramString, CMSAttributeTableGenerator paramCMSAttributeTableGenerator1, CMSAttributeTableGenerator paramCMSAttributeTableGenerator2, Provider paramProvider)
    throws NoSuchAlgorithmException, InvalidKeyException
  {
    addSigner(paramPrivateKey, paramArrayOfByte, getEncOID(paramPrivateKey, paramString), paramString, paramCMSAttributeTableGenerator1, paramCMSAttributeTableGenerator2, paramProvider);
  }
  
  /**
   * @deprecated
   */
  public void addSigner(PrivateKey paramPrivateKey, byte[] paramArrayOfByte, String paramString1, String paramString2, CMSAttributeTableGenerator paramCMSAttributeTableGenerator1, CMSAttributeTableGenerator paramCMSAttributeTableGenerator2, String paramString3)
    throws NoSuchAlgorithmException, NoSuchProviderException, InvalidKeyException
  {
    addSigner(paramPrivateKey, paramArrayOfByte, paramString1, paramString2, paramCMSAttributeTableGenerator1, paramCMSAttributeTableGenerator2, CMSUtils.getProvider(paramString3));
  }
  
  /**
   * @deprecated
   */
  public void addSigner(PrivateKey paramPrivateKey, byte[] paramArrayOfByte, String paramString1, String paramString2, CMSAttributeTableGenerator paramCMSAttributeTableGenerator1, CMSAttributeTableGenerator paramCMSAttributeTableGenerator2, Provider paramProvider)
    throws NoSuchAlgorithmException, InvalidKeyException
  {
    addSigner(paramPrivateKey, paramArrayOfByte, paramString1, paramString2, paramCMSAttributeTableGenerator1, paramCMSAttributeTableGenerator2, paramProvider, paramProvider);
  }
  
  /**
   * @deprecated
   */
  public void addSigner(PrivateKey paramPrivateKey, X509Certificate paramX509Certificate, String paramString1, String paramString2, CMSAttributeTableGenerator paramCMSAttributeTableGenerator1, CMSAttributeTableGenerator paramCMSAttributeTableGenerator2, Provider paramProvider1, Provider paramProvider2)
    throws NoSuchAlgorithmException, InvalidKeyException
  {
    doAddSigner(paramPrivateKey, paramX509Certificate, paramString1, paramString2, paramCMSAttributeTableGenerator1, paramCMSAttributeTableGenerator2, paramProvider1, paramProvider2);
  }
  
  private void doAddSigner(PrivateKey paramPrivateKey, Object paramObject, String paramString1, String paramString2, CMSAttributeTableGenerator paramCMSAttributeTableGenerator1, CMSAttributeTableGenerator paramCMSAttributeTableGenerator2, Provider paramProvider1, Provider paramProvider2)
    throws NoSuchAlgorithmException, InvalidKeyException
  {
    String str1 = CMSSignedHelper.INSTANCE.getDigestAlgName(paramString2);
    String str2 = str1 + "with" + CMSSignedHelper.INSTANCE.getEncryptionAlgName(paramString1);
    JcaContentSignerBuilder localJcaContentSignerBuilder;
    try
    {
      localJcaContentSignerBuilder = new JcaContentSignerBuilder(str2).setSecureRandom(rand);
    }
    catch (IllegalArgumentException localIllegalArgumentException)
    {
      throw new NoSuchAlgorithmException(localIllegalArgumentException.getMessage());
    }
    if (paramProvider1 != null) {
      localJcaContentSignerBuilder.setProvider(paramProvider1);
    }
    try
    {
      JcaDigestCalculatorProviderBuilder localJcaDigestCalculatorProviderBuilder = new JcaDigestCalculatorProviderBuilder();
      if ((paramProvider2 != null) && (!paramProvider2.getName().equalsIgnoreCase("SunRsaSign"))) {
        localJcaDigestCalculatorProviderBuilder.setProvider(paramProvider2);
      }
      JcaSignerInfoGeneratorBuilder localJcaSignerInfoGeneratorBuilder = new JcaSignerInfoGeneratorBuilder(localJcaDigestCalculatorProviderBuilder.build());
      localJcaSignerInfoGeneratorBuilder.setSignedAttributeGenerator(paramCMSAttributeTableGenerator1);
      localJcaSignerInfoGeneratorBuilder.setUnsignedAttributeGenerator(paramCMSAttributeTableGenerator2);
      try
      {
        ContentSigner localContentSigner = localJcaContentSignerBuilder.build(paramPrivateKey);
        if ((paramObject instanceof X509Certificate)) {
          addSignerInfoGenerator(localJcaSignerInfoGeneratorBuilder.build(localContentSigner, (X509Certificate)paramObject));
        } else {
          addSignerInfoGenerator(localJcaSignerInfoGeneratorBuilder.build(localContentSigner, (byte[])paramObject));
        }
      }
      catch (OperatorCreationException localOperatorCreationException2)
      {
        if ((localOperatorCreationException2.getCause() instanceof NoSuchAlgorithmException)) {
          throw ((NoSuchAlgorithmException)localOperatorCreationException2.getCause());
        }
        if ((localOperatorCreationException2.getCause() instanceof InvalidKeyException)) {
          throw ((InvalidKeyException)localOperatorCreationException2.getCause());
        }
      }
    }
    catch (OperatorCreationException localOperatorCreationException1)
    {
      throw new NoSuchAlgorithmException("unable to create operators: " + localOperatorCreationException1.getMessage());
    }
    catch (CertificateEncodingException localCertificateEncodingException)
    {
      throw new IllegalStateException("unable to encode certificate");
    }
  }
  
  /**
   * @deprecated
   */
  public void addSigner(PrivateKey paramPrivateKey, byte[] paramArrayOfByte, String paramString1, String paramString2, CMSAttributeTableGenerator paramCMSAttributeTableGenerator1, CMSAttributeTableGenerator paramCMSAttributeTableGenerator2, Provider paramProvider1, Provider paramProvider2)
    throws NoSuchAlgorithmException, InvalidKeyException
  {
    doAddSigner(paramPrivateKey, paramArrayOfByte, paramString1, paramString2, paramCMSAttributeTableGenerator1, paramCMSAttributeTableGenerator2, paramPr
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd