Skip to content

Commit

Permalink
回滚代码
Browse files Browse the repository at this point in the history
  • Loading branch information
wujunjiesd committed May 6, 2024
1 parent afc45db commit 9096b79
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.wechat.pay.java.core.cipher.AeadCipher;
import com.wechat.pay.java.core.cipher.RSAVerifier;
import com.wechat.pay.java.core.cipher.Verifier;
import java.security.PublicKey;

public abstract class AbstractNotificationConfig implements NotificationConfig {

Expand All @@ -13,9 +12,6 @@ public abstract class AbstractNotificationConfig implements NotificationConfig {
private final CertificateProvider certificateProvider;
private final AeadCipher aeadCipher;

private final PublicKey publicKey;
private final String publicKeyId;

protected AbstractNotificationConfig(
String signType,
String cipherAlgorithm,
Expand All @@ -25,22 +21,6 @@ protected AbstractNotificationConfig(
this.cipherAlgorithm = cipherAlgorithm;
this.certificateProvider = certificateProvider;
this.aeadCipher = aeadCipher;
this.publicKey = null;
this.publicKeyId = null;
}

protected AbstractNotificationConfig(
String signType,
String cipherAlgorithm,
PublicKey publicKey,
String publicKeyId,
AeadCipher aeadCipher) {
this.signType = signType;
this.cipherAlgorithm = cipherAlgorithm;
this.publicKey = publicKey;
this.publicKeyId = publicKeyId;
this.aeadCipher = aeadCipher;
this.certificateProvider = null;
}

@Override
Expand All @@ -55,9 +35,6 @@ public String getCipherType() {

@Override
public Verifier createVerifier() {
if (publicKey != null) {
return new RSAVerifier(publicKey, publicKeyId);
}
return new RSAVerifier(certificateProvider);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@
import com.wechat.pay.java.core.certificate.InMemoryCertificateProvider;
import com.wechat.pay.java.core.cipher.AeadAesCipher;
import com.wechat.pay.java.core.cipher.AeadCipher;
import com.wechat.pay.java.core.exception.ValidationException;
import com.wechat.pay.java.core.util.PemUtil;
import java.nio.charset.StandardCharsets;
import java.security.PublicKey;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -24,18 +22,11 @@ private RSANotificationConfig(CertificateProvider certificateProvider, AeadCiphe
super(RSA_SIGN_TYPE, AES_CIPHER_ALGORITHM, certificateProvider, aeadCipher);
}

private RSANotificationConfig(PublicKey publicKey, String publicKeyId, AeadCipher aeadCipher) {
super(RSA_SIGN_TYPE, AES_CIPHER_ALGORITHM, publicKey, publicKeyId, aeadCipher);
}

public static class Builder {

private List<X509Certificate> certificates;
private byte[] apiV3Key;

private PublicKey publicKey;
private String publicKeyId;

public Builder certificates(X509Certificate... certificates) {
this.certificates = Arrays.asList(certificates);
return this;
Expand All @@ -61,40 +52,12 @@ public Builder certificatesFromPath(String... certificatePaths) {
return this;
}

public Builder publicKey(String publicKey) {
this.publicKey = PemUtil.loadPublicKeyFromString(publicKey);
return this;
}

public Builder publicKey(PublicKey publicKey) {
this.publicKey = publicKey;
return this;
}

public Builder publicFromPath(String publicKeyPath) {
this.publicKey = PemUtil.loadPublicKeyFromPath(publicKeyPath);
return this;
}

public Builder apiV3Key(String apiV3Key) {
this.apiV3Key = apiV3Key.getBytes(StandardCharsets.UTF_8);
return this;
}

public Builder publicKeyId(String publicKeyId) {
this.publicKeyId = publicKeyId;
return this;
}

public RSANotificationConfig build() {
if (publicKey != null && certificates != null) {
throw new ValidationException(
"only one parameter can be set between publicKey and certificates");
}
if (publicKey != null) {
return new RSANotificationConfig(
publicKey, requireNonNull(publicKeyId), new AeadAesCipher(requireNonNull(apiV3Key)));
}
CertificateProvider certificateProvider = new InMemoryCertificateProvider(certificates);
return new RSANotificationConfig(
certificateProvider, new AeadAesCipher(requireNonNull(apiV3Key)));
Expand Down

0 comments on commit 9096b79

Please sign in to comment.