bcpkix-jdk15on-147

.jcajce.JceCMSMacCalculatorBuilder;
import org.bouncycastle.operator.DigestCalculator;
import org.bouncycastle.operator.DigestCalculatorProvider;
import org.bouncycastle.operator.MacCalculator;
import org.bouncycastle.operator.OperatorCreationException;
import org.bouncycastle.util.io.TeeOutputStream;

public class CMSAuthenticatedDataGenerator
  extends CMSAuthenticatedGenerator
{
  public CMSAuthenticatedDataGenerator() {}
  
  public CMSAuthenticatedData generate(CMSTypedData paramCMSTypedData, MacCalculator paramMacCalculator)
    throws CMSException
  {
    return generate(paramCMSTypedData, paramMacCalculator, null);
  }
  
  public CMSAuthenticatedData generate(CMSTypedData paramCMSTypedData, MacCalculator paramMacCalculator, final DigestCalculator paramDigestCalculator)
    throws CMSException
  {
    ASN1EncodableVector localASN1EncodableVector = new ASN1EncodableVector();
    Object localObject1 = recipientInfoGenerators.iterator();
    Object localObject2;
    while (((Iterator)localObject1).hasNext())
    {
      localObject2 = (RecipientInfoGenerator)((Iterator)localObject1).next();
      localASN1EncodableVector.add(((RecipientInfoGenerator)localObject2).generate(paramMacCalculator.getKey()));
    }
    Object localObject5;
    BEROctetString localBEROctetString;
    Object localObject3;
    DEROctetString localDEROctetString;
    if (paramDigestCalculator != null)
    {
      try
      {
        localObject2 = new ByteArrayOutputStream();
        localObject5 = new TeeOutputStream(paramDigestCalculator.getOutputStream(), (OutputStream)localObject2);
        paramCMSTypedData.write((OutputStream)localObject5);
        ((OutputStream)localObject5).close();
        localBEROctetString = new BEROctetString(((ByteArrayOutputStream)localObject2).toByteArray());
      }
      catch (IOException localIOException1)
      {
        throw new CMSException("unable to perform digest calculation: " + localIOException1.getMessage(), localIOException1);
      }
      localObject3 = getBaseParameters(paramCMSTypedData.getContentType(), paramDigestCalculator.getAlgorithmIdentifier(), paramDigestCalculator.getDigest());
      if (authGen == null) {
        authGen = new DefaultAuthenticatedAttributeTableGenerator();
      }
      localObject5 = new DERSet(authGen.getAttributes(Collections.unmodifiableMap((Map)localObject3)).toASN1EncodableVector());
      try
      {
        OutputStream localOutputStream = paramMacCalculator.getOutputStream();
        localOutputStream.write(((ASN1Set)localObject5).getEncoded("DER"));
        localOutputStream.close();
        localDEROctetString = new DEROctetString(paramMacCalculator.getMac());
      }
      catch (IOException localIOException3)
      {
        throw new CMSException("exception decoding algorithm parameters.", localIOException3);
      }
      ASN1Set localASN1Set = unauthGen != null ? new BERSet(unauthGen.getAttributes(Collections.unmodifiableMap((Map)localObject3)).toASN1EncodableVector()) : null;
      ContentInfo localContentInfo = new ContentInfo(CMSObjectIdentifiers.data, localBEROctetString);
      localObject1 = new AuthenticatedData(originatorInfo, new DERSet(localASN1EncodableVector), paramMacCalculator.getAlgorithmIdentifier(), paramDigestCalculator.getAlgorithmIdentifier(), localContentInfo, (ASN1Set)localObject5, localDEROctetString, localASN1Set);
    }
    else
    {
      try
      {
        localObject3 = new ByteArrayOutputStream();
        localObject5 = new TeeOutputStream((OutputStream)localObject3, paramMacCalculator.getOutputStream());
        paramCMSTypedData.write((OutputStream)localObject5);
        ((OutputStream)localObject5).close();
        localBEROctetString = new BEROctetString(((ByteArrayOutputStream)localObject3).toByteArray());
        localDEROctetString = new DEROctetString(paramMacCalculator.getMac());
      }
      catch (IOException localIOException2)
      {
        throw new CMSException("exception decoding algorithm parameters.", localIOException2);
      }
      localObject4 = unauthGen != null ? new BERSet(unauthGen.getAttributes(new HashMap()).toASN1EncodableVector()) : null;
      localObject5 = new ContentInfo(CMSObjectIdentifiers.data, localBEROctetString);
      localObject1 = new AuthenticatedData(originatorInfo, new DERSet(localASN1EncodableVector), paramMacCalculator.getAlgorithmIdentifier(), null, (ContentInfo)localObject5, null, localDEROctetString, (ASN1Set)localObject4);
    }
    Object localObject4 = new ContentInfo(CMSObjectIdentifiers.authenticatedData, (ASN1Encodable)localObject1);
    new CMSAuthenticatedData((ContentInfo)localObject4, new DigestCalculatorProvider()
    {
      public DigestCalculator get(AlgorithmIdentifier paramAnonymousAlgorithmIdentifier)
        throws OperatorCreationException
      {
        return paramDigestCalculator;
      }
    });
  }
  
  /**
   * @deprecated
   */
  public CMSAuthenticatedDataGenerator(SecureRandom paramSecureRandom)
  {
    super(paramSecureRandom);
  }
  
  /**
   * @deprecated
   */
  private CMSAuthenticatedData generate(final CMSProcessable paramCMSProcessable, String paramString, KeyGenerator paramKeyGenerator, Provider paramProvider)
    throws NoSuchAlgorithmException, CMSException
  {
    Provider localProvider = paramKeyGenerator.getProvider();
    convertOldRecipients(rand, paramProvider);
    generate(new CMSTypedData()new JceCMSMacCalculatorBuildernew ASN1ObjectIdentifier
    {
      public ASN1ObjectIdentifier getContentType()
      {
        return CMSObjectIdentifiers.data;
      }
      
      public void write(OutputStream paramAnonymousOutputStream)
        throws IOException, CMSException
      {
        paramCMSProcessable.write(paramAnonymousOutputStream);
      }
      
      public Object getContent()
      {
        return paramCMSProcessable;
      }
    }, new JceCMSMacCalculatorBuilder(new ASN1ObjectIdentifier(paramString)).setProvider(localProvider).setSecureRandom(rand).build());
  }
  
  /**
   * @deprecated
   */
  public CMSAuthenticatedData generate(CMSProcessable paramCMSProcessable, String paramString1, String paramString2)
    throws NoSuchAlgorithmException, NoSuchProviderException, CMSException
  {
    return generate(paramCMSProcessable, paramString1, CMSUtils.getProvider(paramString2));
  }
  
  /**
   * @deprecated
   */
  public CMSAuthenticatedData generate(CMSProcessable paramCMSProcessable, String paramString, Provider paramProvider)
    throws NoSuchAlgorithmException, CMSException
  {
    KeyGenerator localKeyGenerator = CMSEnvelopedHelper.INSTANCE.createSymmetricKeyGenerator(paramString, paramProvider);
    return generate(paramCMSProcessable, paramString, localKeyGenerator, paramProvider);
  }
}

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

import java.io.IOException;
import org.bouncycastle.asn1.ASN1Set;

class CMSAuthenticatedDataParser$1
  implements AuthAttributesProvider
{
  CMSAuthenticatedDataParser$1(CMSAuthenticatedDataParser paramCMSAuthenticatedDataParser) {}
  
  public ASN1Set getAuthAttributes()
  {
    try
    {
      return CMSAuthenticatedDataParser.access$000(this$0);
    }
    catch (IOException localIOException)
    {
      throw new IllegalStateException("can't parse authenticated attributes!");
    }
  }
}

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

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.security.AlgorithmParameters;
import java.security.NoSuchProviderException;
import java.security.Provider;
import org.bouncycastle.asn1.ASN1Encodable;
import org.bouncycastle.asn1.ASN1EncodableVector;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.asn1.ASN1OctetString;
import org.bouncycastle.asn1.ASN1OctetStringParser;
import org.bouncycastle.asn1.ASN1Primitive;
import org.bouncycastle.asn1.ASN1SequenceParser;
import org.bouncycastle.asn1.ASN1Set;
import org.bouncycastle.asn1.ASN1SetParser;
import org.bouncycastle.asn1.DERSet;
import org.bouncycastle.asn1.cms.Attribute;
import org.bouncycastle.asn1.cms.AttributeTable;
import org.bouncycastle.asn1.cms.AuthenticatedDataParser;
import org.bouncycastle.asn1.cms.CMSAttributes;
import org.bouncycastle.asn1.cms.ContentInfoParser;
import org.bouncycastle.asn1.cms.OriginatorInfo;
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
import org.bouncycastle.cms.jcajce.JceAlgorithmIdentifierConverter;
import org.bouncycastle.operator.DigestCalculatorProvider;
import org.bouncycastle.operator.OperatorCreationException;
import org.bouncycastle.util.Arrays;

public class CMSAuthenticatedDataParser
  extends CMSContentInfoParser
{
  RecipientInformationStore recipientInfoStore;
  AuthenticatedDataParser authData = new AuthenticatedDataParser((ASN1SequenceParser)_contentInfo.getContent(16));
  private AlgorithmIdentifier macAlg;
  private byte[] mac;
  private AttributeTable authAttrs;
  private ASN1Set authAttrSet;
  private AttributeTable unauthAttrs;
  private boolean authAttrNotRead = true;
  private boolean unauthAttrNotRead;
  private OriginatorInformation originatorInfo;
  
  public CMSAuthenticatedDataParser(byte[] paramArrayOfByte)
    throws CMSException, IOException
  {
    this(new ByteArrayInputStream(paramArrayOfByte));
  }
  
  public CMSAuthenticatedDataParser(byte[] paramArrayOfByte, DigestCalculatorProvider paramDigestCalculatorProvider)
    throws CMSException, IOException
  {
    this(new ByteArrayInputStream(paramArrayOfByte), paramDigestCalculatorProvider);
  }
  
  public CMSAuthenticatedDataParser(InputStream paramInputStream)
    throws CMSException, IOException
  {
    this(paramInputStream, null);
  }
  
  public CMSAuthenticatedDataParser(InputStream paramInputStream, DigestCalculatorProvider paramDigestCalculatorProvider)
    throws CMSException, IOException
  {
    super(paramInputStream);
    OriginatorInfo localOriginatorInfo = authData.getOriginatorInfo();
    if (localOriginatorInfo != null) {
      originatorInfo = new OriginatorInformation(localOriginatorInfo);
    }
    ASN1Set localASN1Set = ASN1Set.getInstance(authData.getRecipientInfos().toASN1Primitive());
    macAlg = authData.getMacAlgorithm();
    AlgorithmIdentifier localAlgorithmIdentifier = authData.getDigestAlgorithm();
    ContentInfoParser localContentInfoParser;
    CMSProcessableInputStream localCMSProcessableInputStream;
    if (localAlgorithmIdentifier != null)
    {
      if (paramDigestCalculatorProvider == null) {
        throw new CMSException("a digest calculator provider is required if authenticated attributes are present");
      }
      localContentInfoParser = authData.getEnapsulatedContentInfo();
      localCMSProcessableInputStream = new CMSProcessableInputStream(((ASN1OctetStringParser)localContentInfoParser.getContent(4)).getOctetStream());
      try
      {
        CMSEnvelopedHelper.CMSDigestAuthenticatedSecureReadable localCMSDigestAuthenticatedSecureReadable = new CMSEnvelopedHelper.CMSDigestAuthenticatedSecureReadable(paramDigestCalculatorProvider.get(localAlgorithmIdentifier), localCMSProcessableInputStream);
        recipientInfoStore = CMSEnvelopedHelper.buildRecipientInformationStore(localASN1Set, macAlg, localCMSDigestAuthenticatedSecureReadable, new AuthAttributesProvider()
        {
          public ASN1Set getAuthAttributes()
          {
            try
            {
              return CMSAuthenticatedDataParser.this.getAuthAttrSet();
            }
            catch (IOException localIOException)
            {
              throw new IllegalStateException("can't parse authenticated attributes!");
            }
          }
        });
      }
      catch (OperatorCreationException localOperatorCreationException)
      {
        throw new CMSException("unable to create digest calculator: " + localOperatorCreationException.getMessage(), localOperatorCreationException);
      }
    }
    else
    {
      localContentInfoParser = authData.getEnapsulatedContentInfo();
      localCMSProcessableInputStream = new CMSProcessableInputStream(((ASN1OctetStringParser)localContentInfoParser.getContent(4)).getOctetStream());
      CMSEnvelopedHelper.CMSAuthenticatedSecureReadable localCMSAuthenticatedSecureReadable = new CMSEnvelopedHelper.CMSAuthenticatedSecureReadable(macAlg, localCMSProcessableInputStream);
      recipientInfoStore = CMSEnvelopedHelper.buildRecipientInformationStore(localASN1Set, macAlg, localCMSAuthenticatedSecureReadable);
    }
  }
  
  public OriginatorInformation getOriginatorInfo()
  {
    return originatorInfo;
  }
  
  public AlgorithmIdentifier getMacAlgorithm()
  {
    return macAlg;
  }
  
  public String getMacAlgOID()
  {
    return macAlg.getAlgorithm().toString();
  }
  
  public byte[] getMacAlgParams()
  {
    try
    {
      return encodeObj(macAlg.getParameters());
    }
    catch (Exception localException)
    {
      throw new RuntimeException("exception getting encryption parameters " + localException);
    }
  }
  
  /**
   * @deprecated
   */
  public AlgorithmParameters getMacAlgorithmParameters(String paramString)
    throws CMSException, NoSuchProviderException
  {
    return new JceAlgorithmIdentifierConverter().setProvider(paramString).getAlgorithmParameters(macAlg);
  }
  
  /**
   * @deprecated
   */
  public AlgorithmParameters getMacAlgorithmParameters(Provider paramProvider)
    throws CMSException
  {
    return new JceAlgorithmIdentifierConverter().setProvider(paramProvider).getAlgorithmParameters(macAlg);
  }
  
  public RecipientInformationStore getRecipientInfos()
  {
    return recipientInfoStore;
  }
  
  public byte[] getMac()
    throws IOException
  {
    if (mac == null)
    {
      getAuthAttrs();
      mac = authData.getMac().getOctets();
    }
    return Arrays.clone(mac);
  }
  
  private ASN1Set getAuthAttrSet()
    throws IOException
  {
    if ((authAttrs == null) && (authAttrNotRead))
    {
      ASN1SetParser localASN1SetParser = authData.getAuthAttrs();
      if (localASN1SetParser != null) {
        authAttrSet = ((ASN1Set)localASN1SetParser.toASN1Primitive());
      }
      authAttrNotRead = false;
    }
    return authAttrSet;
  }
  
  public AttributeTable getAuthAttrs()
    throws IOException
  {
    if ((authAttrs == null) && (authAttrNotRead))
    {
      ASN1Set localASN1Set = getAuthAttrSet();
      if (localASN1Set != null) {
        authAttrs = new AttributeTable(localASN1Set);
      }
    }
    return authAttrs;
  }
  
  public AttributeTable getUnauthAttrs()
    throws IOException
  {
    if ((unauthAttrs == null) && (unauthAttrNotRead))
    {
      ASN1SetParser localASN1SetParser = authData.getUnauthAttrs();
      unauthAttrNotRead = false;
      if (localASN1SetParser != null)
      {
        ASN1EncodableVector localASN1EncodableVector = new ASN1EncodableVector();
        ASN1Encodable localASN1Encodable;
        while ((localASN1Encodable = localASN1SetParser.readObject()) != null)
        {
          ASN1SequenceParser localASN1SequenceParser = (ASN1SequenceParser)localASN1Encodable;
          localASN1EncodableVector.add(localASN1SequenceParser.toASN1Primitive());
        }
        unauthAttrs = new AttributeTable(new DERSet(localASN1EncodableVector));
      }
    }
    return unauthAttrs;
  }
  
  private byte[] encodeObj(ASN1Encodable paramASN1Encodable)
    throws IOException
  {
    if (paramASN1Encodable != null) {
      return paramASN1Encodable.toASN1Primitive().getEncoded();
    }
    return null;
  }
  
  public byte[] getContentDigest()
  {
    if (authAttrs != null) {
      return ASN1OctetString.getInstance(authAttrs.get(CMSAttributes.messageDigest).getAttrValues().getObjectAt(0)).getOctets();
    }
    return null;
  }
}

/* Location:
 * Qualified Name:     org.bouncycastle.cms.CMSAuthenticatedDataParser
 * 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.Collections;
import java.util.HashMap;
import java.util.Map;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.asn1.ASN1Set;
import org.bouncycastle.asn1.BERSequenceGenerator;
import org.bouncycastle.asn1.BERSet;
import org.bouncycastle.asn1.DEROctetString;
import org.bouncycastle.asn1.DERSet;
import org.bouncycastle.asn1.DERTaggedObject;
import org.bouncycastle.asn1.cms.AttributeTable;
import org.bouncycastle.operator.DigestCalculator;
import org.bouncycastle.operator.MacCalculator;

class CMSAuthenticatedDataStreamGenerator$CmsAuthenticatedDataOutputStream
  extends OutputStream
{
  private OutputStream dataStream;
  private BERSequenceGenerator cGen;
  private BERSequenceGenerator envGen;
  private BERSequenceGenerator eiGen;
  private MacCalculator macCalculator;
  private DigestCalculator digestCalculator;
  private ASN1ObjectIdentifier contentType;
  
  public CMSAuthenticatedDataStreamGenerator$CmsAuthenticatedDataOutputStream(CMSAuthenticatedDataStreamGenerator paramCMSAuthenticatedDataStreamGenerator, MacCalculator paramMacCalculator, DigestCalculator paramDigestCalculator, ASN1ObjectIdentifier paramASN1ObjectIdentifier, OutputStream paramOutputStream, BERSequenceGenerator paramBERSequenceGenerator1, BERSequenceGenerator paramBERSequenceGenerator2, BERSequenceGenerator paramBERSequenceGenerator3)
  {
    macCalculator = paramMacCalculator;
    digestCalculator = paramDigestCalculator;
    contentType = paramASN1ObjectIdentifier;
    dataStream = paramOutputStream;
    cGen = paramBERSequenceGenerator1;
    envGen = paramBERSequenceGenerator2;
    eiGen = paramBERSequenceGenerator3;
  }
  
  public void write(int paramInt)
    throws IOException
  {
    dataStream.write(paramInt);
  }
  
  public void write(byte[] paramArrayOfByte, int paramInt1, int paramInt2)
    throws IOException
  {
    dataStream.write(paramArrayOfByte, paramInt1, paramInt2);
  }
  
  public void write(byte[] paramArrayOfByte)
    throws IOException
  {
    dataStream.write(paramArrayOfByte);
  }
  
  public void close()
    throws IOException
  {
    dataStream.close();
    eiGen.close();
    Map localMap;
    if (digestCalculator != null)
    {
      localMap = Collections.unmodifiableMap(this$0.getBaseParameters(contentType, digestCalculator.getAlgorithmIdentifier(), digestCalculator.getDigest()));
      if (this$0.authGen == null) {
        this$0.authGen = new DefaultAuthenticatedAttributeTableGenerator();
      }
      DERSet localDERSet = new DERSet(this$0.authGen.getAttributes(localMap).toASN1EncodableVector());
      OutputStream localOutputStream = macCalculator.getOutputStream();
      localOutputStream.write(localDERSet.getEncoded("DER"));
      localOutputStream.close();
      envGen.addObject(new DERTaggedObject(false, 2, localDERSet));
    }
    else
    {
      localMap = Collections.unmodifiableMap(new HashMap());
    }
    envGen.addObject(new DEROctetString(macCalculator.getMac()));
    if (this$0.unauthGen != null) {
      envGen.addObject(new DERTaggedObject(false, 3, new BERSet(this$0.unauthGen.getAttributes(localMap).toASN1EncodableVector())));
    }
    envGen.close();
    cGen.close();
  }
}

/* Location:
 * Qualified Name:     org.bouncycastle.cms.CMSAuthenticatedDataStreamGenerator.CmsAuthenticatedDataOutputStream
 * 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.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.Provider;
import java.security.SecureRandom;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.bouncycastle.asn1.ASN1EncodableVector;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.asn1.ASN1Set;
import org.bouncycastle.asn1.BERSequenceGenerator;
import org.bouncycastle.asn1.BERSet;
import org.bouncycastle.asn1.DERInteger;
import org.bouncycastle.asn1.DEROctetString;
import org.bouncycastle.asn1.DERSet;
import org.bouncycastle.asn1.DERTaggedObject;
import org.bouncycastle.asn1.cms.AttributeTable;
import org.bouncycastle.asn1.cms.AuthenticatedData;
import org.bouncycastle.asn1.cms.CMSObjectIdentifiers;
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
import org.bouncycastle.cms.jcajce.JceCMSMacCalculatorBuilder;
import org.bouncycastle.operator.DigestCalculator;
import org.bouncycastle.operator.MacCalculator;
import org.bouncycastle.util.io.TeeOutputStream;

public class CMSAuthenticatedDataStreamGenerator
  extends CMSAuthenticatedGenerator
{
  private int bufferSize;
  private boolean berEncodeRecipientSet;
  private MacCalculator macCalculator;
  
  public CMSAuthenticatedDataStreamGenerator() {}
  
  public void setBufferSize(int paramInt)
  {
    bufferSize = paramInt;
  }
  
  public void setBEREncodeRecipients(boolean paramBoolean)
  {
    berEncodeRecipientSet = paramBoolean;
  }
  
  public OutputStream open(OutputStream paramOutputStream, MacCalculator paramMacCalculator)
    throws CMSException
  {
    return open(CMSObjectIdentifiers.data, paramOutputStream, paramMacCalculator);
  }
  
  public OutputStream open(OutputStream paramOutputStream, MacCalculator paramMacCalculator, DigestCalculator paramDigestCalculator)
    throws CMSException
  {
    return open(CMSObjectIdentifiers.data, paramOutputStream, paramMacCalculator, paramDigestCalculator);
  }
  
  public OutputStream open(ASN1ObjectIdentifier paramASN1ObjectIdentifier, OutputStream paramOutputStream, MacCalculator paramMacCalculator)
    throws CMSException
  {
    return open(paramASN1ObjectIdentifier, paramOutputStream, paramMacCalculator, null);
  }
  
  public OutputStream open(ASN1ObjectIdentifier paramASN1ObjectIdentifier, OutputStream paramOutputStream, MacCalculator paramMacCalculator, DigestCalculator paramDigestCalculator)
    throws CMSException
  {
    macCalculator = paramMacCalculator;
    try
    {
      ASN1EncodableVector localASN1EncodableVector = new ASN1EncodableVector();
      Object localObject1 = recipientInfoGenerators.iterator();
      while (((Iterator)localObject1).hasNext())
      {
        localObject2 = (RecipientInfoGenerator)((Iterator)localObject1).next();
        localASN1EncodableVector.add(((RecipientInfoGenerator)localObject2).generate(paramMacCalculator.getKey()));
      }
      localObject1 = new BERSequenceGenerator(paramOutputStream);
      ((BERSequenceGenerator)localObject1).addObject(CMSObjectIdentifiers.authenticatedData);
      Object localObject2 = new BERSequenceGenerator(((BERSequenceGenerator)localObject1).getRawOutputStream(), 0, true);
      ((BERSequenceGenerator)localObject2).addObject(new DERInteger(AuthenticatedData.calculateVersion(originatorInfo)));
      if (originatorInfo != null) {
        ((BERSequenceGenerator)localObject2).addObject(new DERTaggedObject(false, 0, originatorInfo));
      }
      if (berEncodeRecipientSet) {
        ((BERSequenceGenerator)localObject2).getRawOutputStream().write(new BERSet(localASN1EncodableVector).getEncoded());
      } else {
        ((BERSequenceGenerator)localObject2).getRawOutputStream().write(new DERSet(localASN1EncodableVector).getEncoded());
      }
      AlgorithmIdentifier localAlgorithmIdentifier = paramMacCalculator.getAlgorithmIdentifier();
      ((BERSequenceGenerator)localObject2).getRawOutputStream().write(localAlgorithmIdentifier.getEncoded());
      if (paramDigestCalculator != null) {
        ((BERSequenceGenerator)localObject2).addObject(new DERTaggedObject(false, 1, paramDigestCalculator.getAlgorithmIdentifier()));
      }
      BERSequenceGenerator localBERSequenceGenerator = new BERSequenceGenerator(((BERSequenceGenerator)localObject2).getRawOutputStream());
      localBERSequenceGenerator.addObject(paramASN1ObjectIdentifier);
      OutputStream localOutputStream = CMSUtils.createBEROctetOutputStream(localBERSequenceGenerator.getRawOutputStream(), 0, false, bufferSize);
      TeeOutputStream localTeeOutputStream;
      if (paramDigestCalculator != null) {
        localTeeOutputStream = new TeeOutputStream(localOutputStream, paramDigestCalculator.getOutputStream());
      } else {
        localTeeOutputStream = new TeeOutputStream(localOutputStream, paramMacCalculator.getOutputStream());
      }
      return new CmsAuthenticatedDataOutputStream(paramMacCalculator, paramDigestCalculator, paramASN1ObjectIdentifier, localTeeOutputStream, (BERSequenceGenerator)localObject1, (BERSequenceGenerator)localObject2, localBERSequenceGenerator);
    }
    catch (IOException localIOException)
    {
      throw new CMSException("exception decoding algorithm parameters.", localIOException);
    }
  }
  
  /**
   * @deprecated
   */
  public CMSAuthenticatedDataStreamGenerator(SecureRandom paramSecureRandom)
  {
    super(paramSecureRandom);
  }
  
  /**
   * @deprecated
   */
  public OutputStream open(OutputStream paramOutputStream, String paramString1, String paramString2)
    throws NoSuchAlgorithmException, NoSuchProviderException, CMSException, IOException
  {
    convertOldRecipients(rand, CMSUtils.getProvider(paramString2));
    return open(paramOutputStream, new JceCMSMacCalculatorBuilder(new ASN1ObjectIdentifier(paramString1)).setSecureRandom(rand).setProvider(paramString2).build());
  }
  
  /**
   * @deprecated
   */
  public OutputStream open(OutputStream paramOutputStream, String paramString, Provider paramProvider)
    throws NoSuchAlgorithmException, CMSException, IOException
  {
    convertOldRecipients(rand, paramProvider);
    return open(paramOutputStream, new JceCMSMacCalculatorBuilder(new ASN1ObjectIdentifier(paramString)).setSecureRandom(rand).setProvider(paramProvider).build());
  }
  
  /**
   * @deprecated
   */
  public OutputStream open(OutputStream paramOutputStream, String paramString1, int paramInt, String paramString2)
    throws NoSuchAlgorithmException, NoSuchProviderException, CMSException, IOException
  {
    convertOldRecipients(rand, CMSUtils.getProvider(paramString2));
    return open(paramOutputStream, new JceCMSMacCalculatorBuilder(new ASN1ObjectIdentifier(paramString1), paramInt).setSecureRandom(rand).setProvider(paramString2).build());
  }
  
  /**
   * @deprecated
   */
  public OutputStream open(OutputStream paramOutputStream, String paramString, int paramInt, Provider paramProvider)
    throws NoSuchAlgorithmException, CMSException, IOException
  {
    convertOldRecipients(rand, paramProvider);
    return open(paramOutputStream, new JceCMSMacCalculatorBuilder(new ASN1ObjectIdentifier(paramString), paramInt).setSecureRandom(rand).setProvider(paramProvider).build());
  }
  
  private class CmsAuthenticatedDataOutputStream
    extends OutputStream
  {
    private OutputStream dataStream;
    private BERSequenceGenerator cGen;
    private BERSequenceGenerator envGen;
    private BERSequenceGenerator eiGen;
    private MacCalculator macCalculator;
    private DigestCalculator digestCalculator;
    private ASN1ObjectIdentifier contentType;
    
    public CmsAuthenticatedDataOutputStream(MacCalculator paramMacCalculator, DigestCalculator paramDigestCalculator, ASN1ObjectIdentifier paramASN1ObjectIdentifier, OutputStream paramOutputStream, BERSequenceGenerator paramBERSequenceGenerator1, BERSequenceGenerator paramBERSequenceGenerator2, BERSequenceGenerator paramBERSequenceGenerator3)
    {
      macCalculator = paramMacCalculator;
      digestCalculator = paramDigestCalculator;
      contentType = paramASN1ObjectIdentifier;
      dataStream = paramOutputStream;
      cGen = paramBERSequenceGenerator1;
      envGen = paramBERSequenceGenerator2;
      eiGen = paramBERSequenceGenerator3;
    }
    
    public void write(int paramInt)
      throws IOException
    {
      dataStream.write(paramInt);
    }
    
    public void write(byte[] paramArrayOfByte, int paramInt1, int paramInt2)
      throws IOException
    {
      dataStream.write(paramArrayOfByte, paramInt1, paramInt2);
    }
    
    public void write(byte[] paramArrayOfByte)
      throws IOException
    {
      dataStream.write(paramArrayOfByte);
    }
    
    public void close()
      throws IOException
    {
      dataStream.close();
      eiGen.close();
      Map localMap;
      if (digestCalculator != null)
      {
        localMap = Collections.unmodifiableMap(getBaseParameters(contentType, digestCalculator.getAlgorithmIdentifier(), digestCalculator.getDigest()));
        if (authGen == null) {
          authGen = new DefaultAuthenticatedAttributeTableGenerator();
        }
        DERSet localDERSet = new DERSet(authGen.getAttributes(localMap).toASN1EncodableVector());
        OutputStream localOutputStream = macCalculator.getOutputStream();
        localOutputStream.write(localDERSet.getEncoded("DER"));
        localOutputStream.close();
        envGen.addObject(new DERTaggedObject(false, 2, localDERSet));
      }
      else
      {
        localMap = Collections.unmodifiableMap(new HashMap());
      }
      envGen.addObject(new DEROctetString(macCalculator.getMac()));
      if (unauthGen != null) {
        envGen.addObject(new DERTaggedObject(false, 3, new BERSet(unauthGen.getAttributes(localMap).toASN1EncodableVector())));
      }
      envGen.close();
      cGen.close();
    }
  }
}

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

import java.security.SecureRandom;
import java.util.HashMap;
import java.util.Map;
import org.bouncycastle.asn1.DERObjectIdentifier;
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;

public class CMSAuthenticatedGenerator
  extends CMSEnvelopedGenerator
{
  protected CMSAttributeTableGenerator authGen;
  protected CMSAttributeTableGenerator unauthGen;
  
  public CMSAuthenticatedGenerator() {}
  
  public CMSAuthenticatedGenerator(SecureRandom paramSecureRandom)
  {
    super(paramSecureRandom);
  }
  
  public void setAuthenticatedAttributeGenerator(CMSAttributeTableGenerator paramCMSAttributeTableGenerator)
  {
    authGen = paramCMSAttributeTableGenerator;
  }
  
  public void setUnauthenticatedAttributeGenerator(CMSAttributeTableGenerator paramCMSAttributeTableGenerator)
  {
    unauthGen = paramCMSAttributeTableGenerator;
  }
  
  protected Map getBaseParameters(DERObjectIdentifier paramDERObjectIdentifier, AlgorithmIdentifier paramAlgorithmIdentifier, byte[] paramArrayOfByte)
  {
    HashMap localHashMap = new HashMap();
    localHashMap.put("contentType", paramDERObjectIdentifier);
    localHashMap.put("digestAlgID", paramAlgorithmIdentifier);
    localHashMap.put("digest", paramArrayOfByte.clone());
    return localHashMap;
  }
}

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

import java.io.IOException;
import java.io.InputStream;
import java.util.zip.InflaterInputStream;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.asn1.ASN1OctetString;
import org.bouncycastle.asn1.cms.CompressedData;
import org.bouncycastle.asn1.cms.ContentInfo;
import org.bouncycastle.operator.InputExpander;
import org.bouncycastle.operator.InputExpanderProvider;

public class CMSCompressedData
{
  ContentInfo contentInfo;
  CompressedData comData;
  
  public CMSCompressedData(byte[] paramArrayOfByte)
    throws CMSException
  {
    this(CMSUtils.readContentInfo(paramArrayOfByte));
  }
  
  public CMSCompressedData(InputStream paramInputStream)
    throws CMSException
  {
    this(CMSUtils.readContentInfo(paramInputStream));
  }
  
  public CMSCompressedData(ContentInfo paramContentInfo)
    throws CMSException
  {
    contentInfo = paramContentInfo;
    try
    {
      comData = CompressedData.getInstance(paramContentInfo.getContent());
    }
    catch (ClassCastException localClassCastException)
    {
      throw new CMSException("Malformed content.", localClassCastException);
    }
    catch (IllegalArgumentException localIllegalArgumentException)
    {
      throw new CMSException("Malformed content.", localIllegalArgumentException);
    }
  }
  
  /**
   * @deprecated
   */
  public byte[] getContent()
    throws CMSException
  {
    ContentInfo localContentInfo = comData.getEncapContentInfo();
    ASN1OctetString localASN1OctetString = (ASN1OctetString)localContentInfo.getContent();
    InflaterInputStream localInflaterInputStream = new InflaterInputStream(localASN1OctetString.getOctetStream());
    try
    {
      return CMSUtils.streamToByteArray(localInflaterInputStream);
    }
    catch (IOException localIOException)
    {
      throw new CMSException("exception reading compressed stream.", localIOException);
    }
  }
  
  /**
   * @deprecated
   */
  public byte[] getContent(int paramInt)
    throws CMSException
  {
    ContentInfo localContentInfo = comData.getEncapContentInfo();
    ASN1OctetString localASN1OctetString = (ASN1OctetString)localContentInfo.getContent();
    InflaterInputStream localInflaterInputStream = new InflaterInputStream(localASN1OctetString.getOctetStream());
    try
    {
      return CMSUtils.streamToByteArray(localInflaterInputStream, paramInt);
    }
    catch (IOException localIOException)
    {
      throw new CMSException("exception reading compressed stream.", localIOException);
    }
  }
  
  public ASN1ObjectIdentifier getContentType()
  {
    return contentInfo.getContentType();
  }
  
  public byte[] getContent(InputExpanderProvider paramInputExpanderProvider)
    throws CMSException
  {
    ContentInfo localContentInfo = comData.getEncapContentInfo();
    ASN1OctetString localASN1OctetString = (ASN1OctetString)localContentInfo.getContent();
    InputExpander localInputExpander = paramInputExpanderProvider.get(comData.getCompressionAlgorithmIdentifier());
    InputStream localInputStream = localInputExpander.getInputStream(localASN1OctetString.getOctetStream());
    try
    {
      return CMSUtils.streamToByteArray(localInputStream);
    }
    catch (IOException localIOException)
    {
      throw new CMSException("exception reading compressed stream.", localIOException);
    }
  }
  
  /**
   * @deprecated
   */
  public ContentInfo getContentInfo()
  {
    return contentInfo;
  }
  
  public ContentInfo toASN1Structure()
  {
    return contentInfo;
  }
  
  public byte[] getEncoded()
    throws IOException
  {
    return contentInfo.getEncoded();
  }
}

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

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.zip.DeflaterOutputStream;
import org.bouncycastle.asn1.BERConstructedOctetString;
import org.bouncycastle.asn1.DERObjectIdentifier;
import org.bouncycastle.asn1.cms.CMSObjectIdentifiers;
import org.bouncycastle.asn1.cms.CompressedData;
import org.bouncycastle.asn1.cms.ContentInfo;
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
import org.bouncycastle.operator.OutputCompressor;

public class CMSCompressedDataGenerator
{
  public static final String ZLIB = "1.2.840.113549.1.9.16.3.8";
  
  /**
   * @deprecated
   */
  public CMSCompressedData generate(CMSProcessable paramCMSProcessable, String paramString)
    throws CMSException
  {
    AlgorithmIdentifier localAlgorithmIdentifier;
    BERConstructedOctetString localBERConstructedOctetString;
    try
    {
      ByteArrayOutputStream localByteArrayOutputStream = new ByteArrayOutputStream();
      localObject = new DeflaterOutputStream(localByteArrayOutputStream);
      paramCMSProcessable.write((OutputStream)localObject);
      ((DeflaterOutputStream)localObject).close();
      localAlgorithmIdentifier = new AlgorithmIdentifier(new DERObjectIdentifier(paramString));
      localBERConstructedOctetString = new BERConstructedOctetString(localByteArrayOutputStream.toByteArray());
    }
    catch (IOException localIOException)
    {
      throw new CMSException("exception encoding data.", localIOException);
    }
    ContentInfo localContentInfo = new ContentInfo(CMSObjectIdentifiers.data, localBERConstructedOctetString);
    Object localObject = new ContentInfo(CMSObjectIdentifiers.compressedData, new CompressedData(localAlgorithmIdentifier, localContentInfo));
    return new CMSCompressedData((ContentInfo)localObject);
  }
  
  public CMSCompressedData generate(CMSTypedData paramCMSTypedData, OutputCompressor paramOutputCompressor)
    throws CMSException
  {
    AlgorithmIdentifier localAlgorithmIdentifier;
    BERConstructedOctetString localBERConstructedOctetString;
    try
    {
      ByteArrayOutputStream localByteArrayOutputStream = new ByteArrayOutputStream();
      localObject = paramOutputCompressor.getOutputStream(localByteArrayOutputStream);
      paramCMSTypedData.write((OutputStream)localObject);
      ((OutputStream)localObject).close();
      localAlgorithmIdentifier = paramOutputCompressor.getAlgorithmIdentifier();
      localBERConstructedOctetString = new BERConstructedOctetString(localByteArrayOutputStream.toByteArray());
    }
    catch (IOException localIOException)
    {
      throw new CMSException("exception encoding data.", localIOException);
    }
    ContentInfo localContentInfo = new ContentInfo(paramCMSTypedData.getContentType(), localBERConstructedOctetString);
    Object localObject = new ContentInfo(CMSObjectIdentifiers.compressedData, new CompressedData(localAlgorithmIdentifier, localContentInfo));
    return new CMSCompressedData((ContentInfo)localObject);
  }
}

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

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.zip.InflaterInputStream;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.asn1.ASN1OctetStringParser;
import org.bouncycastle.asn1.ASN1SequenceParser;
import org.bouncycastle.asn1.cms.CompressedDataParser;
import org.bouncycastle.asn1.cms.ContentInfoParser;
import org.bouncycastle.operator.InputExpander;
import org.bouncycastle.operator.InputExpanderProvider;

public class CMSCompressedDataParser
  extends CMSContentInfoParser
{
  public CMSCompressedDataParser(byte[] paramArrayOfByte)
    throws CMSException
  {
    this(new ByteArrayInputStream(paramArrayOfByte));
  }
  
  public CMSCompressedDataParser(InputStream paramInputStream)
    throws CMSException
  {
    super(paramInputStream);
  }
  
  /**
   * @deprecated
   */
  public CMSTypedStream getContent()
    throws CMSException
  {
    try
    {
      CompressedDataParser localCompressedDataParser = new CompressedDataParser((ASN1SequenceParser)_contentInfo.getContent(16));
      ContentInfoParser localContentInfoParser = localCompressedDataParser.getEncapContentInfo();
      ASN1OctetStringParser localASN1OctetStringParser = (ASN1OctetStringParser)localContentInfoParser.getContent(4);
      return new CMSTypedStream(localContentInfoParser.getContentType().toString(), new InflaterInputStream(localASN1OctetStringParser.getOctetStream()));
    }
    catch (IOException localIOException)
    {
      throw new CMSException("IOException reading compressed content.", localIOException);
    }
  }
  
  public CMSTypedStream getContent(InputExpanderProvider paramInputExpanderProvider)
    throws CMSException
  {
    try
    {
      CompressedDataParser localCompressedDataParser = new CompressedDataParser((ASN1SequenceParser)_con
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