package org.bouncycastle.bcpg;

import java.io.IOException;
import java.security.SecureRandom;
import org.bouncycastle.util.Arrays;
import org.bouncycastle.util.io.Streams;

/* JADX INFO: loaded from: classes.dex */
public class PaddingPacket extends ContainedPacket {
    private final byte[] padding;

    public PaddingPacket(int i, SecureRandom secureRandom) {
        this(randomBytes(i, secureRandom));
    }

    public PaddingPacket(BCPGInputStream bCPGInputStream) throws IOException {
        this(bCPGInputStream, true);
    }

    public PaddingPacket(BCPGInputStream bCPGInputStream, boolean z) throws IOException {
        super(21, z);
        this.padding = Streams.readAll(bCPGInputStream);
    }

    public PaddingPacket(byte[] bArr) {
        super(21, true);
        this.padding = bArr;
    }

    private static byte[] randomBytes(int i, SecureRandom secureRandom) {
        if (i <= 0) {
            throw new IllegalArgumentException("Octet count MUST NOT be 0 nor negative.");
        }
        byte[] bArr = new byte[i];
        secureRandom.nextBytes(bArr);
        return bArr;
    }

    @Override // org.bouncycastle.bcpg.ContainedPacket
    public void encode(BCPGOutputStream bCPGOutputStream) throws IOException {
        bCPGOutputStream.writePacket(hasNewPacketFormat(), 21, this.padding);
    }

    public byte[] getPadding() {
        return Arrays.clone(this.padding);
    }
}
