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

package org.bouncycastle.oer.its.ieee1609dot2;

import org.bouncycastle.oer.its.ItsUtils;
import org.bouncycastle.asn1.ASN1Encodable;
import org.bouncycastle.asn1.ASN1Primitive;
import org.bouncycastle.asn1.ASN1Sequence;
import org.bouncycastle.asn1.ASN1Object;

public class EncryptedData extends ASN1Object
{
    private final SequenceOfRecipientInfo recipients;
    private final SymmetricCiphertext ciphertext;
    
    public EncryptedData(final SequenceOfRecipientInfo recipients, final SymmetricCiphertext ciphertext) {
        this.recipients = recipients;
        this.ciphertext = ciphertext;
    }
    
    private EncryptedData(final ASN1Sequence asn1Sequence) {
        if (asn1Sequence.size() != 2) {
            throw new IllegalArgumentException("expected sequence size of 2");
        }
        this.recipients = SequenceOfRecipientInfo.getInstance(asn1Sequence.getObjectAt(0));
        this.ciphertext = SymmetricCiphertext.getInstance(asn1Sequence.getObjectAt(1));
    }
    
    public static EncryptedData getInstance(final Object o) {
        if (o instanceof EncryptedData) {
            return (EncryptedData)o;
        }
        if (o != null) {
            return new EncryptedData(ASN1Sequence.getInstance(o));
        }
        return null;
    }
    
    @Override
    public ASN1Primitive toASN1Primitive() {
        return ItsUtils.toSequence(this.recipients, this.ciphertext);
    }
    
    public SequenceOfRecipientInfo getRecipients() {
        return this.recipients;
    }
    
    public SymmetricCiphertext getCiphertext() {
        return this.ciphertext;
    }
    
    public static Builder builder() {
        return new Builder();
    }
    
    public static class Builder
    {
        private SequenceOfRecipientInfo recipients;
        private SymmetricCiphertext ciphertext;
        
        public Builder setRecipients(final SequenceOfRecipientInfo recipients) {
            this.recipients = recipients;
            return this;
        }
        
        public Builder setCiphertext(final SymmetricCiphertext ciphertext) {
            this.ciphertext = ciphertext;
            return this;
        }
        
        public EncryptedData createEncryptedData() {
            return new EncryptedData(this.recipients, this.ciphertext);
        }
    }
}
