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

package org.bouncycastle.its;

import java.util.Iterator;
import org.bouncycastle.oer.its.ieee1609dot2.SymmetricCiphertext;
import org.bouncycastle.oer.its.ieee1609dot2.AesCcmCiphertext;
import org.bouncycastle.oer.its.ieee1609dot2.EncryptedData;
import org.bouncycastle.oer.its.ieee1609dot2.RecipientInfo;
import org.bouncycastle.oer.its.ieee1609dot2.SequenceOfRecipientInfo;
import org.bouncycastle.its.operator.ETSIDataEncryptor;
import java.util.ArrayList;
import java.util.List;

public class ETSIEncryptedDataBuilder
{
    private final List<ETSIRecipientInfoBuilder> recipientInfoBuilders;
    
    public ETSIEncryptedDataBuilder() {
        this.recipientInfoBuilders = new ArrayList<ETSIRecipientInfoBuilder>();
    }
    
    public void addRecipientInfoBuilder(final ETSIRecipientInfoBuilder etsiRecipientInfoBuilder) {
        this.recipientInfoBuilders.add(etsiRecipientInfoBuilder);
    }
    
    public ETSIEncryptedData build(final ETSIDataEncryptor etsiDataEncryptor, final byte[] array) {
        final byte[] encrypt = etsiDataEncryptor.encrypt(array);
        final byte[] key = etsiDataEncryptor.getKey();
        final byte[] nonce = etsiDataEncryptor.getNonce();
        final SequenceOfRecipientInfo.Builder builder = SequenceOfRecipientInfo.builder();
        final Iterator<ETSIRecipientInfoBuilder> iterator = this.recipientInfoBuilders.iterator();
        while (iterator.hasNext()) {
            builder.addRecipients(iterator.next().build(key));
        }
        return new ETSIEncryptedData(EncryptedData.builder().setRecipients(builder.createSequenceOfRecipientInfo()).setCiphertext(SymmetricCiphertext.aes128ccm(AesCcmCiphertext.builder().setCcmCiphertext(encrypt).setNonce(nonce).createAesCcmCiphertext())).createEncryptedData());
    }
}
