package o4;

import androidx.media3.extractor.AacUtil;
import androidx.media3.extractor.ts.PsExtractor;
import com.google.firebase.firestore.index.FirestoreIndexValueWriter;
import javax.security.auth.x500.X500Principal;

/* JADX INFO: loaded from: classes3.dex */
public final class d {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final String f21839a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final int f21840b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public int f21841c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public int f21842d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public int f21843e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public int f21844f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public char[] f21845g;

    public d(X500Principal x500Principal) {
        String name = x500Principal.getName("RFC2253");
        this.f21839a = name;
        this.f21840b = name.length();
    }

    public final int a(int i6) {
        int i7;
        int i8;
        int i9 = i6 + 1;
        int i10 = this.f21840b;
        String str = this.f21839a;
        if (i9 >= i10) {
            throw new IllegalStateException("Malformed DN: " + str);
        }
        char[] cArr = this.f21845g;
        char c6 = cArr[i6];
        if (c6 >= '0' && c6 <= '9') {
            i7 = c6 - '0';
        } else if (c6 >= 'a' && c6 <= 'f') {
            i7 = c6 - 'W';
        } else {
            if (c6 < 'A' || c6 > 'F') {
                throw new IllegalStateException("Malformed DN: " + str);
            }
            i7 = c6 - '7';
        }
        char c7 = cArr[i9];
        if (c7 >= '0' && c7 <= '9') {
            i8 = c7 - '0';
        } else if (c7 >= 'a' && c7 <= 'f') {
            i8 = c7 - 'W';
        } else {
            if (c7 < 'A' || c7 > 'F') {
                throw new IllegalStateException("Malformed DN: " + str);
            }
            i8 = c7 - '7';
        }
        return (i7 << 4) + i8;
    }

    public final char b() {
        int i6;
        int i7;
        int i8 = this.f21841c + 1;
        this.f21841c = i8;
        int i9 = this.f21840b;
        if (i8 == i9) {
            throw new IllegalStateException("Unexpected end of DN: " + this.f21839a);
        }
        char c6 = this.f21845g[i8];
        if (c6 != ' ' && c6 != '%' && c6 != '\\' && c6 != '_' && c6 != '\"' && c6 != '#') {
            switch (c6) {
                default:
                    switch (c6) {
                        case ';':
                        case FirestoreIndexValueWriter.INDEX_TYPE_REFERENCE_SEGMENT /* 60 */:
                        case '=':
                        case '>':
                            break;
                        default:
                            int iA = a(i8);
                            this.f21841c++;
                            if (iA < 128) {
                                return (char) iA;
                            }
                            if (iA < 192 || iA > 247) {
                                return '?';
                            }
                            if (iA <= 223) {
                                i6 = iA & 31;
                                i7 = 1;
                            } else if (iA <= 239) {
                                i6 = iA & 15;
                                i7 = 2;
                            } else {
                                i6 = iA & 7;
                                i7 = 3;
                            }
                            for (int i10 = 0; i10 < i7; i10++) {
                                int i11 = this.f21841c;
                                int i12 = i11 + 1;
                                this.f21841c = i12;
                                if (i12 == i9 || this.f21845g[i12] != '\\') {
                                    return '?';
                                }
                                int i13 = i11 + 2;
                                this.f21841c = i13;
                                int iA2 = a(i13);
                                this.f21841c++;
                                if ((iA2 & PsExtractor.AUDIO_STREAM) != 128) {
                                    return '?';
                                }
                                i6 = (i6 << 6) + (iA2 & 63);
                            }
                            return (char) i6;
                    }
                case AacUtil.AUDIO_OBJECT_TYPE_AAC_XHE /* 42 */:
                case '+':
                case ',':
                    return c6;
            }
        }
        return c6;
    }

    public final String c() {
        int i6;
        int i7;
        int i8;
        char c6;
        int i9;
        char c7;
        char c8;
        while (true) {
            i6 = this.f21841c;
            i7 = this.f21840b;
            if (i6 >= i7 || this.f21845g[i6] != ' ') {
                break;
            }
            this.f21841c = i6 + 1;
        }
        if (i6 == i7) {
            return null;
        }
        this.f21842d = i6;
        this.f21841c = i6 + 1;
        while (true) {
            i8 = this.f21841c;
            if (i8 >= i7 || (c8 = this.f21845g[i8]) == '=' || c8 == ' ') {
                break;
            }
            this.f21841c = i8 + 1;
        }
        String str = this.f21839a;
        if (i8 >= i7) {
            throw new IllegalStateException("Unexpected end of DN: " + str);
        }
        this.f21843e = i8;
        if (this.f21845g[i8] == ' ') {
            while (true) {
                i9 = this.f21841c;
                if (i9 >= i7 || (c7 = this.f21845g[i9]) == '=' || c7 != ' ') {
                    break;
                }
                this.f21841c = i9 + 1;
            }
            if (this.f21845g[i9] != '=' || i9 == i7) {
                throw new IllegalStateException("Unexpected end of DN: " + str);
            }
        }
        this.f21841c++;
        while (true) {
            int i10 = this.f21841c;
            if (i10 >= i7 || this.f21845g[i10] != ' ') {
                break;
            }
            this.f21841c = i10 + 1;
        }
        int i11 = this.f21843e;
        int i12 = this.f21842d;
        if (i11 - i12 > 4) {
            char[] cArr = this.f21845g;
            if (cArr[i12 + 3] == '.' && (((c6 = cArr[i12]) == 'O' || c6 == 'o') && ((cArr[i12 + 1] == 'I' || cArr[i12 + 1] == 'i') && (cArr[i12 + 2] == 'D' || cArr[i12 + 2] == 'd')))) {
                this.f21842d = i12 + 4;
            }
        }
        char[] cArr2 = this.f21845g;
        int i13 = this.f21842d;
        return new String(cArr2, i13, i11 - i13);
    }
}
