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

package org.bouncycastle.its;

import org.bouncycastle.oer.its.template.etsi103097.EtsiTs103097Module;
import java.util.Iterator;
import java.util.Collection;
import org.bouncycastle.util.CollectionStore;
import org.bouncycastle.oer.its.ieee1609dot2.RecipientInfo;
import java.util.ArrayList;
import org.bouncycastle.util.Store;
import org.bouncycastle.asn1.ASN1Encodable;
import org.bouncycastle.oer.OEREncoder;
import org.bouncycastle.oer.its.ieee1609dot2.Ieee1609Dot2Content;
import org.bouncycastle.oer.its.etsi103097.EtsiTs103097DataEncrypted;
import org.bouncycastle.oer.OERInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ByteArrayInputStream;
import org.bouncycastle.oer.its.ieee1609dot2.EncryptedData;
import org.bouncycastle.oer.Element;

public class ETSIEncryptedData
{
    private static final Element oerDef;
    private final EncryptedData encryptedData;
    
    public ETSIEncryptedData(final byte[] buf) throws IOException {
        this(new ByteArrayInputStream(buf));
    }
    
    public ETSIEncryptedData(final InputStream inputStream) throws IOException {
        OERInputStream oerInputStream;
        if (inputStream instanceof OERInputStream) {
            oerInputStream = (OERInputStream)inputStream;
        }
        else {
            oerInputStream = new OERInputStream(inputStream);
        }
        final Ieee1609Dot2Content content = EtsiTs103097DataEncrypted.getInstance(oerInputStream.parse(ETSIEncryptedData.oerDef)).getContent();
        if (content.getChoice() != 2) {
            throw new IllegalStateException("EtsiTs103097Data-Encrypted did not have encrypted data content");
        }
        this.encryptedData = EncryptedData.getInstance(content.getIeee1609Dot2Content());
    }
    
    ETSIEncryptedData(final EncryptedData encryptedData) {
        this.encryptedData = encryptedData;
    }
    
    public byte[] getEncoded() {
        return OEREncoder.toByteArray(new EtsiTs103097DataEncrypted(Ieee1609Dot2Content.encryptedData(this.encryptedData)), ETSIEncryptedData.oerDef);
    }
    
    public EncryptedData getEncryptedData() {
        return this.encryptedData;
    }
    
    public Store<ETSIRecipientInfo> getRecipients() {
        final ArrayList list = new ArrayList();
        final Iterator<RecipientInfo> iterator = this.encryptedData.getRecipients().getRecipientInfos().iterator();
        while (iterator.hasNext()) {
            list.add(new ETSIRecipientInfo(this.encryptedData, iterator.next()));
        }
        return new CollectionStore<ETSIRecipientInfo>(list);
    }
    
    static {
        oerDef = EtsiTs103097Module.EtsiTs103097Data_Encrypted.build();
    }
}
