what-the-bank/sources/okhttp3/Cookie.java

509 lines
19 KiB
Java

package okhttp3;
import com.google.android.gms.auth.api.credentials.CredentialsApi;
import com.google.common.net.HttpHeaders;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import o.C14851gaI;
import o.C14953gcr;
import o.C14957gcv;
import o.gdW;
import o.gdZ;
import okhttp3.internal.HostnamesKt;
import okhttp3.internal.Util;
import okhttp3.internal.http.DatesKt;
/* loaded from: classes.dex */
public final class Cookie {
private final String domain;
private final long expiresAt;
private final boolean hostOnly;
private final boolean httpOnly;
private final String name;
private final String path;
private final boolean persistent;
private final boolean secure;
private final String value;
public static final Companion Companion = new Companion(null);
private static final Pattern YEAR_PATTERN = Pattern.compile("(\\d{2,4})[^\\d]*");
private static final Pattern MONTH_PATTERN = Pattern.compile("(?i)(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec).*");
private static final Pattern DAY_OF_MONTH_PATTERN = Pattern.compile("(\\d{1,2})[^\\d]*");
private static final Pattern TIME_PATTERN = Pattern.compile("(\\d{1,2}):(\\d{1,2}):(\\d{1,2})[^\\d]*");
private Cookie(String str, String str2, long j, String str3, String str4, boolean z, boolean z2, boolean z3, boolean z4) {
this.name = str;
this.value = str2;
this.expiresAt = j;
this.domain = str3;
this.path = str4;
this.secure = z;
this.httpOnly = z2;
this.persistent = z3;
this.hostOnly = z4;
}
public final boolean matches(HttpUrl httpUrl) {
boolean domainMatch;
C14957gcv.e(httpUrl, "");
if (this.hostOnly) {
domainMatch = C14957gcv.b((Object) httpUrl.host(), (Object) this.domain);
} else {
domainMatch = Companion.domainMatch(httpUrl.host(), this.domain);
}
if (domainMatch && Companion.pathMatch(httpUrl, this.path)) {
return !this.secure || httpUrl.isHttps();
}
return false;
}
public final boolean equals(Object obj) {
if (obj instanceof Cookie) {
Cookie cookie = (Cookie) obj;
if (C14957gcv.b((Object) cookie.name, (Object) this.name) && C14957gcv.b((Object) cookie.value, (Object) this.value) && cookie.expiresAt == this.expiresAt && C14957gcv.b((Object) cookie.domain, (Object) this.domain) && C14957gcv.b((Object) cookie.path, (Object) this.path) && cookie.secure == this.secure && cookie.httpOnly == this.httpOnly && cookie.persistent == this.persistent && cookie.hostOnly == this.hostOnly) {
return true;
}
}
return false;
}
public final int hashCode() {
int hashCode = this.name.hashCode();
int hashCode2 = this.value.hashCode();
int hashCode3 = Long.hashCode(this.expiresAt);
int hashCode4 = this.domain.hashCode();
int hashCode5 = this.path.hashCode();
int hashCode6 = Boolean.hashCode(this.secure);
int hashCode7 = Boolean.hashCode(this.httpOnly);
return ((((((((((((((((hashCode + 527) * 31) + hashCode2) * 31) + hashCode3) * 31) + hashCode4) * 31) + hashCode5) * 31) + hashCode6) * 31) + hashCode7) * 31) + Boolean.hashCode(this.persistent)) * 31) + Boolean.hashCode(this.hostOnly);
}
public final String toString() {
return toString$okhttp(false);
}
public final String toString$okhttp(boolean z) {
StringBuilder sb = new StringBuilder();
sb.append(name());
sb.append('=');
sb.append(value());
if (persistent()) {
if (expiresAt() == Long.MIN_VALUE) {
sb.append("; max-age=0");
} else {
sb.append("; expires=");
sb.append(DatesKt.toHttpDateString(new Date(expiresAt())));
}
}
if (!hostOnly()) {
sb.append("; domain=");
if (z) {
sb.append(".");
}
sb.append(domain());
}
sb.append("; path=");
sb.append(path());
if (secure()) {
sb.append("; secure");
}
if (httpOnly()) {
sb.append("; httponly");
}
String obj = sb.toString();
C14957gcv.c((Object) obj, "");
return obj;
}
/* loaded from: classes6.dex */
public static final class Builder {
private String domain;
private boolean hostOnly;
private boolean httpOnly;
private String name;
private boolean persistent;
private boolean secure;
private String value;
private long expiresAt = 253402300799999L;
private String path = "/";
public final Builder name(String str) {
C14957gcv.e(str, "");
if (!C14957gcv.b((Object) gdZ.b((CharSequence) str).toString(), (Object) str)) {
throw new IllegalArgumentException("name is not trimmed".toString());
}
this.name = str;
return this;
}
public final Builder value(String str) {
C14957gcv.e(str, "");
if (!C14957gcv.b((Object) gdZ.b((CharSequence) str).toString(), (Object) str)) {
throw new IllegalArgumentException("value is not trimmed".toString());
}
this.value = str;
return this;
}
public final Builder expiresAt(long j) {
if (j <= 0) {
j = Long.MIN_VALUE;
}
if (j > 253402300799999L) {
j = 253402300799999L;
}
this.expiresAt = j;
this.persistent = true;
return this;
}
public final Builder domain(String str) {
C14957gcv.e(str, "");
return domain(str, false);
}
public final Builder hostOnlyDomain(String str) {
C14957gcv.e(str, "");
return domain(str, true);
}
private final Builder domain(String str, boolean z) {
String canonicalHost = HostnamesKt.toCanonicalHost(str);
if (canonicalHost == null) {
throw new IllegalArgumentException(C14957gcv.c("unexpected domain: ", (Object) str));
}
this.domain = canonicalHost;
this.hostOnly = z;
return this;
}
public final Builder path(String str) {
C14957gcv.e(str, "");
if (!gdZ.e(str, "/", false)) {
throw new IllegalArgumentException("path must start with '/'".toString());
}
this.path = str;
return this;
}
public final Builder secure() {
this.secure = true;
return this;
}
public final Builder httpOnly() {
this.httpOnly = true;
return this;
}
public final Cookie build() {
String str = this.name;
if (str == null) {
throw new NullPointerException("builder.name == null");
}
String str2 = this.value;
if (str2 == null) {
throw new NullPointerException("builder.value == null");
}
long j = this.expiresAt;
String str3 = this.domain;
if (str3 != null) {
return new Cookie(str, str2, j, str3, this.path, this.secure, this.httpOnly, this.persistent, this.hostOnly, null);
}
throw new NullPointerException("builder.domain == null");
}
}
/* loaded from: classes.dex */
public static final class Companion {
private Companion() {
}
/* JADX INFO: Access modifiers changed from: private */
public final boolean domainMatch(String str, String str2) {
if (C14957gcv.b((Object) str, (Object) str2)) {
return true;
}
return gdZ.d(str, str2, false) && str.charAt((str.length() - str2.length()) - 1) == '.' && !Util.canParseAsIpAddress(str);
}
/* JADX INFO: Access modifiers changed from: private */
public final boolean pathMatch(HttpUrl httpUrl, String str) {
String encodedPath = httpUrl.encodedPath();
if (C14957gcv.b((Object) encodedPath, (Object) str)) {
return true;
}
return gdZ.e(encodedPath, str, false) && (gdZ.d(str, "/", false) || encodedPath.charAt(str.length()) == '/');
}
public final Cookie parse(HttpUrl httpUrl, String str) {
C14957gcv.e(httpUrl, "");
C14957gcv.e(str, "");
return parse$okhttp(System.currentTimeMillis(), httpUrl, str);
}
/* JADX WARN: Code restructure failed: missing block: B:59:0x00fd, code lost:
if (r1 > 253402300799999L) goto L57;
*/
/* JADX WARN: Removed duplicated region for block: B:63:0x0111 */
/* JADX WARN: Removed duplicated region for block: B:78:0x015b */
/* JADX WARN: Removed duplicated region for block: B:80:0x0114 */
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct add '--show-bad-code' argument
*/
public final okhttp3.Cookie parse$okhttp(long r26, okhttp3.HttpUrl r28, java.lang.String r29) {
/*
Method dump skipped, instructions count: 369
To view this dump add '--comments-level debug' option
*/
throw new UnsupportedOperationException("Method not decompiled: okhttp3.Cookie.Companion.parse$okhttp(long, okhttp3.HttpUrl, java.lang.String):okhttp3.Cookie");
}
private final long parseExpires(String str, int i, int i2) {
int dateCharacterOffset = dateCharacterOffset(str, i, i2, false);
Matcher matcher = Cookie.TIME_PATTERN.matcher(str);
int i3 = -1;
int i4 = -1;
int i5 = -1;
int i6 = -1;
int i7 = -1;
int i8 = -1;
while (dateCharacterOffset < i2) {
int dateCharacterOffset2 = dateCharacterOffset(str, dateCharacterOffset + 1, i2, true);
matcher.region(dateCharacterOffset, dateCharacterOffset2);
if (i4 == -1 && matcher.usePattern(Cookie.TIME_PATTERN).matches()) {
String group = matcher.group(1);
C14957gcv.c((Object) group, "");
i4 = Integer.parseInt(group);
String group2 = matcher.group(2);
C14957gcv.c((Object) group2, "");
i7 = Integer.parseInt(group2);
String group3 = matcher.group(3);
C14957gcv.c((Object) group3, "");
i8 = Integer.parseInt(group3);
} else if (i5 == -1 && matcher.usePattern(Cookie.DAY_OF_MONTH_PATTERN).matches()) {
String group4 = matcher.group(1);
C14957gcv.c((Object) group4, "");
i5 = Integer.parseInt(group4);
} else if (i6 == -1 && matcher.usePattern(Cookie.MONTH_PATTERN).matches()) {
String group5 = matcher.group(1);
C14957gcv.c((Object) group5, "");
Locale locale = Locale.US;
C14957gcv.c(locale, "");
String lowerCase = group5.toLowerCase(locale);
C14957gcv.c((Object) lowerCase, "");
String pattern = Cookie.MONTH_PATTERN.pattern();
C14957gcv.c((Object) pattern, "");
i6 = gdZ.e((CharSequence) pattern, lowerCase, 0, false) / 4;
} else if (i3 == -1 && matcher.usePattern(Cookie.YEAR_PATTERN).matches()) {
String group6 = matcher.group(1);
C14957gcv.c((Object) group6, "");
i3 = Integer.parseInt(group6);
}
dateCharacterOffset = dateCharacterOffset(str, dateCharacterOffset2 + 1, i2, false);
}
if (70 <= i3 && i3 < 100) {
i3 += 1900;
}
if (i3 >= 0 && i3 < 70) {
i3 += CredentialsApi.CREDENTIAL_PICKER_REQUEST_CODE;
}
if (i3 < 1601) {
throw new IllegalArgumentException("Failed requirement.".toString());
}
if (i6 == -1) {
throw new IllegalArgumentException("Failed requirement.".toString());
}
if (i5 <= 0 || i5 >= 32) {
throw new IllegalArgumentException("Failed requirement.".toString());
}
if (i4 < 0 || i4 >= 24) {
throw new IllegalArgumentException("Failed requirement.".toString());
}
if (i7 < 0 || i7 >= 60) {
throw new IllegalArgumentException("Failed requirement.".toString());
}
if (i8 < 0 || i8 >= 60) {
throw new IllegalArgumentException("Failed requirement.".toString());
}
GregorianCalendar gregorianCalendar = new GregorianCalendar(Util.UTC);
gregorianCalendar.setLenient(false);
gregorianCalendar.set(1, i3);
gregorianCalendar.set(2, i6 - 1);
gregorianCalendar.set(5, i5);
gregorianCalendar.set(11, i4);
gregorianCalendar.set(12, i7);
gregorianCalendar.set(13, i8);
gregorianCalendar.set(14, 0);
return gregorianCalendar.getTimeInMillis();
}
private final int dateCharacterOffset(String str, int i, int i2, boolean z) {
while (i < i2) {
char charAt = str.charAt(i);
if (((charAt < ' ' && charAt != '\t') || charAt >= 127 || (charAt <= '9' && '0' <= charAt) || ((charAt <= 'z' && 'a' <= charAt) || ((charAt <= 'Z' && 'A' <= charAt) || charAt == ':'))) == (!z)) {
return i;
}
i++;
}
return i2;
}
private final long parseMaxAge(String str) {
try {
long parseLong = Long.parseLong(str);
if (parseLong > 0) {
return parseLong;
}
return Long.MIN_VALUE;
} catch (NumberFormatException e) {
String str2 = str;
gdW gdw = new gdW("-?\\d+");
C14957gcv.e(str2, "");
if (gdw.e.matcher(str2).matches()) {
return !gdZ.e(str, "-", false) ? Long.MAX_VALUE : Long.MIN_VALUE;
}
throw e;
}
}
public final List<Cookie> parseAll(HttpUrl httpUrl, Headers headers) {
C14957gcv.e(httpUrl, "");
C14957gcv.e(headers, "");
List<String> values = headers.values(HttpHeaders.SET_COOKIE);
int size = values.size();
ArrayList arrayList = null;
for (int i = 0; i < size; i++) {
Cookie parse = parse(httpUrl, values.get(i));
if (parse != null) {
if (arrayList == null) {
arrayList = new ArrayList();
}
arrayList.add(parse);
}
}
if (arrayList != null) {
List<Cookie> unmodifiableList = Collections.unmodifiableList(arrayList);
C14957gcv.c(unmodifiableList, "");
return unmodifiableList;
}
return C14851gaI.c;
}
private final String parseDomain(String str) {
if (!(!gdZ.d(str, ".", false))) {
throw new IllegalArgumentException("Failed requirement.".toString());
}
String canonicalHost = HostnamesKt.toCanonicalHost(gdZ.b(str, "."));
if (canonicalHost != null) {
return canonicalHost;
}
throw new IllegalArgumentException();
}
public /* synthetic */ Companion(C14953gcr c14953gcr) {
this();
}
}
public final String value() {
return this.value;
}
public final boolean secure() {
return this.secure;
}
public final boolean persistent() {
return this.persistent;
}
public final String path() {
return this.path;
}
public final String name() {
return this.name;
}
public final boolean httpOnly() {
return this.httpOnly;
}
public final boolean hostOnly() {
return this.hostOnly;
}
public final long expiresAt() {
return this.expiresAt;
}
public final String domain() {
return this.domain;
}
/* renamed from: -deprecated_value, reason: not valid java name */
public final String m395deprecated_value() {
return this.value;
}
/* renamed from: -deprecated_secure, reason: not valid java name */
public final boolean m394deprecated_secure() {
return this.secure;
}
/* renamed from: -deprecated_persistent, reason: not valid java name */
public final boolean m393deprecated_persistent() {
return this.persistent;
}
/* renamed from: -deprecated_path, reason: not valid java name */
public final String m392deprecated_path() {
return this.path;
}
/* renamed from: -deprecated_name, reason: not valid java name */
public final String m391deprecated_name() {
return this.name;
}
/* renamed from: -deprecated_httpOnly, reason: not valid java name */
public final boolean m390deprecated_httpOnly() {
return this.httpOnly;
}
/* renamed from: -deprecated_hostOnly, reason: not valid java name */
public final boolean m389deprecated_hostOnly() {
return this.hostOnly;
}
/* renamed from: -deprecated_expiresAt, reason: not valid java name */
public final long m388deprecated_expiresAt() {
return this.expiresAt;
}
/* renamed from: -deprecated_domain, reason: not valid java name */
public final String m387deprecated_domain() {
return this.domain;
}
public static final List<Cookie> parseAll(HttpUrl httpUrl, Headers headers) {
return Companion.parseAll(httpUrl, headers);
}
public static final Cookie parse(HttpUrl httpUrl, String str) {
return Companion.parse(httpUrl, str);
}
public /* synthetic */ Cookie(String str, String str2, long j, String str3, String str4, boolean z, boolean z2, boolean z3, boolean z4, C14953gcr c14953gcr) {
this(str, str2, j, str3, str4, z, z2, z3, z4);
}
}