package org.bouncycastle.bcpg;

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

/* JADX INFO: loaded from: classes.dex */
public class SymmetricEncIntegrityPacket extends InputStreamPacket implements BCPGHeaderObject {
    public static final int VERSION_1 = 1;
    public static final int VERSION_2 = 2;
    int aeadAlgorithm;
    int chunkSize;
    int cipherAlgorithm;
    byte[] salt;
    int version;

    public SymmetricEncIntegrityPacket() {
        super(null, 18);
        this.version = 1;
    }

    private SymmetricEncIntegrityPacket(int i, int i2, int i3, int i4, byte[] bArr) {
        super(null, 18);
        this.version = i;
        this.cipherAlgorithm = i2;
        this.aeadAlgorithm = i3;
        this.chunkSize = i4;
        this.salt = Arrays.clone(bArr);
    }

    SymmetricEncIntegrityPacket(BCPGInputStream bCPGInputStream) throws IOException {
        this(bCPGInputStream, false);
    }

    SymmetricEncIntegrityPacket(BCPGInputStream bCPGInputStream, boolean z) throws IOException {
        super(bCPGInputStream, 18, z);
        this.version = bCPGInputStream.read();
        if (this.version == 2) {
            this.cipherAlgorithm = bCPGInputStream.read();
            this.aeadAlgorithm = bCPGInputStream.read();
            this.chunkSize = bCPGInputStream.read();
            this.salt = new byte[32];
            if (bCPGInputStream.read(this.salt) != this.salt.length) {
                throw new EOFException("Premature end of stream.");
            }
        }
    }

    public static byte[] createAAData(int i, int i2, int i3, int i4) {
        return new byte[]{-46, (byte) (i & 255), (byte) (i2 & 255), (byte) (i3 & 255), (byte) (i4 & 255)};
    }

    public static SymmetricEncIntegrityPacket createVersion1Packet() {
        return new SymmetricEncIntegrityPacket();
    }

    public static SymmetricEncIntegrityPacket createVersion2Packet(int i, int i2, int i3, byte[] bArr) {
        return new SymmetricEncIntegrityPacket(2, i, i2, i3, bArr);
    }

    @Override // org.bouncycastle.bcpg.BCPGHeaderObject
    public void encode(BCPGOutputStream bCPGOutputStream) throws IOException {
        bCPGOutputStream.write(getVersion());
        if (this.version == 2) {
            bCPGOutputStream.write(this.cipherAlgorithm);
            bCPGOutputStream.write(this.aeadAlgorithm);
            bCPGOutputStream.write(this.chunkSize);
            bCPGOutputStream.write(this.salt);
        }
    }

    public byte[] getAAData() {
        return createAAData(getVersion(), getCipherAlgorithm(), getAeadAlgorithm(), getChunkSize());
    }

    public int getAeadAlgorithm() {
        return this.aeadAlgorithm;
    }

    public int getChunkSize() {
        return this.chunkSize;
    }

    public int getCipherAlgorithm() {
        return this.cipherAlgorithm;
    }

    public byte[] getSalt() {
        return Arrays.copyOf(this.salt, this.salt.length);
    }

    @Override // org.bouncycastle.bcpg.BCPGHeaderObject
    public int getType() {
        return 18;
    }

    public int getVersion() {
        return this.version;
    }
}
