package q4; import android.content.SharedPreferences; import android.util.Base64; import android.util.Log; import com.google.android.gms.ads.RequestConfiguration; import com.google.android.gms.stats.CodePackage; import com.igaworks.ssp.R; import java.security.KeyFactory; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.security.PublicKey; import java.security.spec.InvalidKeySpecException; import java.security.spec.X509EncodedKeySpec; import org.json.JSONException; import org.json.JSONObject; import w3.f; /* loaded from: classes2.dex */ public class b { /* renamed from: c, reason: collision with root package name */ private static final String[] f13474c = {"*", "FCM", CodePackage.GCM, RequestConfiguration.MAX_AD_CONTENT_RATING_UNSPECIFIED}; /* renamed from: a, reason: collision with root package name */ private final SharedPreferences f13475a; /* renamed from: b, reason: collision with root package name */ private final String f13476b; public b(f fVar) { this.f13475a = fVar.k().getSharedPreferences("com.google.android.gms.appid", 0); this.f13476b = b(fVar); } private String a(String str, String str2) { return "|T|" + str + "|" + str2; } private static String b(f fVar) { String d10 = fVar.o().d(); if (d10 != null) { return d10; } String c10 = fVar.o().c(); if (!c10.startsWith("1:") && !c10.startsWith("2:")) { return c10; } String[] split = c10.split(":"); if (split.length != 4) { return null; } String str = split[1]; if (str.isEmpty()) { return null; } return str; } private static String c(PublicKey publicKey) { try { byte[] digest = MessageDigest.getInstance("SHA1").digest(publicKey.getEncoded()); digest[0] = (byte) (((digest[0] & 15) + R.styleable.AppCompatTheme_toolbarNavigationButtonStyle) & 255); return Base64.encodeToString(digest, 0, 8, 11); } catch (NoSuchAlgorithmException unused) { Log.w("ContentValues", "Unexpected error, device missing required algorithms"); return null; } } private String d(String str) { try { return new JSONObject(str).getString("token"); } catch (JSONException unused) { return null; } } private PublicKey e(String str) { try { return KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(Base64.decode(str, 8))); } catch (IllegalArgumentException | NoSuchAlgorithmException | InvalidKeySpecException e10) { Log.w("ContentValues", "Invalid key stored " + e10); return null; } } private String g() { String string; synchronized (this.f13475a) { string = this.f13475a.getString("|S|id", null); } return string; } private String h() { synchronized (this.f13475a) { String string = this.f13475a.getString("|S||P|", null); if (string == null) { return null; } PublicKey e10 = e(string); if (e10 == null) { return null; } return c(e10); } } public String f() { synchronized (this.f13475a) { String g10 = g(); if (g10 != null) { return g10; } return h(); } } public String i() { synchronized (this.f13475a) { for (String str : f13474c) { String string = this.f13475a.getString(a(this.f13476b, str), null); if (string != null && !string.isEmpty()) { if (string.startsWith("{")) { string = d(string); } return string; } } return null; } } }