package org.bouncycastle.bcpg;

import java.io.IOException;
import java.io.OutputStream;
import org.bouncycastle.util.Arrays;

/* JADX INFO: loaded from: classes3.dex */
public class SignatureSubpacket {
    boolean critical;
    protected byte[] data;
    boolean isLongLength;
    int type;

    protected SignatureSubpacket(int i, boolean z, boolean z2, byte[] bArr) {
        this.type = i;
        this.critical = z;
        this.isLongLength = z2;
        this.data = bArr;
    }

    public void encode(OutputStream outputStream) throws IOException {
        int length = this.data.length + 1;
        if (this.isLongLength) {
            outputStream.write(255);
            StreamUtil.writeBodyLen(outputStream, length);
        } else {
            StreamUtil.writeNewPacketLength(outputStream, length);
        }
        boolean z = this.critical;
        int i = this.type;
        if (z) {
            outputStream.write(i | 128);
        } else {
            outputStream.write(i);
        }
        outputStream.write(this.data);
    }

    public boolean equals(Object obj) {
        if (obj == this) {
            return true;
        }
        if (!(obj instanceof SignatureSubpacket)) {
            return false;
        }
        SignatureSubpacket signatureSubpacket = (SignatureSubpacket) obj;
        if (this.type == signatureSubpacket.type && this.critical == signatureSubpacket.critical) {
            return Arrays.areEqual(this.data, signatureSubpacket.data);
        }
        return false;
    }

    public byte[] getData() {
        return this.data;
    }

    public int getType() {
        return this.type;
    }

    public int hashCode() {
        boolean z = this.critical;
        return (z ? 1 : 0) + (this.type * 7) + (Arrays.hashCode(this.data) * 49);
    }

    public boolean isCritical() {
        return this.critical;
    }

    public boolean isLongLength() {
        return this.isLongLength;
    }
}
