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

package org.bouncycastle.oer.its.ieee1609dot2;

import org.bouncycastle.asn1.DEROctetString;
import org.bouncycastle.util.Arrays;
import org.bouncycastle.oer.its.ItsUtils;
import org.bouncycastle.asn1.ASN1Primitive;
import org.bouncycastle.asn1.ASN1Encodable;
import java.util.Iterator;
import org.bouncycastle.asn1.ASN1Sequence;
import org.bouncycastle.asn1.ASN1OctetString;
import org.bouncycastle.asn1.ASN1Object;

public class AesCcmCiphertext extends ASN1Object
{
    private final ASN1OctetString nonce;
    private final Opaque ccmCiphertext;
    
    public AesCcmCiphertext(final ASN1OctetString nonce, final Opaque ccmCiphertext) {
        this.nonce = nonce;
        this.ccmCiphertext = ccmCiphertext;
    }
    
    private AesCcmCiphertext(final ASN1Sequence asn1Sequence) {
        if (asn1Sequence.size() != 2) {
            throw new IllegalArgumentException("expected sequence size of 2");
        }
        final Iterator<ASN1Encodable> iterator = asn1Sequence.iterator();
        this.nonce = ASN1OctetString.getInstance(iterator.next());
        this.ccmCiphertext = Opaque.getInstance(iterator.next());
    }
    
    public static AesCcmCiphertext getInstance(final Object o) {
        if (o instanceof AesCcmCiphertext) {
            return (AesCcmCiphertext)o;
        }
        if (o != null) {
            return new AesCcmCiphertext(ASN1Sequence.getInstance(o));
        }
        return null;
    }
    
    public ASN1OctetString getNonce() {
        return this.nonce;
    }
    
    public Opaque getCcmCiphertext() {
        return this.ccmCiphertext;
    }
    
    @Override
    public ASN1Primitive toASN1Primitive() {
        return ItsUtils.toSequence(this.nonce, this.ccmCiphertext);
    }
    
    public static Builder builder() {
        return new Builder();
    }
    
    public static class Builder
    {
        private ASN1OctetString nonce;
        private Opaque opaque;
        
        public Builder setNonce(final ASN1OctetString nonce) {
            this.nonce = nonce;
            return this;
        }
        
        public Builder setNonce(final byte[] array) {
            return this.setNonce(new DEROctetString(Arrays.clone(array)));
        }
        
        public Builder setCcmCiphertext(final Opaque opaque) {
            this.opaque = opaque;
            return this;
        }
        
        public Builder setCcmCiphertext(final byte[] array) {
            return this.setCcmCiphertext(new Opaque(array));
        }
        
        public AesCcmCiphertext createAesCcmCiphertext() {
            return new AesCcmCiphertext(this.nonce, this.opaque);
        }
    }
}
