正在查看: Crafto v9.3.3 应用的 EphemeralKeyManager.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: Crafto v9.3.3 应用的 EphemeralKeyManager.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.stripe.android;
import Hk.p;
import Hk.q;
import com.stripe.android.EphemeralOperation;
import com.stripe.android.core.ApiVersion;
import com.stripe.android.model.parsers.EphemeralKeyJsonParser;
import java.util.Calendar;
import java.util.concurrent.TimeUnit;
import kotlin.Metadata;
import kotlin.Unit;
import kotlin.collections.H;
import kotlin.jvm.functions.Function0;
import kotlin.jvm.internal.DefaultConstructorMarker;
import kotlin.jvm.internal.Intrinsics;
import kotlin.text.j;
import org.jetbrains.annotations.NotNull;
import org.json.JSONException;
import org.json.JSONObject;
@Metadata
public final class EphemeralKeyManager {
@NotNull
private static final Companion Companion = new Companion(null);
@Deprecated
private static final long REFRESH_BUFFER_IN_SECONDS = 30;
@NotNull
private final String apiVersion;
private EphemeralKey ephemeralKey;
@NotNull
private final EphemeralKeyProvider ephemeralKeyProvider;
@NotNull
private final KeyManagerListener listener;
private final long timeBufferInSeconds;
@NotNull
private final Function0<Long> timeSupplier;
@Metadata
public static final class ClientKeyUpdateListener implements EphemeralKeyUpdateListener {
@NotNull
private final EphemeralKeyManager ephemeralKeyManager;
@NotNull
private final EphemeralOperation operation;
public ClientKeyUpdateListener(@NotNull EphemeralKeyManager ephemeralKeyManager, @NotNull EphemeralOperation ephemeralOperation) {
Intrinsics.checkNotNullParameter(ephemeralKeyManager, "ephemeralKeyManager");
Intrinsics.checkNotNullParameter(ephemeralOperation, "operation");
this.ephemeralKeyManager = ephemeralKeyManager;
this.operation = ephemeralOperation;
}
@Override
public void onKeyUpdate(@NotNull String str) {
Intrinsics.checkNotNullParameter(str, "stripeResponseJson");
this.ephemeralKeyManager.updateKey(this.operation, str);
}
@Override
public void onKeyUpdateFailure(int i, @NotNull String str) {
Intrinsics.checkNotNullParameter(str, "message");
this.ephemeralKeyManager.updateKeyError(this.operation.getId$payments_core_release(), i, str);
}
}
@Metadata
public static final class Companion {
public Companion(DefaultConstructorMarker defaultConstructorMarker) {
this();
}
private Companion() {
}
}
@Metadata
public interface KeyManagerListener {
void onKeyError(@NotNull String str, int i, @NotNull String str2);
void onKeyUpdate(@NotNull EphemeralKey ephemeralKey, @NotNull EphemeralOperation ephemeralOperation);
}
public EphemeralKeyManager(@NotNull EphemeralKeyProvider ephemeralKeyProvider, @NotNull KeyManagerListener keyManagerListener, @NotNull OperationIdFactory operationIdFactory, boolean z, @NotNull Function0<Long> function0, long j) {
Intrinsics.checkNotNullParameter(ephemeralKeyProvider, "ephemeralKeyProvider");
Intrinsics.checkNotNullParameter(keyManagerListener, "listener");
Intrinsics.checkNotNullParameter(operationIdFactory, "operationIdFactory");
Intrinsics.checkNotNullParameter(function0, "timeSupplier");
this.ephemeralKeyProvider = ephemeralKeyProvider;
this.listener = keyManagerListener;
this.timeSupplier = function0;
this.timeBufferInSeconds = j;
this.apiVersion = ApiVersion.Companion.get().getCode();
if (z) {
retrieveEphemeralKey$payments_core_release(new EphemeralOperation.RetrieveKey(operationIdFactory.create(), H.a));
}
}
public final void updateKey(EphemeralOperation ephemeralOperation, String str) {
EphemeralKey a;
String b;
if (str == null) {
this.listener.onKeyError(ephemeralOperation.getId$payments_core_release(), 500, "EphemeralKeyUpdateListener.onKeyUpdate was called with a null value");
return;
}
try {
p.a aVar = p.b;
a = new EphemeralKeyJsonParser().parse(new JSONObject(str));
this.ephemeralKey = a;
} catch (Throwable th) {
p.a aVar2 = p.b;
a = q.a(th);
}
Throwable a2 = p.a(a);
if (a2 == null) {
this.listener.onKeyUpdate(a, ephemeralOperation);
return;
}
if (a2 instanceof JSONException) {
b = j.b("\n Received an ephemeral key that could not be parsed. See https://stripe.com/docs/mobile/android/basic for more details.\n \n " + a2.getMessage() + "\n ");
} else {
b = j.b("\n Received an invalid ephemeral key. See https://stripe.com/docs/mobile/android/basic for more details.\n \n " + a2.getMessage() + "\n ");
}
this.listener.onKeyError(ephemeralOperation.getId$payments_core_release(), 500, b);
}
public final void updateKeyError(String str, int i, String str2) {
this.ephemeralKey = null;
this.listener.onKeyError(str, i, str2);
}
public final EphemeralKey getEphemeralKey$payments_core_release() {
return this.ephemeralKey;
}
public final void retrieveEphemeralKey$payments_core_release(EphemeralOperation ephemeralOperation) {
Intrinsics.checkNotNullParameter(ephemeralOperation, "operation");
EphemeralKey ephemeralKey = this.ephemeralKey;
Unit unit = null;
if (ephemeralKey == null || shouldRefreshKey$payments_core_release(ephemeralKey)) {
ephemeralKey = null;
}
if (ephemeralKey != null) {
this.listener.onKeyUpdate(ephemeralKey, ephemeralOperation);
unit = Unit.a;
}
if (unit == null) {
this.ephemeralKeyProvider.createEphemeralKey(this.apiVersion, new ClientKeyUpdateListener(this, ephemeralOperation));
}
}
public final void setEphemeralKey$payments_core_release(EphemeralKey ephemeralKey) {
this.ephemeralKey = ephemeralKey;
}
public final boolean shouldRefreshKey$payments_core_release(EphemeralKey ephemeralKey) {
if (ephemeralKey == null) {
return true;
}
return ephemeralKey.getExpires$payments_core_release() < TimeUnit.MILLISECONDS.toSeconds(((Number) this.timeSupplier.invoke()).longValue()) + this.timeBufferInSeconds;
}
@Metadata
public interface Factory {
@NotNull
EphemeralKeyManager create(@NotNull KeyManagerListener keyManagerListener);
@Metadata
public static final class Default implements Factory {
public static final int $stable = 0;
@NotNull
private final EphemeralKeyProvider keyProvider;
@NotNull
private final OperationIdFactory operationIdFactory;
private final boolean shouldPrefetchEphemeralKey;
@NotNull
private final Function0<Long> timeSupplier;
public Default(@NotNull EphemeralKeyProvider ephemeralKeyProvider, boolean z, @NotNull OperationIdFactory operationIdFactory, @NotNull Function0<Long> function0) {
Intrinsics.checkNotNullParameter(ephemeralKeyProvider, "keyProvider");
Intrinsics.checkNotNullParameter(operationIdFactory, "operationIdFactory");
Intrinsics.checkNotNullParameter(function0, "timeSupplier");
this.keyProvider = ephemeralKeyProvider;
this.shouldPrefetchEphemeralKey = z;
this.operationIdFactory = operationIdFactory;
this.timeSupplier = function0;
}
@Override
public EphemeralKeyManager create(KeyManagerListener keyManagerListener) {
Intrinsics.checkNotNullParameter(keyManagerListener, "arg");
return new EphemeralKeyManager(this.keyProvider, keyManagerListener, this.operationIdFactory, this.shouldPrefetchEphemeralKey, this.timeSupplier, 0L, 32, null);
}
public Default(EphemeralKeyProvider ephemeralKeyProvider, boolean z, OperationIdFactory operationIdFactory, Function0 function0, int i, DefaultConstructorMarker defaultConstructorMarker) {
this(ephemeralKeyProvider, z, (i & 4) != 0 ? new StripeOperationIdFactory() : operationIdFactory, (i & 8) != 0 ? new Function0<Long>() {
@NotNull
public final Long m6invoke() {
return Long.valueOf(Calendar.getInstance().getTimeInMillis());
}
} : function0);
}
}
}
public EphemeralKeyManager(EphemeralKeyProvider ephemeralKeyProvider, KeyManagerListener keyManagerListener, OperationIdFactory operationIdFactory, boolean z, Function0 function0, long j, int i, DefaultConstructorMarker defaultConstructorMarker) {
this(ephemeralKeyProvider, keyManagerListener, (i & 4) != 0 ? new StripeOperationIdFactory() : operationIdFactory, (i & 8) != 0 ? true : z, (i & 16) != 0 ? new Function0<Long>() {
@NotNull
public final Long m5invoke() {
return Long.valueOf(Calendar.getInstance().getTimeInMillis());
}
} : function0, (i & 32) != 0 ? 30L : j);
}
}