Information

0
Story Points

Technologies

Decompiled Java File
package iaik.pkcs.pkcs7;

import iaik.asn1.ASN;
import iaik.asn1.ASN1Object;
import iaik.asn1.CodingException;
import iaik.asn1.DerCoder;
import iaik.asn1.DerInputStream;
import iaik.asn1.INTEGER;
import iaik.asn1.ObjectID;
import iaik.asn1.SEQUENCE;
import iaik.asn1.structures.AlgorithmID;
import iaik.pkcs.PKCSException;
import iaik.pkcs.PKCSParsingException;
import iaik.pkcs.pkcs7.ContentStream;
import iaik.pkcs.pkcs7.EncryptedContentInfoStream;
import iaik.pkcs.pkcs7.IssuerAndSerialNumber;
import iaik.pkcs.pkcs7.RecipientInfo;
import iaik.utils.Util;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.security.InvalidKeyException;
import java.security.Key;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.cert.X509Certificate;
import java.util.Enumeration;
import java.util.Vector;
import javax.crypto.SecretKey;

public class EnvelopedDataStream implements ContentStream {
   // $FF: synthetic field
   static Class a;
   protected int block_size;
   protected SecretKey symmetric_key;
   protected EncryptedContentInfoStream encrypted_content_info;
   protected Vector recipient_infos;
   protected int version;

   static Class a(String var0) {
      try {
         return Class.forName(var0);
      } catch (ClassNotFoundException var2) {
         throw new NoClassDefFoundError(var2.getMessage());
      }
   }

   public void writeTo(OutputStream var1, int var2) throws IOException {
      try {
         DerCoder.encodeTo(this.toASN1Object(var2), var1);
      } catch (PKCSException var4) {
         throw new IOException(var4.toString());
      }
   }

   public void writeTo(OutputStream var1) throws IOException {
      try {
         DerCoder.encodeTo(this.toASN1Object(), var1);
      } catch (PKCSException var3) {
         throw new IOException(var3.toString());
      }
   }

   public String toString(boolean var1) {
      StringBuffer var2 = new StringBuffer();
      var2.append("Version: " + this.version + "\n");
      if(var1) {
         for(int var3 = 0; var3 < this.recipient_infos.size(); ++var3) {
            var2.append("\nRecipientInfo " + (var3 + 1) + ":{\n");
            var2.append(((RecipientInfo)this.recipient_infos.elementAt(var3)).toString());
            var2.append("\n}");
         }
      } else {
         var2.append("RecipientInfos: " + this.recipient_infos.size() + "\n");
      }

      var2.append("\nEncryptedContentInfo: {\n");
      var2.append(this.encrypted_content_info.toString() + "}");
      return var2.toString();
   }

   public String toString() {
      return this.toString(false);
   }

   protected ASN1Object toASN1Object(int var1) throws PKCSException {
      if(var1 <= 0) {
         var1 = this.block_size;
      }

      if(this.recipient_infos == null) {
         throw new PKCSException("No recipients specified.");
      } else {
         if(this.symmetric_key != null) {
            Enumeration var2 = this.recipient_infos.elements();

            while(var2.hasMoreElements()) {
               ((RecipientInfo)var2.nextElement()).encryptKey(this.symmetric_key);
            }
         }

         this.encrypted_content_info.setBlockSize(var1);
         SEQUENCE var5 = new SEQUENCE(true);

         try {
            var5.addComponent(new INTEGER(this.version));
            var5.addComponent(ASN.createSetOf(this.recipient_infos));
            var5.addComponent(this.encrypted_content_info.toASN1Object());
            return var5;
         } catch (CodingException var4) {
            throw new PKCSException(var4.toString());
         }
      }
   }

   public ASN1Object toASN1Object() throws PKCSException {
      return this.toASN1Object(-1);
   }

   public void setupCipher(PrivateKey var1, int var2) throws InvalidKeyException, NoSuchAlgorithmException, PKCSException {
      SecretKey var3 = ((RecipientInfo)this.recipient_infos.elementAt(var2)).decryptKey(var1);
      this.encrypted_content_info.setupCipher(var3);
   }

   public void setupCipher(Key var1) throws InvalidKeyException, NoSuchAlgorithmException, PKCSException {
      this.encrypted_content_info.setupCipher(var1);
   }

   public void setRecipientInfos(RecipientInfo[] var1) {
      this.recipient_infos = Util.getVector(var1);
   }

   public void setBlockSize(int var1) {
      this.block_size = var1;
   }

   public int getVersion() {
      return this.version;
   }

   public RecipientInfo[] getRecipientInfos() {
      return (RecipientInfo[])Util.toArray(this.recipient_infos, a != null?a:(a = a("iaik.pkcs.pkcs7.RecipientInfo")));
   }

   public RecipientInfo getRecipientInfo(X509Certificate var1) {
      Enumeration var2 = this.recipient_infos.elements();

      RecipientInfo var3;
      IssuerAndSerialNumber var4;
      do {
         if(!var2.hasMoreElements()) {
            return null;
         }

         var3 = (RecipientInfo)var2.nextElement();
         var4 = var3.getIssuerAndSerialNumber();
      } while(var4 == null || !var4.isIssuerOf(var1));

      return var3;
   }

   public InputStream getInputStream() {
      return this.encrypted_content_info.getInputStream();
   }

   public Object getEncryptedContentInfo() {
      return this.encrypted_content_info;
   }

   public ObjectID getContentType() {
      return ObjectID.pkcs7_envelopedData;
   }

   public int getBlockSize() {
      return this.block_size;
   }

   public void decode(InputStream var1) throws PKCSParsingException, IOException {
      if(!(var1 instanceof DerInputStream)) {
         var1 = new DerInputStream((InputStream)var1);
      }

      DerInputStream var2 = ((DerInputStream)var1).readSequence();
      this.version = var2.readInteger().intValue();

      try {
         this.recipient_infos = Util.getVector((RecipientInfo[])ASN.parseSequenceOf(DerCoder.decode(var2), a != null?a:(a = a("iaik.pkcs.pkcs7.RecipientInfo"))));
      } catch (CodingException var3) {
         throw new PKCSParsingException("Error parsing recipient infos!");
      }

      this.encrypted_content_info = new EncryptedContentInfoStream(var2);
   }

   public void addRecipientInfo(RecipientInfo var1) {
      this.recipient_infos.addElement(var1);
   }

   public EnvelopedDataStream(RecipientInfo[] var1, EncryptedContentInfoStream var2) {
      this();
      this.recipient_infos = Util.getVector(var1);
      this.encrypted_content_info = var2;
   }

   public EnvelopedDataStream(InputStream var1, AlgorithmID var2, int var3) throws NoSuchAlgorithmException {
      this();
      this.encrypted_content_info = new EncryptedContentInfoStream(ObjectID.pkcs7_data, var1);
      this.symmetric_key = this.encrypted_content_info.setupCipher(var2, var3);
   }

   public EnvelopedDataStream(InputStream var1, AlgorithmID var2) throws NoSuchAlgorithmException {
      this();
      this.encrypted_content_info = new EncryptedContentInfoStream(ObjectID.pkcs7_data, var1);
      this.symmetric_key = this.encrypted_content_info.setupCipher(var2);
   }

   public EnvelopedDataStream(InputStream var1) throws IOException, PKCSParsingException {
      this();
      this.decode(var1);
   }

   protected EnvelopedDataStream() {
      this.version = 0;
      this.recipient_infos = new Vector();
      this.block_size = -1;
   }
}
Page generated: Oct 19, 2017 2:34:58 PM