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

package org.bouncycastle.oer.its.ieee1609dot2.basetypes;

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 PublicEncryptionKey extends ASN1Object
{
    private final SymmAlgorithm supportedSymmAlg;
    private final BasePublicEncryptionKey publicKey;
    
    public PublicEncryptionKey(final SymmAlgorithm supportedSymmAlg, final BasePublicEncryptionKey publicKey) {
        this.supportedSymmAlg = supportedSymmAlg;
        this.publicKey = publicKey;
    }
    
    private PublicEncryptionKey(final ASN1Sequence asn1Sequence) {
        if (asn1Sequence.size() != 2) {
            throw new IllegalArgumentException("expected sequence size of 2");
        }
        this.supportedSymmAlg = SymmAlgorithm.getInstance(asn1Sequence.getObjectAt(0));
        this.publicKey = BasePublicEncryptionKey.getInstance(asn1Sequence.getObjectAt(1));
    }
    
    public static PublicEncryptionKey getInstance(final Object o) {
        if (o instanceof PublicEncryptionKey) {
            return (PublicEncryptionKey)o;
        }
        if (o != null) {
            return new PublicEncryptionKey(ASN1Sequence.getInstance(o));
        }
        return null;
    }
    
    public SymmAlgorithm getSupportedSymmAlg() {
        return this.supportedSymmAlg;
    }
    
    public BasePublicEncryptionKey getPublicKey() {
        return this.publicKey;
    }
    
    @Override
    public ASN1Primitive toASN1Primitive() {
        return ItsUtils.toSequence(this.supportedSymmAlg, this.publicKey);
    }
    
    public static Builder builder() {
        return new Builder();
    }
    
    public static class Builder
    {
        private SymmAlgorithm supportedSymmAlg;
        private BasePublicEncryptionKey publicKey;
        
        public Builder setSupportedSymmAlg(final SymmAlgorithm supportedSymmAlg) {
            this.supportedSymmAlg = supportedSymmAlg;
            return this;
        }
        
        public Builder setPublicKey(final BasePublicEncryptionKey publicKey) {
            this.publicKey = publicKey;
            return this;
        }
        
        public PublicEncryptionKey createPublicEncryptionKey() {
            return new PublicEncryptionKey(this.supportedSymmAlg, this.publicKey);
        }
    }
}
