// 
// 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 LMOtsSignature implements Encodable
{
    private final LMOtsParameters type;
    private final byte[] C;
    private final byte[] y;
    
    public LMOtsSignature(final LMOtsParameters type, final byte[] c, final byte[] y) {
        this.type = type;
        this.C = c;
        this.y = y;
    }
    
    public static LMOtsSignature getInstance(final Object obj) throws IOException {
        if (obj instanceof LMOtsSignature) {
            return (LMOtsSignature)obj;
        }
        if (obj instanceof DataInputStream) {
            final LMOtsParameters parametersForType = LMOtsParameters.getParametersForType(((DataInputStream)obj).readInt());
            final byte[] b = new byte[parametersForType.getN()];
            ((DataInputStream)obj).readFully(b);
            final byte[] b2 = new byte[parametersForType.getP() * parametersForType.getN()];
            ((DataInputStream)obj).readFully(b2);
            return new LMOtsSignature(parametersForType, b, b2);
        }
        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);
    }
    
    public LMOtsParameters getType() {
        return this.type;
    }
    
    public byte[] getC() {
        return this.C;
    }
    
    public byte[] getY() {
        return this.y;
    }
    
    @Override
    public boolean equals(final Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || this.getClass() != o.getClass()) {
            return false;
        }
        final LMOtsSignature lmOtsSignature = (LMOtsSignature)o;
        if (this.type != null) {
            if (this.type.equals(lmOtsSignature.type)) {
                return Arrays.equals(this.C, lmOtsSignature.C) && Arrays.equals(this.y, lmOtsSignature.y);
            }
        }
        else if (lmOtsSignature.type == null) {
            return Arrays.equals(this.C, lmOtsSignature.C) && Arrays.equals(this.y, lmOtsSignature.y);
        }
        return false;
    }
    
    @Override
    public int hashCode() {
        return 31 * (31 * ((this.type != null) ? this.type.hashCode() : 0) + Arrays.hashCode(this.C)) + Arrays.hashCode(this.y);
    }
    
    @Override
    public byte[] getEncoded() throws IOException {
        return Composer.compose().u32str(this.type.getType()).bytes(this.C).bytes(this.y).build();
    }
}
