package com.facebook; import android.os.Parcel; import android.os.Parcelable; import android.util.Base64; import androidx.annotation.VisibleForTesting; import com.facebook.internal.Validate; import com.google.android.gms.fido.u2f.api.common.ClientData; import com.ironsource.mediationsdk.logger.IronSourceError; import java.nio.charset.Charset; import kotlin.jvm.internal.DefaultConstructorMarker; import kotlin.jvm.internal.Intrinsics; import kotlin.text.Charsets; import org.json.JSONException; import org.json.JSONObject; /* loaded from: classes2.dex */ public final class AuthenticationTokenHeader implements Parcelable { private final String alg; private final String kid; private final String typ; public static final Companion Companion = new Companion(null); public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { // from class: com.facebook.AuthenticationTokenHeader$Companion$CREATOR$1 /* JADX WARN: Can't rename method to resolve collision */ @Override // android.os.Parcelable.Creator public AuthenticationTokenHeader createFromParcel(Parcel source) { Intrinsics.checkNotNullParameter(source, "source"); return new AuthenticationTokenHeader(source); } /* JADX WARN: Can't rename method to resolve collision */ @Override // android.os.Parcelable.Creator public AuthenticationTokenHeader[] newArray(int i) { return new AuthenticationTokenHeader[i]; } }; @Override // android.os.Parcelable public int describeContents() { return 0; } public final String getAlg() { return this.alg; } public final String getKid() { return this.kid; } public final String getTyp() { return this.typ; } public AuthenticationTokenHeader(String encodedHeaderString) { Intrinsics.checkNotNullParameter(encodedHeaderString, "encodedHeaderString"); if (!isValidHeader(encodedHeaderString)) { throw new IllegalArgumentException("Invalid Header".toString()); } byte[] decodedBytes = Base64.decode(encodedHeaderString, 0); Intrinsics.checkNotNullExpressionValue(decodedBytes, "decodedBytes"); JSONObject jSONObject = new JSONObject(new String(decodedBytes, Charsets.UTF_8)); String string = jSONObject.getString("alg"); Intrinsics.checkNotNullExpressionValue(string, "jsonObj.getString(\"alg\")"); this.alg = string; String string2 = jSONObject.getString(ClientData.KEY_TYPE); Intrinsics.checkNotNullExpressionValue(string2, "jsonObj.getString(\"typ\")"); this.typ = string2; String string3 = jSONObject.getString("kid"); Intrinsics.checkNotNullExpressionValue(string3, "jsonObj.getString(\"kid\")"); this.kid = string3; } public AuthenticationTokenHeader(Parcel parcel) { Intrinsics.checkNotNullParameter(parcel, "parcel"); this.alg = Validate.notNullOrEmpty(parcel.readString(), "alg"); this.typ = Validate.notNullOrEmpty(parcel.readString(), ClientData.KEY_TYPE); this.kid = Validate.notNullOrEmpty(parcel.readString(), "kid"); } public AuthenticationTokenHeader(JSONObject jsonObject) throws JSONException { Intrinsics.checkNotNullParameter(jsonObject, "jsonObject"); String string = jsonObject.getString("alg"); Intrinsics.checkNotNullExpressionValue(string, "jsonObject.getString(\"alg\")"); this.alg = string; String string2 = jsonObject.getString(ClientData.KEY_TYPE); Intrinsics.checkNotNullExpressionValue(string2, "jsonObject.getString(\"typ\")"); this.typ = string2; String string3 = jsonObject.getString("kid"); Intrinsics.checkNotNullExpressionValue(string3, "jsonObject.getString(\"kid\")"); this.kid = string3; } @VisibleForTesting(otherwise = 2) public AuthenticationTokenHeader(String alg, String typ, String kid) { Intrinsics.checkNotNullParameter(alg, "alg"); Intrinsics.checkNotNullParameter(typ, "typ"); Intrinsics.checkNotNullParameter(kid, "kid"); this.alg = alg; this.typ = typ; this.kid = kid; } @Override // android.os.Parcelable public void writeToParcel(Parcel dest, int i) { Intrinsics.checkNotNullParameter(dest, "dest"); dest.writeString(this.alg); dest.writeString(this.typ); dest.writeString(this.kid); } public String toString() { String jSONObject = toJSONObject$facebook_core_release().toString(); Intrinsics.checkNotNullExpressionValue(jSONObject, "headerJsonObject.toString()"); return jSONObject; } public boolean equals(Object obj) { if (this == obj) { return true; } if (!(obj instanceof AuthenticationTokenHeader)) { return false; } AuthenticationTokenHeader authenticationTokenHeader = (AuthenticationTokenHeader) obj; return Intrinsics.areEqual(this.alg, authenticationTokenHeader.alg) && Intrinsics.areEqual(this.typ, authenticationTokenHeader.typ) && Intrinsics.areEqual(this.kid, authenticationTokenHeader.kid); } public int hashCode() { return ((((IronSourceError.ERROR_NON_EXISTENT_INSTANCE + this.alg.hashCode()) * 31) + this.typ.hashCode()) * 31) + this.kid.hashCode(); } private final boolean isValidHeader(String str) { Validate.notEmpty(str, "encodedHeaderString"); byte[] decodedBytes = Base64.decode(str, 0); Intrinsics.checkNotNullExpressionValue(decodedBytes, "decodedBytes"); try { JSONObject jSONObject = new JSONObject(new String(decodedBytes, Charsets.UTF_8)); String alg = jSONObject.optString("alg"); Intrinsics.checkNotNullExpressionValue(alg, "alg"); boolean z = alg.length() > 0 && Intrinsics.areEqual(alg, "RS256"); String optString = jSONObject.optString("kid"); Intrinsics.checkNotNullExpressionValue(optString, "jsonObj.optString(\"kid\")"); boolean z2 = optString.length() > 0; String optString2 = jSONObject.optString(ClientData.KEY_TYPE); Intrinsics.checkNotNullExpressionValue(optString2, "jsonObj.optString(\"typ\")"); return z && z2 && (optString2.length() > 0); } catch (JSONException unused) { return false; } } public final JSONObject toJSONObject$facebook_core_release() { JSONObject jSONObject = new JSONObject(); jSONObject.put("alg", this.alg); jSONObject.put(ClientData.KEY_TYPE, this.typ); jSONObject.put("kid", this.kid); return jSONObject; } @VisibleForTesting(otherwise = 2) public final String toEnCodedString() { String authenticationTokenHeader = toString(); Charset charset = Charsets.UTF_8; if (authenticationTokenHeader == null) { throw new NullPointerException("null cannot be cast to non-null type java.lang.String"); } byte[] bytes = authenticationTokenHeader.getBytes(charset); Intrinsics.checkNotNullExpressionValue(bytes, "(this as java.lang.String).getBytes(charset)"); String encodeToString = Base64.encodeToString(bytes, 0); Intrinsics.checkNotNullExpressionValue(encodeToString, "encodeToString(claimsJsonString.toByteArray(), Base64.DEFAULT)"); return encodeToString; } public static final class Companion { public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) { this(); } private Companion() { } } }