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

package org.bouncycastle.pqc.crypto.lms;

import java.util.Arrays;
import java.io.IOException;
import org.bouncycastle.util.io.Streams;
import java.io.InputStream;
import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import org.bouncycastle.util.Encodable;

class LMSSignature implements Encodable
{
    private final int q;
    private final LMOtsSignature otsSignature;
    private final LMSigParameters parameter;
    private final byte[][] y;
    
    public LMSSignature(final int q, final LMOtsSignature otsSignature, final LMSigParameters parameter, final byte[][] y) {
        this.q = q;
        this.otsSignature = otsSignature;
        this.parameter = parameter;
        this.y = y;
    }
    
    public static LMSSignature getInstance(final Object obj) throws IOException {
        if (obj instanceof LMSSignature) {
            return (LMSSignature)obj;
        }
        if (obj instanceof DataInputStream) {
            final int int1 = ((DataInputStream)obj).readInt();
            final LMOtsSignature instance = LMOtsSignature.getInstance(obj);
            final LMSigParameters parametersForType = LMSigParameters.getParametersForType(((DataInputStream)obj).readInt());
            final byte[][] array = new byte[parametersForType.getH()][];
            for (int i = 0; i < array.length; ++i) {
                array[i] = new byte[parametersForType.getM()];
                ((DataInputStream)obj).readFully(array[i]);
            }
            return new LMSSignature(int1, instance, parametersForType, array);
        }
        if (obj instanceof byte[]) {
            Object o = null;
            try {
                o = new DataInputStream(new ByteArrayInputStream((byte[])obj));
                return getInstance(o);
            }
            finally {
                if (o != null) {
                    ((InputStream)o).close();
                }
            }
        }
        if (obj instanceof InputStream) {
            return getInstance(Streams.readAll((InputStream)obj));
        }
        throw new IllegalArgumentException("cannot parse " + obj);
    }
    
    @Override
    public boolean equals(final Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || this.getClass() != o.getClass()) {
            return false;
        }
        final LMSSignature lmsSignature = (LMSSignature)o;
        if (this.q != lmsSignature.q) {
            return false;
        }
        Label_0075: {
            if (this.otsSignature != null) {
                if (this.otsSignature.equals(lmsSignature.otsSignature)) {
                    break Label_0075;
                }
            }
            else if (lmsSignature.otsSignature == null) {
                break Label_0075;
            }
            return false;
        }
        if (this.parameter != null) {
            if (this.parameter.equals(lmsSignature.parameter)) {
                return Arrays.deepEquals(this.y, lmsSignature.y);
            }
        }
        else if (lmsSignature.parameter == null) {
            return Arrays.deepEquals(this.y, lmsSignature.y);
        }
        return false;
    }
    
    @Override
    public int hashCode() {
        return 31 * (31 * (31 * this.q + ((this.otsSignature != null) ? this.otsSignature.hashCode() : 0)) + ((this.parameter != null) ? this.parameter.hashCode() : 0)) + Arrays.deepHashCode(this.y);
    }
    
    @Override
    public byte[] getEncoded() throws IOException {
        return Composer.compose().u32str(this.q).bytes(this.otsSignature.getEncoded()).u32str(this.parameter.getType()).bytes(this.y).build();
    }
    
    public int getQ() {
        return this.q;
    }
    
    public LMOtsSignature getOtsSignature() {
        return this.otsSignature;
    }
    
    public LMSigParameters getParameter() {
        return this.parameter;
    }
    
    public byte[][] getY() {
        return this.y;
    }
}
