414 lines
14 KiB
Java
414 lines
14 KiB
Java
|
package okhttp3.repackaged;
|
||
|
|
||
|
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 okhttp3.repackaged.internal.Util;
|
||
|
import okhttp3.repackaged.internal.http.HttpDate;
|
||
|
|
||
|
/* loaded from: classes6.dex */
|
||
|
public final class Cookie {
|
||
|
private static final Pattern ahr = Pattern.compile("(\\d{2,4})[^\\d]*");
|
||
|
private static final Pattern ahs = Pattern.compile("(?i)(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec).*");
|
||
|
private static final Pattern aht = Pattern.compile("(\\d{1,2})[^\\d]*");
|
||
|
private static final Pattern ahu = Pattern.compile("(\\d{1,2}):(\\d{1,2}):(\\d{1,2})[^\\d]*");
|
||
|
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;
|
||
|
|
||
|
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.hostOnly = z3;
|
||
|
this.persistent = z4;
|
||
|
}
|
||
|
|
||
|
private Cookie(Builder builder) {
|
||
|
if (builder.name == null) {
|
||
|
throw new IllegalArgumentException("builder.name == null");
|
||
|
}
|
||
|
if (builder.value == null) {
|
||
|
throw new IllegalArgumentException("builder.value == null");
|
||
|
}
|
||
|
if (builder.domain == null) {
|
||
|
throw new IllegalArgumentException("builder.domain == null");
|
||
|
}
|
||
|
this.name = builder.name;
|
||
|
this.value = builder.value;
|
||
|
this.expiresAt = builder.expiresAt;
|
||
|
this.domain = builder.domain;
|
||
|
this.path = builder.path;
|
||
|
this.secure = builder.secure;
|
||
|
this.httpOnly = builder.httpOnly;
|
||
|
this.persistent = builder.persistent;
|
||
|
this.hostOnly = builder.hostOnly;
|
||
|
}
|
||
|
|
||
|
public final boolean matches(HttpUrl httpUrl) {
|
||
|
boolean a;
|
||
|
if (this.hostOnly) {
|
||
|
a = httpUrl.host().equals(this.domain);
|
||
|
} else {
|
||
|
a = a(httpUrl, this.domain);
|
||
|
}
|
||
|
if (a && b(httpUrl, this.path)) {
|
||
|
return !this.secure || httpUrl.isHttps();
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
private static boolean a(HttpUrl httpUrl, String str) {
|
||
|
String host = httpUrl.host();
|
||
|
if (host.equals(str)) {
|
||
|
return true;
|
||
|
}
|
||
|
return host.endsWith(str) && host.charAt((host.length() - str.length()) - 1) == '.' && !Util.verifyAsIpAddress(host);
|
||
|
}
|
||
|
|
||
|
private static boolean b(HttpUrl httpUrl, String str) {
|
||
|
String encodedPath = httpUrl.encodedPath();
|
||
|
if (encodedPath.equals(str)) {
|
||
|
return true;
|
||
|
}
|
||
|
if (encodedPath.startsWith(str)) {
|
||
|
return str.endsWith("/") || encodedPath.charAt(str.length()) == '/';
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
public static Cookie parse(HttpUrl httpUrl, String str) {
|
||
|
return a(System.currentTimeMillis(), httpUrl, str);
|
||
|
}
|
||
|
|
||
|
/* JADX WARN: Removed duplicated region for block: B:58:0x00dc */
|
||
|
/* JADX WARN: Removed duplicated region for block: B:68:0x0107 */
|
||
|
/* JADX WARN: Removed duplicated region for block: B:69:0x010d */
|
||
|
/* JADX WARN: Removed duplicated region for block: B:70:0x00e4 */
|
||
|
/*
|
||
|
Code decompiled incorrectly, please refer to instructions dump.
|
||
|
To view partially-correct add '--show-bad-code' argument
|
||
|
*/
|
||
|
static okhttp3.repackaged.Cookie a(long r23, okhttp3.repackaged.HttpUrl r25, java.lang.String r26) {
|
||
|
/*
|
||
|
Method dump skipped, instructions count: 277
|
||
|
To view this dump add '--comments-level debug' option
|
||
|
*/
|
||
|
throw new UnsupportedOperationException("Method not decompiled: okhttp3.repackaged.Cookie.a(long, okhttp3.repackaged.HttpUrl, java.lang.String):okhttp3.repackaged.Cookie");
|
||
|
}
|
||
|
|
||
|
private static long a(String str, int i, int i2) {
|
||
|
int a = a(str, i, i2, false);
|
||
|
Matcher matcher = ahu.matcher(str);
|
||
|
int i3 = -1;
|
||
|
int i4 = -1;
|
||
|
int i5 = -1;
|
||
|
int i6 = -1;
|
||
|
int i7 = -1;
|
||
|
int i8 = -1;
|
||
|
while (a < i2) {
|
||
|
int a2 = a(str, a + 1, i2, true);
|
||
|
matcher.region(a, a2);
|
||
|
if (i4 == -1 && matcher.usePattern(ahu).matches()) {
|
||
|
i4 = Integer.parseInt(matcher.group(1));
|
||
|
i7 = Integer.parseInt(matcher.group(2));
|
||
|
i8 = Integer.parseInt(matcher.group(3));
|
||
|
} else if (i5 == -1 && matcher.usePattern(aht).matches()) {
|
||
|
i5 = Integer.parseInt(matcher.group(1));
|
||
|
} else {
|
||
|
if (i6 == -1) {
|
||
|
Pattern pattern = ahs;
|
||
|
if (matcher.usePattern(pattern).matches()) {
|
||
|
i6 = pattern.pattern().indexOf(matcher.group(1).toLowerCase(Locale.US)) / 4;
|
||
|
}
|
||
|
}
|
||
|
if (i3 == -1 && matcher.usePattern(ahr).matches()) {
|
||
|
i3 = Integer.parseInt(matcher.group(1));
|
||
|
}
|
||
|
}
|
||
|
a = a(str, a2 + 1, i2, false);
|
||
|
}
|
||
|
if (i3 >= 70 && i3 <= 99) {
|
||
|
i3 += 1900;
|
||
|
}
|
||
|
if (i3 >= 0 && i3 <= 69) {
|
||
|
i3 += CredentialsApi.CREDENTIAL_PICKER_REQUEST_CODE;
|
||
|
}
|
||
|
if (i3 < 1601) {
|
||
|
throw new IllegalArgumentException();
|
||
|
}
|
||
|
if (i6 == -1) {
|
||
|
throw new IllegalArgumentException();
|
||
|
}
|
||
|
if (i5 <= 0 || i5 > 31) {
|
||
|
throw new IllegalArgumentException();
|
||
|
}
|
||
|
if (i4 < 0 || i4 > 23) {
|
||
|
throw new IllegalArgumentException();
|
||
|
}
|
||
|
if (i7 < 0 || i7 > 59) {
|
||
|
throw new IllegalArgumentException();
|
||
|
}
|
||
|
if (i8 < 0 || i8 > 59) {
|
||
|
throw new IllegalArgumentException();
|
||
|
}
|
||
|
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 static int a(String str, int i, int i2, boolean z) {
|
||
|
while (i < i2) {
|
||
|
char charAt = str.charAt(i);
|
||
|
if (((charAt < ' ' && charAt != '\t') || charAt >= 127 || (charAt >= '0' && charAt <= '9') || ((charAt >= 'a' && charAt <= 'z') || ((charAt >= 'A' && charAt <= 'Z') || charAt == ':'))) == (!z)) {
|
||
|
return i;
|
||
|
}
|
||
|
i++;
|
||
|
}
|
||
|
return i2;
|
||
|
}
|
||
|
|
||
|
private static long aR(String str) {
|
||
|
try {
|
||
|
long parseLong = Long.parseLong(str);
|
||
|
if (parseLong > 0) {
|
||
|
return parseLong;
|
||
|
}
|
||
|
return Long.MIN_VALUE;
|
||
|
} catch (NumberFormatException e) {
|
||
|
if (str.matches("-?\\d+")) {
|
||
|
return !str.startsWith("-") ? Long.MAX_VALUE : Long.MIN_VALUE;
|
||
|
}
|
||
|
throw e;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private static String aS(String str) {
|
||
|
if (str.endsWith(".")) {
|
||
|
throw new IllegalArgumentException();
|
||
|
}
|
||
|
if (str.startsWith(".")) {
|
||
|
str = str.substring(1);
|
||
|
}
|
||
|
String domainToAscii = Util.domainToAscii(str);
|
||
|
if (domainToAscii != null) {
|
||
|
return domainToAscii;
|
||
|
}
|
||
|
throw new IllegalArgumentException();
|
||
|
}
|
||
|
|
||
|
public static List<Cookie> parseAll(HttpUrl httpUrl, Headers 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) {
|
||
|
return Collections.unmodifiableList(arrayList);
|
||
|
}
|
||
|
return Collections.emptyList();
|
||
|
}
|
||
|
|
||
|
/* loaded from: classes6.dex */
|
||
|
public static final class Builder {
|
||
|
String domain;
|
||
|
boolean hostOnly;
|
||
|
boolean httpOnly;
|
||
|
String name;
|
||
|
boolean persistent;
|
||
|
boolean secure;
|
||
|
String value;
|
||
|
long expiresAt = 253402300799999L;
|
||
|
String path = "/";
|
||
|
|
||
|
public final Builder name(String str) {
|
||
|
if (str == null) {
|
||
|
throw new NullPointerException("name == null");
|
||
|
}
|
||
|
if (!str.trim().equals(str)) {
|
||
|
throw new IllegalArgumentException("name is not trimmed");
|
||
|
}
|
||
|
this.name = str;
|
||
|
return this;
|
||
|
}
|
||
|
|
||
|
public final Builder value(String str) {
|
||
|
if (str == null) {
|
||
|
throw new NullPointerException("value == null");
|
||
|
}
|
||
|
if (!str.trim().equals(str)) {
|
||
|
throw new IllegalArgumentException("value is not trimmed");
|
||
|
}
|
||
|
this.value = str;
|
||
|
return this;
|
||
|
}
|
||
|
|
||
|
public final Builder domain(String str) {
|
||
|
return d(str, false);
|
||
|
}
|
||
|
|
||
|
public final Builder hostOnlyDomain(String str) {
|
||
|
return d(str, true);
|
||
|
}
|
||
|
|
||
|
private Builder d(String str, boolean z) {
|
||
|
if (str == null) {
|
||
|
throw new IllegalArgumentException("domain == null");
|
||
|
}
|
||
|
String domainToAscii = Util.domainToAscii(str);
|
||
|
if (domainToAscii == null) {
|
||
|
throw new IllegalArgumentException("unexpected domain: ".concat(String.valueOf(str)));
|
||
|
}
|
||
|
this.domain = domainToAscii;
|
||
|
this.hostOnly = z;
|
||
|
return this;
|
||
|
}
|
||
|
|
||
|
public final Builder path(String str) {
|
||
|
if (!str.startsWith("/")) {
|
||
|
throw new IllegalArgumentException("path must start with '/'");
|
||
|
}
|
||
|
this.path = str;
|
||
|
return this;
|
||
|
}
|
||
|
|
||
|
public final Cookie build() {
|
||
|
return new Cookie(this);
|
||
|
}
|
||
|
|
||
|
public final Builder secure() {
|
||
|
this.secure = true;
|
||
|
return this;
|
||
|
}
|
||
|
|
||
|
public final Builder httpOnly() {
|
||
|
this.httpOnly = true;
|
||
|
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 String toString() {
|
||
|
StringBuilder sb = new StringBuilder();
|
||
|
sb.append(this.name);
|
||
|
sb.append('=');
|
||
|
sb.append(this.value);
|
||
|
if (this.persistent) {
|
||
|
if (this.expiresAt == Long.MIN_VALUE) {
|
||
|
sb.append("; max-age=0");
|
||
|
} else {
|
||
|
sb.append("; expires=");
|
||
|
sb.append(HttpDate.format(new Date(this.expiresAt)));
|
||
|
}
|
||
|
}
|
||
|
if (!this.hostOnly) {
|
||
|
sb.append("; domain=");
|
||
|
sb.append(this.domain);
|
||
|
}
|
||
|
sb.append("; path=");
|
||
|
sb.append(this.path);
|
||
|
if (this.secure) {
|
||
|
sb.append("; secure");
|
||
|
}
|
||
|
if (this.httpOnly) {
|
||
|
sb.append("; httponly");
|
||
|
}
|
||
|
return sb.toString();
|
||
|
}
|
||
|
|
||
|
public final boolean equals(Object obj) {
|
||
|
if (!(obj instanceof Cookie)) {
|
||
|
return false;
|
||
|
}
|
||
|
Cookie cookie = (Cookie) obj;
|
||
|
return cookie.name.equals(this.name) && cookie.value.equals(this.value) && cookie.domain.equals(this.domain) && cookie.path.equals(this.path) && cookie.expiresAt == this.expiresAt && cookie.secure == this.secure && cookie.httpOnly == this.httpOnly && cookie.persistent == this.persistent && cookie.hostOnly == this.hostOnly;
|
||
|
}
|
||
|
|
||
|
public final int hashCode() {
|
||
|
int hashCode = this.name.hashCode();
|
||
|
int hashCode2 = this.value.hashCode();
|
||
|
int hashCode3 = this.domain.hashCode();
|
||
|
int hashCode4 = this.path.hashCode();
|
||
|
long j = this.expiresAt;
|
||
|
return ((((((((((((((((hashCode + 527) * 31) + hashCode2) * 31) + hashCode3) * 31) + hashCode4) * 31) + ((int) ((j >>> 32) ^ j))) * 31) + (!this.secure ? 1 : 0)) * 31) + (!this.httpOnly ? 1 : 0)) * 31) + (!this.persistent ? 1 : 0)) * 31) + (!this.hostOnly ? 1 : 0);
|
||
|
}
|
||
|
|
||
|
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;
|
||
|
}
|
||
|
}
|