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

package org.bouncycastle.pqc.crypto.lms;

import org.bouncycastle.util.Encodable;
import java.io.ByteArrayOutputStream;

public class Composer
{
    private final ByteArrayOutputStream bos;
    
    private Composer() {
        this.bos = new ByteArrayOutputStream();
    }
    
    public static Composer compose() {
        return new Composer();
    }
    
    public Composer u64str(final long n) {
        this.u32str((int)(n >>> 32));
        this.u32str((int)n);
        return this;
    }
    
    public Composer u32str(final int n) {
        this.bos.write((byte)(n >>> 24));
        this.bos.write((byte)(n >>> 16));
        this.bos.write((byte)(n >>> 8));
        this.bos.write((byte)n);
        return this;
    }
    
    public Composer u16str(int n) {
        n &= 0xFFFF;
        this.bos.write((byte)(n >>> 8));
        this.bos.write((byte)n);
        return this;
    }
    
    public Composer bytes(final Encodable[] array) {
        try {
            for (int length = array.length, i = 0; i < length; ++i) {
                this.bos.write(array[i].getEncoded());
            }
        }
        catch (final Exception cause) {
            throw new RuntimeException(cause.getMessage(), cause);
        }
        return this;
    }
    
    public Composer bytes(final Encodable encodable) {
        try {
            this.bos.write(encodable.getEncoded());
        }
        catch (final Exception cause) {
            throw new RuntimeException(cause.getMessage(), cause);
        }
        return this;
    }
    
    public Composer pad(final int b, int i) {
        while (i >= 0) {
            try {
                this.bos.write(b);
            }
            catch (final Exception cause) {
                throw new RuntimeException(cause.getMessage(), cause);
            }
            --i;
        }
        return this;
    }
    
    public Composer bytes(final byte[][] array) {
        try {
            for (int length = array.length, i = 0; i < length; ++i) {
                this.bos.write(array[i]);
            }
        }
        catch (final Exception cause) {
            throw new RuntimeException(cause.getMessage(), cause);
        }
        return this;
    }
    
    public Composer bytes(final byte[][] array, final int n, final int n2) {
        try {
            for (int i = n; i != n2; ++i) {
                this.bos.write(array[i]);
            }
        }
        catch (final Exception cause) {
            throw new RuntimeException(cause.getMessage(), cause);
        }
        return this;
    }
    
    public Composer bytes(final byte[] b) {
        try {
            this.bos.write(b);
        }
        catch (final Exception cause) {
            throw new RuntimeException(cause.getMessage(), cause);
        }
        return this;
    }
    
    public Composer bytes(final byte[] b, final int off, final int len) {
        try {
            this.bos.write(b, off, len);
        }
        catch (final Exception cause) {
            throw new RuntimeException(cause.getMessage(), cause);
        }
        return this;
    }
    
    public byte[] build() {
        return this.bos.toByteArray();
    }
    
    public Composer padUntil(final int b, final int n) {
        while (this.bos.size() < n) {
            this.bos.write(b);
        }
        return this;
    }
    
    public Composer bool(final boolean b) {
        this.bos.write(b ? 1 : 0);
        return this;
    }
}
