mirror of
https://github.com/google/nomulus.git
synced 2025-07-08 20:23:24 +02:00
Refactor KmsKeyring and KmsUpdater to use a centralized serializer
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=151853998
This commit is contained in:
parent
ff9c72097c
commit
bb70fcb66d
7 changed files with 377 additions and 195 deletions
|
@ -18,9 +18,13 @@ import static com.google.common.io.Resources.getResource;
|
|||
|
||||
import com.google.common.io.ByteSource;
|
||||
import com.google.common.io.Resources;
|
||||
import org.bouncycastle.openpgp.PGPKeyPair;
|
||||
import org.bouncycastle.openpgp.PGPPublicKey;
|
||||
import org.bouncycastle.openpgp.PGPSecretKey;
|
||||
import org.bouncycastle.openpgp.PGPUtil;
|
||||
import org.bouncycastle.openpgp.bc.BcPGPPublicKeyRing;
|
||||
import org.bouncycastle.openpgp.bc.BcPGPSecretKeyRing;
|
||||
import org.bouncycastle.openpgp.operator.bc.BcPBESecretKeyDecryptorBuilder;
|
||||
import org.bouncycastle.openpgp.operator.bc.BcPGPDigestCalculatorProvider;
|
||||
|
||||
/** Stores dummy values for test use in {@link KmsUpdaterTest} and {@link KmsKeyringTest}. */
|
||||
final class KmsTestHelper {
|
||||
|
@ -28,20 +32,25 @@ final class KmsTestHelper {
|
|||
static final String DUMMY_CRYPTO_KEY_VERSION = "cheeseburger";
|
||||
static final String DUMMY_ENCRYPTED_VALUE = "meow";
|
||||
|
||||
/** The contents of a dummy PGP public key stored in a file. */
|
||||
private static final ByteSource PGP_PUBLIC_KEYRING =
|
||||
Resources.asByteSource(getResource(KmsTestHelper.class, "pgp-public-keyring.asc"));
|
||||
|
||||
/** The contents of a dummy PGP private key stored in a file. */
|
||||
private static final ByteSource PGP_PRIVATE_KEYRING =
|
||||
Resources.asByteSource(getResource(KmsTestHelper.class, "pgp-private-keyring-registry.asc"));
|
||||
|
||||
static BcPGPPublicKeyRing getPublicKeyring() throws Exception {
|
||||
return new BcPGPPublicKeyRing(PGPUtil.getDecoderStream(PGP_PUBLIC_KEYRING.openStream()));
|
||||
private static BcPGPSecretKeyRing getPrivateKeyring() throws Exception {
|
||||
return new BcPGPSecretKeyRing(PGPUtil.getDecoderStream(PGP_PRIVATE_KEYRING.openStream()));
|
||||
}
|
||||
|
||||
static BcPGPSecretKeyRing getPrivateKeyring() throws Exception {
|
||||
return new BcPGPSecretKeyRing(PGPUtil.getDecoderStream(PGP_PRIVATE_KEYRING.openStream()));
|
||||
static PGPPublicKey getPublicKey() throws Exception {
|
||||
return getPrivateKeyring().getPublicKey();
|
||||
}
|
||||
|
||||
static PGPKeyPair getKeyPair() throws Exception {
|
||||
PGPSecretKey secretKey = getPrivateKeyring().getSecretKey();
|
||||
return new PGPKeyPair(
|
||||
secretKey.getPublicKey(),
|
||||
secretKey.extractPrivateKey(
|
||||
new BcPBESecretKeyDecryptorBuilder(new BcPGPDigestCalculatorProvider())
|
||||
.build(new char[0])));
|
||||
}
|
||||
|
||||
private KmsTestHelper() {}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue