// 
// Decompiled by Procyon v0.6.0
// 

package org.bouncycastle.cms;

import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
import org.bouncycastle.asn1.ASN1Encodable;
import org.bouncycastle.asn1.cms.ContentInfo;
import org.bouncycastle.asn1.cms.EncryptedData;
import org.bouncycastle.asn1.cms.CMSObjectIdentifiers;
import org.bouncycastle.asn1.BEROctetString;
import java.io.IOException;
import java.io.OutputStream;
import java.io.ByteArrayOutputStream;
import org.bouncycastle.operator.OutputEncryptor;

public class CMSEncryptedDataGenerator extends CMSEncryptedGenerator
{
    private CMSEncryptedData doGenerate(final CMSTypedData cmsTypedData, final OutputEncryptor outputEncryptor) throws CMSException {
        final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        try {
            final OutputStream outputStream = outputEncryptor.getOutputStream(byteArrayOutputStream);
            cmsTypedData.write(outputStream);
            outputStream.close();
        }
        catch (final IOException ex) {
            throw new CMSException("");
        }
        final byte[] byteArray = byteArrayOutputStream.toByteArray();
        final AlgorithmIdentifier algorithmIdentifier = outputEncryptor.getAlgorithmIdentifier();
        final BEROctetString berOctetString = new BEROctetString(byteArray);
        return new CMSEncryptedData(new ContentInfo(CMSObjectIdentifiers.encryptedData, new EncryptedData(CMSUtils.getEncryptedContentInfo(cmsTypedData.getContentType(), algorithmIdentifier, byteArray), CMSUtils.getAttrBERSet(this.unprotectedAttributeGenerator))));
    }
    
    public CMSEncryptedData generate(final CMSTypedData cmsTypedData, final OutputEncryptor outputEncryptor) throws CMSException {
        return this.doGenerate(cmsTypedData, outputEncryptor);
    }
}
