package org.bouncycastle.asn1;

/* JADX INFO: loaded from: E:\ios\vf_dex\classes4.dex */
public class DLBitStringParser implements org.bouncycastle.asn1.ASN1BitStringParser {
    private final org.bouncycastle.asn1.DefiniteLengthInputStream a;
    private int b = 0;

    DLBitStringParser(org.bouncycastle.asn1.DefiniteLengthInputStream definiteLengthInputStream) {
        this.a = definiteLengthInputStream;
    }

    private java.io.InputStream d(boolean z) throws java.io.IOException {
        int iE = this.a.e();
        if (iE < 1) {
            throw new java.lang.IllegalStateException("content octets cannot be empty");
        }
        int i = this.a.read();
        this.b = i;
        if (i > 0) {
            if (iE < 2) {
                throw new java.lang.IllegalStateException("zero length data with non-zero pad bits");
            }
            if (i > 7) {
                throw new java.lang.IllegalStateException("pad bits cannot be greater than 7 or less than 0");
            }
            if (z) {
                throw new java.io.IOException("expected octet-aligned bitstring, but found padBits: " + this.b);
            }
        }
        return this.a;
    }

    @Override // org.bouncycastle.asn1.InMemoryRepresentable
    public org.bouncycastle.asn1.ASN1Primitive a() {
        return org.bouncycastle.asn1.ASN1BitString.x(this.a.k());
    }

    @Override // org.bouncycastle.asn1.ASN1BitStringParser
    public java.io.InputStream e() {
        return d(false);
    }

    @Override // org.bouncycastle.asn1.ASN1BitStringParser
    public int i() {
        return this.b;
    }

    @Override // org.bouncycastle.asn1.ASN1Encodable
    public org.bouncycastle.asn1.ASN1Primitive j() {
        try {
            return a();
        } catch (java.io.IOException e) {
            throw new org.bouncycastle.asn1.ASN1ParsingException("IOException converting stream to byte array: " + e.getMessage(), e);
        }
    }
}
