package com.facebook;

import X.9ev;
import X.C5471M1m;
import X.C5604M6p;
import X.C5607M6s;
import X.M12;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.Base64;
import com.bytedance.covode.number.Covode;
import java.io.IOException;
import java.security.KeyFactory;
import java.security.PublicKey;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.X509EncodedKeySpec;
import java.util.List;
import kotlin.h.b.n;
import kotlin.o.y;
import kotlin.o.z;

public final class AuthenticationToken implements Parcelable {
    public static final Parcelable.Creator<AuthenticationToken> CREATOR = new C5607M6s();
    public static final C5604M6p LIZ = new C5604M6p((byte) 0);
    public final String LIZIZ;
    public final String LIZJ;
    public final AuthenticationTokenHeader LIZLLL;
    public final AuthenticationTokenClaims LJ;
    public final String LJFF;

    public final int describeContents() {
        return 0;
    }

    static {
        Covode.recordClassIndex(40779);
    }

    public final int hashCode() {
        return ((((((((this.LIZIZ.hashCode() + 527) * 31) + this.LIZJ.hashCode()) * 31) + this.LIZLLL.hashCode()) * 31) + this.LJ.hashCode()) * 31) + this.LJFF.hashCode();
    }

    public final boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (!(obj instanceof AuthenticationToken)) {
            return false;
        }
        AuthenticationToken authenticationToken = (AuthenticationToken) obj;
        if (!n.LIZ(this.LIZIZ, authenticationToken.LIZIZ) || !n.LIZ(this.LIZJ, authenticationToken.LIZJ) || !n.LIZ(this.LIZLLL, authenticationToken.LIZLLL) || !n.LIZ(this.LJ, authenticationToken.LJ) || !n.LIZ(this.LJFF, authenticationToken.LJFF)) {
            return false;
        }
        return true;
    }

    public AuthenticationToken(Parcel parcel) {
        M12.LIZ((Object) parcel);
        String readString = parcel.readString();
        C5471M1m.LIZ(readString, "token");
        this.LIZIZ = readString;
        String readString2 = parcel.readString();
        C5471M1m.LIZ(readString2, "expectedNonce");
        this.LIZJ = readString2;
        Parcelable readParcelable = parcel.readParcelable(AuthenticationTokenHeader.class.getClassLoader());
        if (readParcelable != null) {
            this.LIZLLL = (AuthenticationTokenHeader) readParcelable;
            Parcelable readParcelable2 = parcel.readParcelable(AuthenticationTokenClaims.class.getClassLoader());
            if (readParcelable2 != null) {
                this.LJ = (AuthenticationTokenClaims) readParcelable2;
                String readString3 = parcel.readString();
                C5471M1m.LIZ(readString3, "signature");
                this.LJFF = readString3;
                return;
            }
            throw new IllegalStateException("Required value was null.".toString());
        }
        throw new IllegalStateException("Required value was null.".toString());
    }

    public final void writeToParcel(Parcel parcel, int i) {
        M12.LIZ((Object) parcel);
        parcel.writeString(this.LIZIZ);
        parcel.writeString(this.LIZJ);
        parcel.writeParcelable(this.LIZLLL, i);
        parcel.writeParcelable(this.LJ, i);
        parcel.writeString(this.LJFF);
    }

    public AuthenticationToken(String str, String str2) {
        M12.LIZ((Object) str, (Object) str2);
        C5471M1m.LIZIZ(str, "token");
        C5471M1m.LIZIZ(str2, "expectedNonce");
        List LIZ2 = z.LIZ((CharSequence) str, new String[]{"."}, 0, 6);
        if (LIZ2.size() == 3) {
            String str3 = (String) LIZ2.get(0);
            String str4 = (String) LIZ2.get(1);
            String str5 = (String) LIZ2.get(2);
            this.LIZIZ = str;
            this.LIZJ = str2;
            AuthenticationTokenHeader authenticationTokenHeader = new AuthenticationTokenHeader(str3);
            this.LIZLLL = authenticationTokenHeader;
            this.LJ = new AuthenticationTokenClaims(str4, str2);
            if (LIZ(str3, str4, str5, authenticationTokenHeader.LIZLLL)) {
                this.LJFF = str5;
                return;
            }
            throw new IllegalArgumentException("Invalid Signature".toString());
        }
        throw new IllegalArgumentException("Invalid IdToken string".toString());
    }

    private final boolean LIZ(String str, String str2, String str3, String str4) {
        try {
            String LIZ2 = 9ev.LIZ(str4);
            if (LIZ2 == null) {
                return false;
            }
            M12.LIZ((Object) LIZ2);
            byte[] decode = Base64.decode(y.LIZ(y.LIZ(y.LIZ(LIZ2, "\n", "", false), "-----BEGIN PUBLIC KEY-----", "", false), "-----END PUBLIC KEY-----", "", false), 0);
            M12.LIZ((Object) decode);
            PublicKey generatePublic = KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(decode));
            M12.LIZ((Object) generatePublic);
            return 9ev.LIZ(generatePublic, str + '.' + str2, str3);
        } catch (IOException | InvalidKeySpecException unused) {
            return false;
        }
    }
}
