fix(KMS): Allow arn and alias to encrypt (#69)

Thanks again, @MasatoshiTada!

This is a great addition to Floci. Your continued support really makes a difference. Hope to see you around soon!

---------

* fix(KMS): Allow arn and alias to encrypt

* fix(KMS): Allow alias-arn to encrypt

---------

Co-authored-by: tada <tada20591@cs.saisoncard.co.jp>
This commit is contained in:
Masatoshi Tadaandtada authored and GitHub committed 2026-03-27 14:06:48 -05:00
1 parent 7b87bf2c1f
commit fa4e107572
2 files changed
+51 -4

No files matched your search

@@ -127,7 +127,7 @@ class KmsServiceTest {
}
@Test
void encryptAndDecrypt() {
void encryptAndDecryptWithId() {
KmsKey key = kmsService.createKey(null, REGION);
byte[] plaintext = "hello world".getBytes(StandardCharsets.UTF_8);
@@ -137,6 +137,43 @@ class KmsServiceTest {
assertArrayEquals(plaintext, decrypted);
}
@Test
void encryptAndDecryptWithArn() {
KmsKey key = kmsService.createKey(null, REGION);
byte[] plaintext = "hello world".getBytes(StandardCharsets.UTF_8);
byte[] ciphertext = kmsService.encrypt(key.getArn(), plaintext, REGION);
byte[] decrypted = kmsService.decrypt(ciphertext, REGION);
assertArrayEquals(plaintext, decrypted);
}
@Test
void encryptAndDecryptWithAliasName() {
KmsKey key = kmsService.createKey(null, REGION);
String aliasName = "alias/my-alias";
kmsService.createAlias(aliasName, key.getKeyId(), REGION);
byte[] plaintext = "hello world".getBytes(StandardCharsets.UTF_8);
byte[] ciphertext = kmsService.encrypt(aliasName, plaintext, REGION);
byte[] decrypted = kmsService.decrypt(ciphertext, REGION);
assertArrayEquals(plaintext, decrypted);
}
@Test
void encryptAndDecryptWithAliasArn() {
KmsKey key = kmsService.createKey(null, REGION);
String aliasName = "alias/my-alias";
kmsService.createAlias(aliasName, key.getKeyId(), REGION);
byte[] plaintext = "hello world".getBytes(StandardCharsets.UTF_8);
byte[] ciphertext = kmsService.encrypt("arn:aws:kms:" + REGION + ":000000000000:" + aliasName, plaintext, REGION);
byte[] decrypted = kmsService.decrypt(ciphertext, REGION);
assertArrayEquals(plaintext, decrypted);
}
@Test
void decryptInvalidCiphertextThrows() {
assertThrows(AwsException.class, () ->