// 
// 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.oer.its.ieee1609dot2.basetypes.HashedId;
import org.bouncycastle.asn1.ASN1Sequence;
import org.bouncycastle.oer.its.ieee1609dot2.basetypes.HashedId8;
import org.bouncycastle.asn1.ASN1Object;

public class SymmRecipientInfo extends ASN1Object
{
    private final HashedId8 recipientId;
    private final SymmetricCiphertext encKey;
    
    public SymmRecipientInfo(final HashedId8 recipientId, final SymmetricCiphertext encKey) {
        this.recipientId = recipientId;
        this.encKey = encKey;
    }
    
    private SymmRecipientInfo(final ASN1Sequence asn1Sequence) {
        if (asn1Sequence.size() != 2) {
            throw new IllegalArgumentException("expected sequence size of 2");
        }
        this.recipientId = HashedId8.getInstance(asn1Sequence.getObjectAt(0));
        this.encKey = SymmetricCiphertext.getInstance(asn1Sequence.getObjectAt(1));
    }
    
    public static SymmRecipientInfo getInstance(final Object o) {
        if (o instanceof SymmRecipientInfo) {
            return (SymmRecipientInfo)o;
        }
        if (o != null) {
            return new SymmRecipientInfo(ASN1Sequence.getInstance(o));
        }
        return null;
    }
    
    public HashedId getRecipientId() {
        return this.recipientId;
    }
    
    public SymmetricCiphertext getEncKey() {
        return this.encKey;
    }
    
    @Override
    public ASN1Primitive toASN1Primitive() {
        return ItsUtils.toSequence(this.recipientId, this.encKey);
    }
    
    public static Builder builder() {
        return new Builder();
    }
    
    public static class Builder
    {
        private HashedId8 recipientId;
        private SymmetricCiphertext encKey;
        
        public Builder setRecipientId(final HashedId8 recipientId) {
            this.recipientId = recipientId;
            return this;
        }
        
        public Builder setEncKey(final SymmetricCiphertext encKey) {
            this.encKey = encKey;
            return this;
        }
        
        public SymmRecipientInfo createSymmRecipientInfo() {
            return new SymmRecipientInfo(this.recipientId, this.encKey);
        }
    }
}
