Skip to content

Commit

Permalink
Automated Code Change
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 671356607
Change-Id: Iad775b8ff693d17b0b5d90c497e38fc8047565e3
  • Loading branch information
LizaTretyakova authored and copybara-github committed Sep 5, 2024
1 parent 69b95d9 commit 18eb678
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.google.crypto.tink.KeysetHandle;
import com.google.crypto.tink.KmsClient;
import com.google.crypto.tink.KmsClientsTestUtil;
import com.google.crypto.tink.RegistryConfiguration;
import com.google.crypto.tink.aead.AeadConfig;
import com.google.crypto.tink.aead.KmsAeadKeyManager;
import com.google.crypto.tink.aead.KmsEnvelopeAead;
Expand Down Expand Up @@ -165,13 +166,15 @@ public void registerBoundWithFakeAwsKms_kmsEnvelopeAeadCanOnlyBeCreatedForBounde
// getPrimitive works for kekUri
KeyTemplate envelopeTemplate = KmsEnvelopeAeadKeyManager.createKeyTemplate(kekUri, dekTemplate);
KeysetHandle handle = KeysetHandle.generateNew(envelopeTemplate);
Aead unused = handle.getPrimitive(Aead.class);
Aead unused = handle.getPrimitive(RegistryConfiguration.get(), Aead.class);

// getPrimitive does not work for kekUri2
KeyTemplate envelopeTemplate2 =
KmsEnvelopeAeadKeyManager.createKeyTemplate(kekUri2, dekTemplate);
KeysetHandle handle2 = KeysetHandle.generateNew(envelopeTemplate2);
assertThrows(GeneralSecurityException.class, () -> handle2.getPrimitive(Aead.class));
assertThrows(
GeneralSecurityException.class,
() -> handle2.getPrimitive(RegistryConfiguration.get(), Aead.class));
}

@Test
Expand All @@ -192,14 +195,14 @@ public void registerTwoBoundWithFakeAwsKms_kmsAeadWorks() throws Exception {

KeyTemplate kmsTemplate = KmsAeadKeyManager.createKeyTemplate(kekUri);
KeysetHandle handle = KeysetHandle.generateNew(kmsTemplate);
Aead kmsAead = handle.getPrimitive(Aead.class);
Aead kmsAead = handle.getPrimitive(RegistryConfiguration.get(), Aead.class);
byte[] ciphertext = kmsAead.encrypt(plaintext, associatedData);
byte[] decrypted = kmsAead.decrypt(ciphertext, associatedData);
assertThat(decrypted).isEqualTo(plaintext);

KeyTemplate kmsTemplate2 = KmsAeadKeyManager.createKeyTemplate(kekUri2);
KeysetHandle handle2 = KeysetHandle.generateNew(kmsTemplate2);
Aead kmsAead2 = handle2.getPrimitive(Aead.class);
Aead kmsAead2 = handle2.getPrimitive(RegistryConfiguration.get(), Aead.class);
byte[] ciphertext2 = kmsAead2.encrypt(plaintext, associatedData);
byte[] decrypted2 = kmsAead2.decrypt(ciphertext2, associatedData);
assertThat(decrypted2).isEqualTo(plaintext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ java_test(
"@tink_java//src/main/java/com/google/crypto/tink:kms_client",
"@tink_java//src/main/java/com/google/crypto/tink:kms_clients_test_util",
"@tink_java//src/main/java/com/google/crypto/tink:registry_cluster",
"@tink_java//src/main/java/com/google/crypto/tink:registry_configuration",
"@tink_java//src/main/java/com/google/crypto/tink/aead:aead_config",
"@tink_java//src/main/java/com/google/crypto/tink/aead:kms_aead_key_manager",
"@tink_java//src/main/java/com/google/crypto/tink/aead:kms_envelope_aead",
Expand Down

0 comments on commit 18eb678

Please sign in to comment.