what-the-bank/sources/okhttp3/internal/HostnamesKt.java

245 lines
7.3 KiB
Java
Raw Normal View History

2024-07-27 18:17:47 +07:00
package okhttp3.internal;
import java.net.IDN;
import java.net.InetAddress;
import java.util.Locale;
import o.C14957gcv;
import o.C15111ghZ;
import o.gdP;
import o.gdZ;
/* loaded from: classes.dex */
public final class HostnamesKt {
public static final String toCanonicalHost(String str) {
InetAddress decodeIpv6;
C14957gcv.e(str, "");
if (!gdZ.d((CharSequence) str, (CharSequence) ":", false)) {
try {
String ascii = IDN.toASCII(str);
C14957gcv.c((Object) ascii, "");
Locale locale = Locale.US;
C14957gcv.c(locale, "");
String lowerCase = ascii.toLowerCase(locale);
C14957gcv.c((Object) lowerCase, "");
if (lowerCase.length() == 0) {
return null;
}
if (containsInvalidHostnameAsciiCodes(lowerCase)) {
return null;
}
return lowerCase;
} catch (IllegalArgumentException unused) {
return null;
}
}
if (gdZ.e(str, "[", false) && gdZ.d(str, "]", false)) {
decodeIpv6 = decodeIpv6(str, 1, str.length() - 1);
} else {
decodeIpv6 = decodeIpv6(str, 0, str.length());
}
if (decodeIpv6 == null) {
return null;
}
byte[] address = decodeIpv6.getAddress();
if (address.length == 16) {
C14957gcv.c(address, "");
return inet6AddressToAscii(address);
}
if (address.length == 4) {
return decodeIpv6.getHostAddress();
}
StringBuilder sb = new StringBuilder("Invalid IPv6 address: '");
sb.append(str);
sb.append('\'');
throw new AssertionError(sb.toString());
}
private static final boolean containsInvalidHostnameAsciiCodes(String str) {
int length = str.length();
for (int i = 0; i < length; i++) {
char charAt = str.charAt(i);
if (C14957gcv.a(charAt, 31) <= 0 || C14957gcv.a(charAt, 127) >= 0 || gdZ.a((CharSequence) " #%/:?@[\\]", charAt, 0, false) != -1) {
return true;
}
}
return false;
}
/* JADX WARN: Code restructure failed: missing block: B:25:0x0072, code lost:
return null;
*/
/* JADX WARN: Removed duplicated region for block: B:15:0x004d */
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct add '--show-bad-code' argument
*/
private static final java.net.InetAddress decodeIpv6(java.lang.String r11, int r12, int r13) {
/*
r0 = 16
byte[] r1 = new byte[r0]
r2 = -1
r3 = 0
r5 = r2
r6 = r5
r4 = r3
L9:
r7 = 0
if (r12 >= r13) goto L73
if (r4 != r0) goto Lf
return r7
Lf:
int r8 = r12 + 2
if (r8 > r13) goto L26
java.lang.String r9 = "::"
boolean r9 = o.gdZ.a(r11, r9, r12, r3)
if (r9 == 0) goto L26
if (r5 == r2) goto L1e
return r7
L1e:
int r4 = r4 + 2
r5 = r4
if (r8 != r13) goto L24
goto L73
L24:
r6 = r8
goto L49
L26:
if (r4 == 0) goto L48
java.lang.String r8 = ":"
boolean r8 = o.gdZ.a(r11, r8, r12, r3)
if (r8 == 0) goto L33
int r12 = r12 + 1
goto L48
L33:
java.lang.String r8 = "."
boolean r12 = o.gdZ.a(r11, r8, r12, r3)
if (r12 == 0) goto L47
int r12 = r4 + (-2)
boolean r11 = decodeIpv4Suffix(r11, r6, r13, r1, r12)
if (r11 != 0) goto L44
return r7
L44:
int r4 = r4 + 2
goto L73
L47:
return r7
L48:
r6 = r12
L49:
r8 = r3
r12 = r6
L4b:
if (r12 >= r13) goto L5d
char r9 = r11.charAt(r12)
int r9 = okhttp3.internal.Util.parseHexDigit(r9)
if (r9 == r2) goto L5d
int r8 = r8 << 4
int r8 = r8 + r9
int r12 = r12 + 1
goto L4b
L5d:
int r9 = r12 - r6
if (r9 == 0) goto L72
r10 = 4
if (r9 > r10) goto L72
int r7 = r8 >>> 8
byte r7 = (byte) r7
r1[r4] = r7
int r7 = r4 + 2
byte r8 = (byte) r8
int r4 = r4 + 1
r1[r4] = r8
r4 = r7
goto L9
L72:
return r7
L73:
if (r4 == r0) goto L84
if (r5 != r2) goto L78
return r7
L78:
int r11 = r4 - r5
int r12 = 16 - r11
java.lang.System.arraycopy(r1, r5, r1, r12, r11)
int r0 = r0 - r4
int r0 = r0 + r5
java.util.Arrays.fill(r1, r5, r0, r3)
L84:
java.net.InetAddress r11 = java.net.InetAddress.getByAddress(r1)
return r11
*/
throw new UnsupportedOperationException("Method not decompiled: okhttp3.internal.HostnamesKt.decodeIpv6(java.lang.String, int, int):java.net.InetAddress");
}
private static final boolean decodeIpv4Suffix(String str, int i, int i2, byte[] bArr, int i3) {
int i4 = i3;
while (i < i2) {
if (i4 == bArr.length) {
return false;
}
if (i4 != i3) {
if (str.charAt(i) != '.') {
return false;
}
i++;
}
int i5 = i;
int i6 = 0;
while (i5 < i2) {
char charAt = str.charAt(i5);
if (C14957gcv.a(charAt, 48) < 0 || C14957gcv.a(charAt, 57) > 0) {
break;
}
if ((i6 == 0 && i != i5) || (i6 = ((i6 * 10) + charAt) - 48) > 255) {
return false;
}
i5++;
}
if (i5 - i == 0) {
return false;
}
bArr[i4] = (byte) i6;
i4++;
i = i5;
}
return i4 == i3 + 4;
}
private static final String inet6AddressToAscii(byte[] bArr) {
int i = -1;
int i2 = 0;
int i3 = 0;
int i4 = 0;
while (i3 < bArr.length) {
int i5 = i3;
while (i5 < 16 && bArr[i5] == 0 && bArr[i5 + 1] == 0) {
i5 += 2;
}
int i6 = i5 - i3;
if (i6 > i4 && i6 >= 4) {
i = i3;
i4 = i6;
}
i3 = i5 + 2;
}
C15111ghZ c15111ghZ = new C15111ghZ();
while (i2 < bArr.length) {
if (i2 == i) {
c15111ghZ.b(58);
i2 += i4;
if (i2 == 16) {
c15111ghZ.b(58);
}
} else {
if (i2 > 0) {
c15111ghZ.b(58);
}
c15111ghZ.l((Util.and(bArr[i2], 255) << 8) | Util.and(bArr[i2 + 1], 255));
i2 += 2;
}
}
return c15111ghZ.b(c15111ghZ.c, gdP.a);
}
}