package org.bouncycastle.asn1;

/* JADX INFO: loaded from: E:\ios\vf_dex\classes4.dex */
public abstract class ASN1External extends org.bouncycastle.asn1.ASN1Primitive {
    static final org.bouncycastle.asn1.ASN1UniversalType f = new org.bouncycastle.asn1.ASN1UniversalType(org.bouncycastle.asn1.ASN1External.class, 8) { // from class: org.bouncycastle.asn1.ASN1External.1
        @Override // org.bouncycastle.asn1.ASN1UniversalType
        org.bouncycastle.asn1.ASN1Primitive c(org.bouncycastle.asn1.ASN1Sequence aSN1Sequence) {
            return aSN1Sequence.F();
        }
    };
    org.bouncycastle.asn1.ASN1ObjectIdentifier a;
    org.bouncycastle.asn1.ASN1Integer b;
    org.bouncycastle.asn1.ASN1Primitive c;
    int d;
    org.bouncycastle.asn1.ASN1Primitive e;

    ASN1External(org.bouncycastle.asn1.ASN1ObjectIdentifier aSN1ObjectIdentifier, org.bouncycastle.asn1.ASN1Integer aSN1Integer, org.bouncycastle.asn1.ASN1Primitive aSN1Primitive, int i, org.bouncycastle.asn1.ASN1Primitive aSN1Primitive2) {
        this.a = aSN1ObjectIdentifier;
        this.b = aSN1Integer;
        this.c = aSN1Primitive;
        this.d = y(i);
        this.e = z(i, aSN1Primitive2);
    }

    private static org.bouncycastle.asn1.ASN1Primitive E(org.bouncycastle.asn1.ASN1TaggedObject aSN1TaggedObject) {
        org.bouncycastle.asn1.ASN1Util.a(aSN1TaggedObject);
        int iC = aSN1TaggedObject.c();
        if (iC == 0) {
            return aSN1TaggedObject.G().j();
        }
        if (iC == 1) {
            return org.bouncycastle.asn1.ASN1OctetString.z(aSN1TaggedObject, false);
        }
        if (iC == 2) {
            return org.bouncycastle.asn1.ASN1BitString.B(aSN1TaggedObject, false);
        }
        throw new java.lang.IllegalArgumentException("invalid tag: " + org.bouncycastle.asn1.ASN1Util.i(aSN1TaggedObject));
    }

    private static org.bouncycastle.asn1.ASN1Primitive G(org.bouncycastle.asn1.ASN1Sequence aSN1Sequence, int i) {
        if (aSN1Sequence.size() > i) {
            return aSN1Sequence.B(i).j();
        }
        throw new java.lang.IllegalArgumentException("too few objects in input sequence");
    }

    private static int y(int i) {
        if (i >= 0 && i <= 2) {
            return i;
        }
        throw new java.lang.IllegalArgumentException("invalid encoding value: " + i);
    }

    private static org.bouncycastle.asn1.ASN1Primitive z(int i, org.bouncycastle.asn1.ASN1Primitive aSN1Primitive) {
        org.bouncycastle.asn1.ASN1UniversalType aSN1UniversalType;
        if (i == 1) {
            aSN1UniversalType = org.bouncycastle.asn1.ASN1OctetString.b;
        } else {
            if (i != 2) {
                return aSN1Primitive;
            }
            aSN1UniversalType = org.bouncycastle.asn1.ASN1BitString.b;
        }
        return aSN1UniversalType.a(aSN1Primitive);
    }

    public org.bouncycastle.asn1.ASN1Primitive A() {
        return this.c;
    }

    public org.bouncycastle.asn1.ASN1ObjectIdentifier B() {
        return this.a;
    }

    public int C() {
        return this.d;
    }

    public org.bouncycastle.asn1.ASN1Primitive D() {
        return this.e;
    }

    public org.bouncycastle.asn1.ASN1Integer F() {
        return this.b;
    }

    @Override // org.bouncycastle.asn1.ASN1Primitive, org.bouncycastle.asn1.ASN1Object
    public int hashCode() {
        return this.e.hashCode() ^ (((org.bouncycastle.util.Objects.b(this.a) ^ org.bouncycastle.util.Objects.b(this.b)) ^ org.bouncycastle.util.Objects.b(this.c)) ^ this.d);
    }

    @Override // org.bouncycastle.asn1.ASN1Primitive
    boolean n(org.bouncycastle.asn1.ASN1Primitive aSN1Primitive) {
        if (this == aSN1Primitive) {
            return true;
        }
        if (!(aSN1Primitive instanceof org.bouncycastle.asn1.ASN1External)) {
            return false;
        }
        org.bouncycastle.asn1.ASN1External aSN1External = (org.bouncycastle.asn1.ASN1External) aSN1Primitive;
        return org.bouncycastle.util.Objects.a(this.a, aSN1External.a) && org.bouncycastle.util.Objects.a(this.b, aSN1External.b) && org.bouncycastle.util.Objects.a(this.c, aSN1External.c) && this.d == aSN1External.d && this.e.t(aSN1External.e);
    }

    @Override // org.bouncycastle.asn1.ASN1Primitive
    void o(org.bouncycastle.asn1.ASN1OutputStream aSN1OutputStream, boolean z) throws java.io.IOException {
        aSN1OutputStream.s(z, 40);
        x().o(aSN1OutputStream, false);
    }

    @Override // org.bouncycastle.asn1.ASN1Primitive
    boolean p() {
        return true;
    }

    @Override // org.bouncycastle.asn1.ASN1Primitive
    int r(boolean z) {
        return x().r(z);
    }

    @Override // org.bouncycastle.asn1.ASN1Primitive
    org.bouncycastle.asn1.ASN1Primitive v() {
        return new org.bouncycastle.asn1.DERExternal(this.a, this.b, this.c, this.d, this.e);
    }

    @Override // org.bouncycastle.asn1.ASN1Primitive
    org.bouncycastle.asn1.ASN1Primitive w() {
        return new org.bouncycastle.asn1.DLExternal(this.a, this.b, this.c, this.d, this.e);
    }

    abstract org.bouncycastle.asn1.ASN1Sequence x();

    ASN1External(org.bouncycastle.asn1.ASN1Sequence aSN1Sequence) {
        int i = 0;
        org.bouncycastle.asn1.ASN1Primitive aSN1PrimitiveG = G(aSN1Sequence, 0);
        if (aSN1PrimitiveG instanceof org.bouncycastle.asn1.ASN1ObjectIdentifier) {
            this.a = (org.bouncycastle.asn1.ASN1ObjectIdentifier) aSN1PrimitiveG;
            aSN1PrimitiveG = G(aSN1Sequence, 1);
            i = 1;
        }
        if (aSN1PrimitiveG instanceof org.bouncycastle.asn1.ASN1Integer) {
            this.b = (org.bouncycastle.asn1.ASN1Integer) aSN1PrimitiveG;
            i++;
            aSN1PrimitiveG = G(aSN1Sequence, i);
        }
        if (!(aSN1PrimitiveG instanceof org.bouncycastle.asn1.ASN1TaggedObject)) {
            this.c = aSN1PrimitiveG;
            i++;
            aSN1PrimitiveG = G(aSN1Sequence, i);
        }
        if (aSN1Sequence.size() != i + 1) {
            throw new java.lang.IllegalArgumentException("input sequence too large");
        }
        if (!(aSN1PrimitiveG instanceof org.bouncycastle.asn1.ASN1TaggedObject)) {
            throw new java.lang.IllegalArgumentException("No tagged object found in sequence. Structure doesn't seem to be of type External");
        }
        org.bouncycastle.asn1.ASN1TaggedObject aSN1TaggedObject = (org.bouncycastle.asn1.ASN1TaggedObject) aSN1PrimitiveG;
        this.d = y(aSN1TaggedObject.c());
        this.e = E(aSN1TaggedObject);
    }
}
