From ce814a8bb2ecd91c466b56c1f9ac0694706b1403 Mon Sep 17 00:00:00 2001 From: Bikram Sharma Date: Fri, 10 Apr 2026 13:21:22 -0700 Subject: [PATCH 1/5] chore(java): deconflicts the test run across various Java and OS versions --- .../cryptography/examples/ExampleUtils.java | 18 ++++++++++++++++++ .../clientsupplier/ClientSupplierExample.java | 7 ++++--- .../enhanced/EnhancedPutGetExample.java | 4 +++- .../examples/enhanced/LombokPutGetExample.java | 4 +++- .../examples/enhanced/SingleTableExample.java | 14 ++++++++------ .../TableSchemaBuilderPutGetExample.java | 4 +++- .../ItemEncryptDecryptExample.java | 7 ++++--- .../keyring/HierarchicalKeyringExample.java | 5 +++-- .../keyring/KmsEcdhKeyringExample.java | 7 ++++--- .../examples/keyring/KmsRsaKeyringExample.java | 5 +++-- .../MrkDiscoveryMultiKeyringExample.java | 5 +++-- .../examples/keyring/MultiKeyringExample.java | 7 ++++--- .../keyring/MultiMrkKeyringExample.java | 9 +++++---- .../examples/keyring/RawAesKeyringExample.java | 5 +++-- .../keyring/RawEcdhKeyringExample.java | 9 +++++---- .../examples/keyring/RawRsaKeyringExample.java | 5 +++-- ...CacheAcrossHierarchicalKeyringsExample.java | 5 +++-- 17 files changed, 79 insertions(+), 41 deletions(-) create mode 100644 Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/ExampleUtils.java diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/ExampleUtils.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/ExampleUtils.java new file mode 100644 index 0000000000..8f9a667e98 --- /dev/null +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/ExampleUtils.java @@ -0,0 +1,18 @@ +// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 +package software.amazon.cryptography.examples; + +import java.util.concurrent.ThreadLocalRandom; + +/** + * Shared utilities for examples. The SORT_KEY constant provides a unique value + * per JVM process so that parallel CI matrix jobs (different Java versions / OS) + * do not overwrite each other's items in the shared DynamoDB test table. + */ +public class ExampleUtils { + + public static final int SORT_KEY = + ThreadLocalRandom.current().nextInt(100000, 999999); + + public static final String SORT_KEY_VALUE = String.valueOf(SORT_KEY); +} diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/clientsupplier/ClientSupplierExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/clientsupplier/ClientSupplierExample.java index 7d75d2f9b2..bf7d31c4e2 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/clientsupplier/ClientSupplierExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/clientsupplier/ClientSupplierExample.java @@ -1,6 +1,7 @@ package software.amazon.cryptography.examples.clientsupplier; import java.util.ArrayList; +import software.amazon.cryptography.examples.ExampleUtils; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -168,7 +169,7 @@ public static void ClientSupplierPutItemGetItem( "partition_key", AttributeValue.builder().s("clientSupplierItem").build() ); - item.put("sort_key", AttributeValue.builder().n("0").build()); + item.put("sort_key", AttributeValue.builder().n(ExampleUtils.SORT_KEY_VALUE).build()); item.put( "sensitive_data", AttributeValue.builder().s("encrypt and sign me!").build() @@ -193,7 +194,7 @@ public static void ClientSupplierPutItemGetItem( "partition_key", AttributeValue.builder().s("clientSupplierItem").build() ); - keyToGet.put("sort_key", AttributeValue.builder().n("0").build()); + keyToGet.put("sort_key", AttributeValue.builder().n(ExampleUtils.SORT_KEY_VALUE).build()); final GetItemRequest getRequest = GetItemRequest .builder() @@ -293,7 +294,7 @@ public static void ClientSupplierPutItemGetItem( ); onlyReplicaKeyKeyToGet.put( "sort_key", - AttributeValue.builder().n("0").build() + AttributeValue.builder().n(ExampleUtils.SORT_KEY_VALUE).build() ); final GetItemRequest onlyReplicaKeyGetRequest = GetItemRequest diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/enhanced/EnhancedPutGetExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/enhanced/EnhancedPutGetExample.java index 3474b3094b..9ae5282699 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/enhanced/EnhancedPutGetExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/enhanced/EnhancedPutGetExample.java @@ -1,6 +1,8 @@ package software.amazon.cryptography.examples.enhanced; import java.util.ArrayList; +import software.amazon.cryptography.examples.ExampleUtils; +import software.amazon.cryptography.examples.ExampleUtils; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -154,7 +156,7 @@ public static void PutItemGetItem(String kmsKeyId, String ddbTableName) { // configuration above before it is sent to DynamoDb. final SimpleClass4 item = new SimpleClass4(); item.setPartitionKey("EnhancedPutGetExample"); - item.setSortKey(0); + item.setSortKey(ExampleUtils.SORT_KEY); item.setAttribute1("encrypt and sign me!"); item.setAttribute2("sign me!"); item.setAttribute3("ignore me!"); diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/enhanced/LombokPutGetExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/enhanced/LombokPutGetExample.java index 4eff731ad1..8ade3c2dec 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/enhanced/LombokPutGetExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/enhanced/LombokPutGetExample.java @@ -1,6 +1,8 @@ package software.amazon.cryptography.examples.enhanced; import static software.amazon.cryptography.examples.ConfigUtils.fromEncryptionInterceptor; +import software.amazon.cryptography.examples.ExampleUtils; +import software.amazon.cryptography.examples.ExampleUtils; import static software.amazon.cryptography.examples.ManipulationUtils.assertManipulationProof; import static software.amazon.cryptography.examples.ManipulationUtils.assertNotManipulationProof; import static software.amazon.cryptography.examples.ManipulationUtils.assertProtectedByEncryptionContext; @@ -164,7 +166,7 @@ public static void PutItemGetItem(String kmsKeyId, String ddbTableName) { final SimpleViaLombok.SimpleViaLombokBuilder itemBuilder = SimpleViaLombok.builder(); itemBuilder.partitionKey("LombokPutGetExample"); - itemBuilder.sortKey(0); + itemBuilder.sortKey(ExampleUtils.SORT_KEY); itemBuilder.attribute1("encrypt and sign me!"); itemBuilder.attribute2("sign me!"); itemBuilder.attribute3("ignore me!"); diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/enhanced/SingleTableExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/enhanced/SingleTableExample.java index c0657017c0..5af9140fa1 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/enhanced/SingleTableExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/enhanced/SingleTableExample.java @@ -1,5 +1,7 @@ package software.amazon.cryptography.examples.enhanced; +import software.amazon.cryptography.examples.ExampleUtils; +import software.amazon.cryptography.examples.ExampleUtils; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -169,21 +171,21 @@ public static void TransactWriteItems(String kmsKeyId, String ddbTableName) { // configuration above before it is sent to DynamoDb. final SimpleClass item1 = new SimpleClass(); item1.setPartitionKey("EnhancedPutGetExample1"); - item1.setSortKey(0); + item1.setSortKey(ExampleUtils.SORT_KEY); item1.setAttribute1("item1 encrypt and sign me!"); item1.setAttribute2("item1 sign me!"); item1.setAttribute3("item1 ignore me!"); final SimpleClass2 item2 = new SimpleClass2(); item2.setPartitionKey("EnhancedPutGetExample2"); - item2.setSortKey(0); + item2.setSortKey(ExampleUtils.SORT_KEY); item2.setAttribute4("item2 encrypt and sign me!"); item2.setAttribute5("item2 sign me!"); item2.setAttribute3("item2 ignore me!"); final SimpleClass3 item3 = new SimpleClass3(); item3.setPartitionKey("EnhancedPutGetExample3"); - item3.setSortKey(0); + item3.setSortKey(ExampleUtils.SORT_KEY); item3.setAttribute6("item3 encrypt and sign me!"); item3.setAttribute2("item3 sign me!"); item3.setAttribute7("item3 sign and include me!"); @@ -203,15 +205,15 @@ public static void TransactWriteItems(String kmsKeyId, String ddbTableName) { // original item. final SimpleClass key1 = new SimpleClass(); key1.setPartitionKey("EnhancedPutGetExample1"); - key1.setSortKey(0); + key1.setSortKey(ExampleUtils.SORT_KEY); final SimpleClass2 key2 = new SimpleClass2(); key2.setPartitionKey("EnhancedPutGetExample2"); - key2.setSortKey(0); + key2.setSortKey(ExampleUtils.SORT_KEY); final SimpleClass3 key3 = new SimpleClass3(); key3.setPartitionKey("EnhancedPutGetExample3"); - key3.setSortKey(0); + key3.setSortKey(ExampleUtils.SORT_KEY); final TransactGetItemsEnhancedRequest getRequest = TransactGetItemsEnhancedRequest diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/enhanced/TableSchemaBuilderPutGetExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/enhanced/TableSchemaBuilderPutGetExample.java index 2ec8e61675..21d2e55ffb 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/enhanced/TableSchemaBuilderPutGetExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/enhanced/TableSchemaBuilderPutGetExample.java @@ -1,6 +1,8 @@ package software.amazon.cryptography.examples.enhanced; import static software.amazon.awssdk.enhanced.dynamodb.mapper.StaticAttributeTags.primaryPartitionKey; +import software.amazon.cryptography.examples.ExampleUtils; +import software.amazon.cryptography.examples.ExampleUtils; import static software.amazon.awssdk.enhanced.dynamodb.mapper.StaticAttributeTags.primarySortKey; import static software.amazon.cryptography.examples.ManipulationUtils.assertManipulationProof; import static software.amazon.cryptography.examples.ManipulationUtils.assertNotManipulationProof; @@ -213,7 +215,7 @@ public static void PutItemGetItem(String kmsKeyId, String ddbTableName) { // configuration above before it is sent to DynamoDb. final SimpleClass item = new SimpleClass(); item.setPartitionKey("TableSchemaBuilderPutGetExample"); - item.setSortKey(0); + item.setSortKey(ExampleUtils.SORT_KEY); item.setAttribute1("encrypt and sign me!"); item.setAttribute2("sign me!"); item.setAttribute3("ignore me!"); diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/itemencryptor/ItemEncryptDecryptExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/itemencryptor/ItemEncryptDecryptExample.java index ea6b296054..75aa96e0b6 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/itemencryptor/ItemEncryptDecryptExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/itemencryptor/ItemEncryptDecryptExample.java @@ -1,6 +1,7 @@ package software.amazon.cryptography.examples.itemencryptor; import java.util.HashMap; +import software.amazon.cryptography.examples.ExampleUtils; import java.util.Map; import software.amazon.awssdk.services.dynamodb.model.*; import software.amazon.cryptography.dbencryptionsdk.dynamodb.itemencryptor.DynamoDbItemEncryptor; @@ -126,7 +127,7 @@ public static void PutItemGetItem(String kmsKeyId, String ddbTableName) { "partition_key", AttributeValue.builder().s("ItemEncryptDecryptExample").build() ); - originalItem.put("sort_key", AttributeValue.builder().n("0").build()); + originalItem.put("sort_key", AttributeValue.builder().n(ExampleUtils.SORT_KEY_VALUE).build()); originalItem.put( "attribute1", AttributeValue.builder().s("encrypt and sign me!").build() @@ -151,7 +152,7 @@ public static void PutItemGetItem(String kmsKeyId, String ddbTableName) { .get("partition_key") .s() .equals("ItemEncryptDecryptExample"); - assert encryptedItem.get("sort_key").n().equals("0"); + assert encryptedItem.get("sort_key").n().equals(ExampleUtils.SORT_KEY_VALUE); assert encryptedItem.get("attribute1").b() != null; // 7. Directly decrypt the encrypted item using the DynamoDb Item Encryptor @@ -166,7 +167,7 @@ public static void PutItemGetItem(String kmsKeyId, String ddbTableName) { .get("partition_key") .s() .equals("ItemEncryptDecryptExample"); - assert decryptedItem.get("sort_key").n().equals("0"); + assert decryptedItem.get("sort_key").n().equals(ExampleUtils.SORT_KEY_VALUE); assert decryptedItem.get("attribute1").s().equals("encrypt and sign me!"); } diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/HierarchicalKeyringExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/HierarchicalKeyringExample.java index a0ad297bb3..5c8ae614f4 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/HierarchicalKeyringExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/HierarchicalKeyringExample.java @@ -1,6 +1,7 @@ package software.amazon.cryptography.examples.keyring; import java.util.HashMap; +import software.amazon.cryptography.examples.ExampleUtils; import java.util.Map; import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration; import software.amazon.awssdk.services.dynamodb.DynamoDbClient; @@ -236,7 +237,7 @@ public static void HierarchicalKeyringGetItemPutItem( // `tenant1BranchKeyId` will be used to encrypt this item. final HashMap item = new HashMap<>(); item.put("partition_key", AttributeValue.builder().s("tenant1Id").build()); - item.put("sort_key", AttributeValue.builder().n("0").build()); + item.put("sort_key", AttributeValue.builder().n(ExampleUtils.SORT_KEY_VALUE).build()); item.put( "tenant_sensitive_data", AttributeValue.builder().s("encrypt and sign me!").build() @@ -264,7 +265,7 @@ public static void HierarchicalKeyringGetItemPutItem( "partition_key", AttributeValue.builder().s("tenant1Id").build() ); - keyToGet.put("sort_key", AttributeValue.builder().n("0").build()); + keyToGet.put("sort_key", AttributeValue.builder().n(ExampleUtils.SORT_KEY_VALUE).build()); final GetItemRequest getRequest = GetItemRequest .builder() diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/KmsEcdhKeyringExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/KmsEcdhKeyringExample.java index bb9978d4db..2ba535170e 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/KmsEcdhKeyringExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/KmsEcdhKeyringExample.java @@ -1,6 +1,7 @@ package software.amazon.cryptography.examples.keyring; import java.io.ByteArrayInputStream; +import software.amazon.cryptography.examples.ExampleUtils; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; @@ -341,7 +342,7 @@ private static void GetItemWithKeyring( "partition_key", AttributeValue.builder().s("awsKmsEcdhKeyringItem").build() ); - keyToGet.put("sort_key", AttributeValue.builder().n("0").build()); + keyToGet.put("sort_key", AttributeValue.builder().n(ExampleUtils.SORT_KEY_VALUE).build()); final GetItemRequest getRequest = GetItemRequest .builder() @@ -458,7 +459,7 @@ private static void PutGetItemWithKeyring( "partition_key", AttributeValue.builder().s("awsKmsEcdhKeyringItem").build() ); - item.put("sort_key", AttributeValue.builder().n("0").build()); + item.put("sort_key", AttributeValue.builder().n(ExampleUtils.SORT_KEY_VALUE).build()); item.put( "sensitive_data", AttributeValue.builder().s("encrypt and sign me!").build() @@ -483,7 +484,7 @@ private static void PutGetItemWithKeyring( "partition_key", AttributeValue.builder().s("awsKmsEcdhKeyringItem").build() ); - keyToGet.put("sort_key", AttributeValue.builder().n("0").build()); + keyToGet.put("sort_key", AttributeValue.builder().n(ExampleUtils.SORT_KEY_VALUE).build()); final GetItemRequest getRequest = GetItemRequest .builder() diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/KmsRsaKeyringExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/KmsRsaKeyringExample.java index cd02dd4595..21fc1442a2 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/KmsRsaKeyringExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/KmsRsaKeyringExample.java @@ -1,6 +1,7 @@ package software.amazon.cryptography.examples.keyring; import java.io.File; +import software.amazon.cryptography.examples.ExampleUtils; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; @@ -203,7 +204,7 @@ public static void KmsRsaKeyringGetItemPutItem( "partition_key", AttributeValue.builder().s("awsKmsRsaKeyringItem").build() ); - item.put("sort_key", AttributeValue.builder().n("0").build()); + item.put("sort_key", AttributeValue.builder().n(ExampleUtils.SORT_KEY_VALUE).build()); item.put( "sensitive_data", AttributeValue.builder().s("encrypt and sign me!").build() @@ -228,7 +229,7 @@ public static void KmsRsaKeyringGetItemPutItem( "partition_key", AttributeValue.builder().s("awsKmsRsaKeyringItem").build() ); - keyToGet.put("sort_key", AttributeValue.builder().n("0").build()); + keyToGet.put("sort_key", AttributeValue.builder().n(ExampleUtils.SORT_KEY_VALUE).build()); final GetItemRequest getRequest = GetItemRequest .builder() diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/MrkDiscoveryMultiKeyringExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/MrkDiscoveryMultiKeyringExample.java index 7f896876c3..ccbf81eaf0 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/MrkDiscoveryMultiKeyringExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/MrkDiscoveryMultiKeyringExample.java @@ -1,6 +1,7 @@ package software.amazon.cryptography.examples.keyring; import java.util.ArrayList; +import software.amazon.cryptography.examples.ExampleUtils; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -159,7 +160,7 @@ public static void MultiMrkDiscoveryKeyringGetItemPutItem( "partition_key", AttributeValue.builder().s("awsKmsMrkDiscoveryMultiKeyringItem").build() ); - item.put("sort_key", AttributeValue.builder().n("0").build()); + item.put("sort_key", AttributeValue.builder().n(ExampleUtils.SORT_KEY_VALUE).build()); item.put( "sensitive_data", AttributeValue.builder().s("encrypt and sign me!").build() @@ -252,7 +253,7 @@ public static void MultiMrkDiscoveryKeyringGetItemPutItem( "partition_key", AttributeValue.builder().s("awsKmsMrkDiscoveryMultiKeyringItem").build() ); - keyToGet.put("sort_key", AttributeValue.builder().n("0").build()); + keyToGet.put("sort_key", AttributeValue.builder().n(ExampleUtils.SORT_KEY_VALUE).build()); final GetItemRequest getRequest = GetItemRequest .builder() diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/MultiKeyringExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/MultiKeyringExample.java index 635f637c23..753730532d 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/MultiKeyringExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/MultiKeyringExample.java @@ -1,6 +1,7 @@ package software.amazon.cryptography.examples.keyring; import com.amazonaws.services.dynamodbv2.datamodeling.internal.Utils; +import software.amazon.cryptography.examples.ExampleUtils; import java.nio.ByteBuffer; import java.security.NoSuchAlgorithmException; import java.security.SecureRandom; @@ -205,7 +206,7 @@ public static void MultiKeyringGetItemPutItem( "partition_key", AttributeValue.builder().s("multiKeyringItem").build() ); - item.put("sort_key", AttributeValue.builder().n("0").build()); + item.put("sort_key", AttributeValue.builder().n(ExampleUtils.SORT_KEY_VALUE).build()); item.put( "sensitive_data", AttributeValue.builder().s("encrypt and sign me!").build() @@ -232,7 +233,7 @@ public static void MultiKeyringGetItemPutItem( "partition_key", AttributeValue.builder().s("multiKeyringItem").build() ); - keyToGet.put("sort_key", AttributeValue.builder().n("0").build()); + keyToGet.put("sort_key", AttributeValue.builder().n(ExampleUtils.SORT_KEY_VALUE).build()); final GetItemRequest getRequest = GetItemRequest .builder() @@ -302,7 +303,7 @@ public static void MultiKeyringGetItemPutItem( ); onlyAesKeyringKeyToGet.put( "sort_key", - AttributeValue.builder().n("0").build() + AttributeValue.builder().n(ExampleUtils.SORT_KEY_VALUE).build() ); final GetItemRequest onlyAesKeyringGetRequest = GetItemRequest diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/MultiMrkKeyringExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/MultiMrkKeyringExample.java index 3024a67397..91ffe7cfb7 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/MultiMrkKeyringExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/MultiMrkKeyringExample.java @@ -1,6 +1,7 @@ package software.amazon.cryptography.examples.keyring; import java.util.Collections; +import software.amazon.cryptography.examples.ExampleUtils; import java.util.HashMap; import java.util.Map; import software.amazon.awssdk.arns.Arn; @@ -189,7 +190,7 @@ public static void MultiMrkKeyringGetItemPutItem( "partition_key", AttributeValue.builder().s("awsKmsMrkMultiKeyringItem").build() ); - item.put("sort_key", AttributeValue.builder().n("0").build()); + item.put("sort_key", AttributeValue.builder().n(ExampleUtils.SORT_KEY_VALUE).build()); item.put( "sensitive_data", AttributeValue.builder().s("encrypt and sign me!").build() @@ -216,7 +217,7 @@ public static void MultiMrkKeyringGetItemPutItem( "partition_key", AttributeValue.builder().s("awsKmsMrkMultiKeyringItem").build() ); - keyToGet.put("sort_key", AttributeValue.builder().n("0").build()); + keyToGet.put("sort_key", AttributeValue.builder().n(ExampleUtils.SORT_KEY_VALUE).build()); final GetItemRequest getRequest = GetItemRequest .builder() @@ -300,7 +301,7 @@ public static void MultiMrkKeyringGetItemPutItem( ); onlyReplicaKeyKeyToGet.put( "sort_key", - AttributeValue.builder().n("0").build() + AttributeValue.builder().n(ExampleUtils.SORT_KEY_VALUE).build() ); final GetItemRequest onlyReplicaKeyGetRequest = GetItemRequest @@ -380,7 +381,7 @@ public static void MultiMrkKeyringGetItemPutItem( "partition_key", AttributeValue.builder().s("awsKmsMrkMultiKeyringItem").build() ); - onlySrkKeyToGet.put("sort_key", AttributeValue.builder().n("0").build()); + onlySrkKeyToGet.put("sort_key", AttributeValue.builder().n(ExampleUtils.SORT_KEY_VALUE).build()); final GetItemRequest onlySrkGetRequest = GetItemRequest .builder() diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/RawAesKeyringExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/RawAesKeyringExample.java index 5ef15b1f1b..dac9f9b899 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/RawAesKeyringExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/RawAesKeyringExample.java @@ -1,6 +1,7 @@ package software.amazon.cryptography.examples.keyring; import java.nio.ByteBuffer; +import software.amazon.cryptography.examples.ExampleUtils; import java.security.NoSuchAlgorithmException; import java.security.SecureRandom; import java.util.HashMap; @@ -158,7 +159,7 @@ public static void RawAesKeyringGetItemPutItem( "partition_key", AttributeValue.builder().s("rawAesKeyringItem").build() ); - item.put("sort_key", AttributeValue.builder().n("0").build()); + item.put("sort_key", AttributeValue.builder().n(ExampleUtils.SORT_KEY_VALUE).build()); item.put( "sensitive_data", AttributeValue.builder().s("encrypt and sign me!").build() @@ -183,7 +184,7 @@ public static void RawAesKeyringGetItemPutItem( "partition_key", AttributeValue.builder().s("rawAesKeyringItem").build() ); - keyToGet.put("sort_key", AttributeValue.builder().n("0").build()); + keyToGet.put("sort_key", AttributeValue.builder().n(ExampleUtils.SORT_KEY_VALUE).build()); final GetItemRequest getRequest = GetItemRequest .builder() diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/RawEcdhKeyringExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/RawEcdhKeyringExample.java index 97fbac6f0c..3b1ea3cdd4 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/RawEcdhKeyringExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/RawEcdhKeyringExample.java @@ -1,6 +1,7 @@ package software.amazon.cryptography.examples.keyring; import java.io.ByteArrayInputStream; +import software.amazon.cryptography.examples.ExampleUtils; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; @@ -440,7 +441,7 @@ public static void PutGetExampleWithKeyring( "partition_key", AttributeValue.builder().s("rawEcdhKeyringItem").build() ); - item.put("sort_key", AttributeValue.builder().n("0").build()); + item.put("sort_key", AttributeValue.builder().n(ExampleUtils.SORT_KEY_VALUE).build()); item.put( "sensitive_data", AttributeValue.builder().s("encrypt and sign me!").build() @@ -465,7 +466,7 @@ public static void PutGetExampleWithKeyring( "partition_key", AttributeValue.builder().s("rawEcdhKeyringItem").build() ); - keyToGet.put("sort_key", AttributeValue.builder().n("0").build()); + keyToGet.put("sort_key", AttributeValue.builder().n(ExampleUtils.SORT_KEY_VALUE).build()); final GetItemRequest getRequest = GetItemRequest .builder() @@ -577,7 +578,7 @@ public static void PutExampleWithKeyring( "partition_key", AttributeValue.builder().s("rawEcdhKeyringItem").build() ); - item.put("sort_key", AttributeValue.builder().n("0").build()); + item.put("sort_key", AttributeValue.builder().n(ExampleUtils.SORT_KEY_VALUE).build()); item.put( "sensitive_data", AttributeValue.builder().s("encrypt and sign me!").build() @@ -687,7 +688,7 @@ public static void GetExampleWithKeyring( "partition_key", AttributeValue.builder().s("rawEcdhKeyringItem").build() ); - keyToGet.put("sort_key", AttributeValue.builder().n("0").build()); + keyToGet.put("sort_key", AttributeValue.builder().n(ExampleUtils.SORT_KEY_VALUE).build()); final GetItemRequest getRequest = GetItemRequest .builder() diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/RawRsaKeyringExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/RawRsaKeyringExample.java index e5b9e608e3..a88c38dd64 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/RawRsaKeyringExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/RawRsaKeyringExample.java @@ -1,6 +1,7 @@ package software.amazon.cryptography.examples.keyring; import java.io.File; +import software.amazon.cryptography.examples.ExampleUtils; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; @@ -212,7 +213,7 @@ public static void RawRsaKeyringGetItemPutItem(String ddbTableName) { "partition_key", AttributeValue.builder().s("rawRsaKeyringItem").build() ); - item.put("sort_key", AttributeValue.builder().n("0").build()); + item.put("sort_key", AttributeValue.builder().n(ExampleUtils.SORT_KEY_VALUE).build()); item.put( "sensitive_data", AttributeValue.builder().s("encrypt and sign me!").build() @@ -237,7 +238,7 @@ public static void RawRsaKeyringGetItemPutItem(String ddbTableName) { "partition_key", AttributeValue.builder().s("rawRsaKeyringItem").build() ); - keyToGet.put("sort_key", AttributeValue.builder().n("0").build()); + keyToGet.put("sort_key", AttributeValue.builder().n(ExampleUtils.SORT_KEY_VALUE).build()); final GetItemRequest getRequest = GetItemRequest .builder() diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/SharedCacheAcrossHierarchicalKeyringsExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/SharedCacheAcrossHierarchicalKeyringsExample.java index dfed4b84de..d4309fa07c 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/SharedCacheAcrossHierarchicalKeyringsExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/SharedCacheAcrossHierarchicalKeyringsExample.java @@ -1,6 +1,7 @@ package software.amazon.cryptography.examples.keyring; import java.util.HashMap; +import software.amazon.cryptography.examples.ExampleUtils; import java.util.Map; import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration; import software.amazon.awssdk.services.dynamodb.DynamoDbClient; @@ -360,7 +361,7 @@ public static void PutGetItems( // information. final HashMap item = new HashMap<>(); item.put("partition_key", AttributeValue.builder().s("id").build()); - item.put("sort_key", AttributeValue.builder().n("0").build()); + item.put("sort_key", AttributeValue.builder().n(ExampleUtils.SORT_KEY_VALUE).build()); item.put( "sensitive_data", AttributeValue.builder().s("encrypt and sign me!").build() @@ -385,7 +386,7 @@ public static void PutGetItems( // information. final HashMap keyToGet = new HashMap<>(); keyToGet.put("partition_key", AttributeValue.builder().s("id").build()); - keyToGet.put("sort_key", AttributeValue.builder().n("0").build()); + keyToGet.put("sort_key", AttributeValue.builder().n(ExampleUtils.SORT_KEY_VALUE).build()); final GetItemRequest getRequest = GetItemRequest .builder() From e288b5583f8853a2d2c23d0258e60ee254979265 Mon Sep 17 00:00:00 2001 From: Bikram Sharma Date: Fri, 10 Apr 2026 14:04:00 -0700 Subject: [PATCH 2/5] chore(java): attempts to deconflict tests across different java and OS versions --- .../cryptography/examples/ExampleUtils.java | 21 ++++++++++++---- .../clientsupplier/ClientSupplierExample.java | 12 +++++----- .../enhanced/EnhancedPutGetExample.java | 8 +++---- .../enhanced/LombokPutGetExample.java | 6 ++--- .../examples/enhanced/SingleTableExample.java | 24 +++++++++---------- .../TableSchemaBuilderPutGetExample.java | 6 ++--- .../ItemEncryptDecryptExample.java | 7 +++--- .../keyring/HierarchicalKeyringExample.java | 8 +++---- .../keyring/KmsEcdhKeyringExample.java | 12 +++++----- .../keyring/KmsRsaKeyringExample.java | 8 +++---- .../MrkDiscoveryMultiKeyringExample.java | 8 +++---- .../examples/keyring/MultiKeyringExample.java | 12 +++++----- .../keyring/MultiMrkKeyringExample.java | 16 ++++++------- .../keyring/RawAesKeyringExample.java | 8 +++---- .../keyring/RawEcdhKeyringExample.java | 16 ++++++------- .../keyring/RawRsaKeyringExample.java | 8 +++---- ...acheAcrossHierarchicalKeyringsExample.java | 8 +++---- .../TestClientSupplierExample.java | 11 +++++++++ .../keyring/TestKmsEcdhKeyringExample.java | 2 +- 19 files changed, 112 insertions(+), 89 deletions(-) diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/ExampleUtils.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/ExampleUtils.java index 8f9a667e98..20928b7bee 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/ExampleUtils.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/ExampleUtils.java @@ -5,14 +5,27 @@ import java.util.concurrent.ThreadLocalRandom; /** - * Shared utilities for examples. The SORT_KEY constant provides a unique value + * Shared utilities for examples. The TEST_PREFIX provides a unique suffix * per JVM process so that parallel CI matrix jobs (different Java versions / OS) * do not overwrite each other's items in the shared DynamoDB test table. + * + * Each example uses a hardcoded partition key like "rawEcdhKeyringItem". + * In CI, multiple JVMs run in parallel against the same table. Without + * isolation, one JVM can overwrite another's item, causing decrypt failures. + * By appending a random prefix, each JVM writes to its own partition key + * (e.g., "rawEcdhKeyringItem-482913") while keeping cross-example reads + * working within the same JVM. */ public class ExampleUtils { - public static final int SORT_KEY = - ThreadLocalRandom.current().nextInt(100000, 999999); + private static final String TEST_PREFIX = + String.valueOf(ThreadLocalRandom.current().nextInt(100000, 999999)); - public static final String SORT_KEY_VALUE = String.valueOf(SORT_KEY); + /** + * Returns a partition key value unique to this JVM process. + * Example: "rawEcdhKeyringItem" becomes "rawEcdhKeyringItem-482913" + */ + public static String uniquePk(String base) { + return base + "-" + TEST_PREFIX; + } } diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/clientsupplier/ClientSupplierExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/clientsupplier/ClientSupplierExample.java index bf7d31c4e2..3eed398273 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/clientsupplier/ClientSupplierExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/clientsupplier/ClientSupplierExample.java @@ -167,9 +167,9 @@ public static void ClientSupplierPutItemGetItem( final HashMap item = new HashMap<>(); item.put( "partition_key", - AttributeValue.builder().s("clientSupplierItem").build() + AttributeValue.builder().s(ExampleUtils.uniquePk("clientSupplierItem")).build() ); - item.put("sort_key", AttributeValue.builder().n(ExampleUtils.SORT_KEY_VALUE).build()); + item.put("sort_key", AttributeValue.builder().n("0").build()); item.put( "sensitive_data", AttributeValue.builder().s("encrypt and sign me!").build() @@ -192,9 +192,9 @@ public static void ClientSupplierPutItemGetItem( final HashMap keyToGet = new HashMap<>(); keyToGet.put( "partition_key", - AttributeValue.builder().s("clientSupplierItem").build() + AttributeValue.builder().s(ExampleUtils.uniquePk("clientSupplierItem")).build() ); - keyToGet.put("sort_key", AttributeValue.builder().n(ExampleUtils.SORT_KEY_VALUE).build()); + keyToGet.put("sort_key", AttributeValue.builder().n("0").build()); final GetItemRequest getRequest = GetItemRequest .builder() @@ -290,11 +290,11 @@ public static void ClientSupplierPutItemGetItem( new HashMap<>(); onlyReplicaKeyKeyToGet.put( "partition_key", - AttributeValue.builder().s("awsKmsMrkMultiKeyringItem").build() + AttributeValue.builder().s(ExampleUtils.uniquePk("awsKmsMrkMultiKeyringItem")).build() ); onlyReplicaKeyKeyToGet.put( "sort_key", - AttributeValue.builder().n(ExampleUtils.SORT_KEY_VALUE).build() + AttributeValue.builder().n("0").build() ); final GetItemRequest onlyReplicaKeyGetRequest = GetItemRequest diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/enhanced/EnhancedPutGetExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/enhanced/EnhancedPutGetExample.java index 9ae5282699..e6c9169fa6 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/enhanced/EnhancedPutGetExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/enhanced/EnhancedPutGetExample.java @@ -155,8 +155,8 @@ public static void PutItemGetItem(String kmsKeyId, String ddbTableName) { // The item will be encrypted client-side according to your // configuration above before it is sent to DynamoDb. final SimpleClass4 item = new SimpleClass4(); - item.setPartitionKey("EnhancedPutGetExample"); - item.setSortKey(ExampleUtils.SORT_KEY); + item.setPartitionKey(ExampleUtils.uniquePk("EnhancedPutGetExample")); + item.setSortKey(0); item.setAttribute1("encrypt and sign me!"); item.setAttribute2("sign me!"); item.setAttribute3("ignore me!"); @@ -169,7 +169,7 @@ public static void PutItemGetItem(String kmsKeyId, String ddbTableName) { // original item. final Key key = Key .builder() - .partitionValue("EnhancedPutGetExample") + .partitionValue(ExampleUtils.uniquePk("EnhancedPutGetExample")) .sortValue(0) .build(); @@ -183,7 +183,7 @@ public static void PutItemGetItem(String kmsKeyId, String ddbTableName) { // retrieve the same record via a Query PageIterable items = table.query( - QueryConditional.keyEqualTo(k -> k.partitionValue("EnhancedPutGetExample") + QueryConditional.keyEqualTo(k -> k.partitionValue(ExampleUtils.uniquePk("EnhancedPutGetExample")) ) ); List itemList = new ArrayList(); diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/enhanced/LombokPutGetExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/enhanced/LombokPutGetExample.java index 8ade3c2dec..c638aea50c 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/enhanced/LombokPutGetExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/enhanced/LombokPutGetExample.java @@ -165,8 +165,8 @@ public static void PutItemGetItem(String kmsKeyId, String ddbTableName) { // configuration above before it is sent to DynamoDb. final SimpleViaLombok.SimpleViaLombokBuilder itemBuilder = SimpleViaLombok.builder(); - itemBuilder.partitionKey("LombokPutGetExample"); - itemBuilder.sortKey(ExampleUtils.SORT_KEY); + itemBuilder.partitionKey(ExampleUtils.uniquePk("LombokPutGetExample")); + itemBuilder.sortKey(0); itemBuilder.attribute1("encrypt and sign me!"); itemBuilder.attribute2("sign me!"); itemBuilder.attribute3("ignore me!"); @@ -178,7 +178,7 @@ public static void PutItemGetItem(String kmsKeyId, String ddbTableName) { // original item. final Key key = Key .builder() - .partitionValue("LombokPutGetExample") + .partitionValue(ExampleUtils.uniquePk("LombokPutGetExample")) .sortValue(0) .build(); diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/enhanced/SingleTableExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/enhanced/SingleTableExample.java index 5af9140fa1..306c166d38 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/enhanced/SingleTableExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/enhanced/SingleTableExample.java @@ -170,22 +170,22 @@ public static void TransactWriteItems(String kmsKeyId, String ddbTableName) { // The item will be encrypted client-side according to your // configuration above before it is sent to DynamoDb. final SimpleClass item1 = new SimpleClass(); - item1.setPartitionKey("EnhancedPutGetExample1"); - item1.setSortKey(ExampleUtils.SORT_KEY); + item1.setPartitionKey(ExampleUtils.uniquePk("EnhancedPutGetExample1")); + item1.setSortKey(0); item1.setAttribute1("item1 encrypt and sign me!"); item1.setAttribute2("item1 sign me!"); item1.setAttribute3("item1 ignore me!"); final SimpleClass2 item2 = new SimpleClass2(); - item2.setPartitionKey("EnhancedPutGetExample2"); - item2.setSortKey(ExampleUtils.SORT_KEY); + item2.setPartitionKey(ExampleUtils.uniquePk("EnhancedPutGetExample2")); + item2.setSortKey(0); item2.setAttribute4("item2 encrypt and sign me!"); item2.setAttribute5("item2 sign me!"); item2.setAttribute3("item2 ignore me!"); final SimpleClass3 item3 = new SimpleClass3(); - item3.setPartitionKey("EnhancedPutGetExample3"); - item3.setSortKey(ExampleUtils.SORT_KEY); + item3.setPartitionKey(ExampleUtils.uniquePk("EnhancedPutGetExample3")); + item3.setSortKey(0); item3.setAttribute6("item3 encrypt and sign me!"); item3.setAttribute2("item3 sign me!"); item3.setAttribute7("item3 sign and include me!"); @@ -204,16 +204,16 @@ public static void TransactWriteItems(String kmsKeyId, String ddbTableName) { // The item will be decrypted client-side, and you will get back the // original item. final SimpleClass key1 = new SimpleClass(); - key1.setPartitionKey("EnhancedPutGetExample1"); - key1.setSortKey(ExampleUtils.SORT_KEY); + key1.setPartitionKey(ExampleUtils.uniquePk("EnhancedPutGetExample1")); + key1.setSortKey(0); final SimpleClass2 key2 = new SimpleClass2(); - key2.setPartitionKey("EnhancedPutGetExample2"); - key2.setSortKey(ExampleUtils.SORT_KEY); + key2.setPartitionKey(ExampleUtils.uniquePk("EnhancedPutGetExample2")); + key2.setSortKey(0); final SimpleClass3 key3 = new SimpleClass3(); - key3.setPartitionKey("EnhancedPutGetExample3"); - key3.setSortKey(ExampleUtils.SORT_KEY); + key3.setPartitionKey(ExampleUtils.uniquePk("EnhancedPutGetExample3")); + key3.setSortKey(0); final TransactGetItemsEnhancedRequest getRequest = TransactGetItemsEnhancedRequest diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/enhanced/TableSchemaBuilderPutGetExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/enhanced/TableSchemaBuilderPutGetExample.java index 21d2e55ffb..d9ff44ad4c 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/enhanced/TableSchemaBuilderPutGetExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/enhanced/TableSchemaBuilderPutGetExample.java @@ -214,8 +214,8 @@ public static void PutItemGetItem(String kmsKeyId, String ddbTableName) { // The item will be encrypted client-side according to your // configuration above before it is sent to DynamoDb. final SimpleClass item = new SimpleClass(); - item.setPartitionKey("TableSchemaBuilderPutGetExample"); - item.setSortKey(ExampleUtils.SORT_KEY); + item.setPartitionKey(ExampleUtils.uniquePk("TableSchemaBuilderPutGetExample")); + item.setSortKey(0); item.setAttribute1("encrypt and sign me!"); item.setAttribute2("sign me!"); item.setAttribute3("ignore me!"); @@ -226,7 +226,7 @@ public static void PutItemGetItem(String kmsKeyId, String ddbTableName) { // original item. final Key key = Key .builder() - .partitionValue("TableSchemaBuilderPutGetExample") + .partitionValue(ExampleUtils.uniquePk("TableSchemaBuilderPutGetExample")) .sortValue(0) .build(); diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/itemencryptor/ItemEncryptDecryptExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/itemencryptor/ItemEncryptDecryptExample.java index 75aa96e0b6..ea6b296054 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/itemencryptor/ItemEncryptDecryptExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/itemencryptor/ItemEncryptDecryptExample.java @@ -1,7 +1,6 @@ package software.amazon.cryptography.examples.itemencryptor; import java.util.HashMap; -import software.amazon.cryptography.examples.ExampleUtils; import java.util.Map; import software.amazon.awssdk.services.dynamodb.model.*; import software.amazon.cryptography.dbencryptionsdk.dynamodb.itemencryptor.DynamoDbItemEncryptor; @@ -127,7 +126,7 @@ public static void PutItemGetItem(String kmsKeyId, String ddbTableName) { "partition_key", AttributeValue.builder().s("ItemEncryptDecryptExample").build() ); - originalItem.put("sort_key", AttributeValue.builder().n(ExampleUtils.SORT_KEY_VALUE).build()); + originalItem.put("sort_key", AttributeValue.builder().n("0").build()); originalItem.put( "attribute1", AttributeValue.builder().s("encrypt and sign me!").build() @@ -152,7 +151,7 @@ public static void PutItemGetItem(String kmsKeyId, String ddbTableName) { .get("partition_key") .s() .equals("ItemEncryptDecryptExample"); - assert encryptedItem.get("sort_key").n().equals(ExampleUtils.SORT_KEY_VALUE); + assert encryptedItem.get("sort_key").n().equals("0"); assert encryptedItem.get("attribute1").b() != null; // 7. Directly decrypt the encrypted item using the DynamoDb Item Encryptor @@ -167,7 +166,7 @@ public static void PutItemGetItem(String kmsKeyId, String ddbTableName) { .get("partition_key") .s() .equals("ItemEncryptDecryptExample"); - assert decryptedItem.get("sort_key").n().equals(ExampleUtils.SORT_KEY_VALUE); + assert decryptedItem.get("sort_key").n().equals("0"); assert decryptedItem.get("attribute1").s().equals("encrypt and sign me!"); } diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/HierarchicalKeyringExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/HierarchicalKeyringExample.java index 5c8ae614f4..1f93b1695c 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/HierarchicalKeyringExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/HierarchicalKeyringExample.java @@ -236,8 +236,8 @@ public static void HierarchicalKeyringGetItemPutItem( // based on the code we wrote in the ExampleBranchKeySupplier, // `tenant1BranchKeyId` will be used to encrypt this item. final HashMap item = new HashMap<>(); - item.put("partition_key", AttributeValue.builder().s("tenant1Id").build()); - item.put("sort_key", AttributeValue.builder().n(ExampleUtils.SORT_KEY_VALUE).build()); + item.put("partition_key", AttributeValue.builder().s(ExampleUtils.uniquePk("tenant1Id")).build()); + item.put("sort_key", AttributeValue.builder().n("0").build()); item.put( "tenant_sensitive_data", AttributeValue.builder().s("encrypt and sign me!").build() @@ -263,9 +263,9 @@ public static void HierarchicalKeyringGetItemPutItem( final HashMap keyToGet = new HashMap<>(); keyToGet.put( "partition_key", - AttributeValue.builder().s("tenant1Id").build() + AttributeValue.builder().s(ExampleUtils.uniquePk("tenant1Id")).build() ); - keyToGet.put("sort_key", AttributeValue.builder().n(ExampleUtils.SORT_KEY_VALUE).build()); + keyToGet.put("sort_key", AttributeValue.builder().n("0").build()); final GetItemRequest getRequest = GetItemRequest .builder() diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/KmsEcdhKeyringExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/KmsEcdhKeyringExample.java index 2ba535170e..b2cb8e9ef8 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/KmsEcdhKeyringExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/KmsEcdhKeyringExample.java @@ -340,9 +340,9 @@ private static void GetItemWithKeyring( final HashMap keyToGet = new HashMap<>(); keyToGet.put( "partition_key", - AttributeValue.builder().s("awsKmsEcdhKeyringItem").build() + AttributeValue.builder().s(ExampleUtils.uniquePk("awsKmsEcdhKeyringItem")).build() ); - keyToGet.put("sort_key", AttributeValue.builder().n(ExampleUtils.SORT_KEY_VALUE).build()); + keyToGet.put("sort_key", AttributeValue.builder().n("0").build()); final GetItemRequest getRequest = GetItemRequest .builder() @@ -457,9 +457,9 @@ private static void PutGetItemWithKeyring( final HashMap item = new HashMap<>(); item.put( "partition_key", - AttributeValue.builder().s("awsKmsEcdhKeyringItem").build() + AttributeValue.builder().s(ExampleUtils.uniquePk("awsKmsEcdhKeyringItem")).build() ); - item.put("sort_key", AttributeValue.builder().n(ExampleUtils.SORT_KEY_VALUE).build()); + item.put("sort_key", AttributeValue.builder().n("0").build()); item.put( "sensitive_data", AttributeValue.builder().s("encrypt and sign me!").build() @@ -482,9 +482,9 @@ private static void PutGetItemWithKeyring( final HashMap keyToGet = new HashMap<>(); keyToGet.put( "partition_key", - AttributeValue.builder().s("awsKmsEcdhKeyringItem").build() + AttributeValue.builder().s(ExampleUtils.uniquePk("awsKmsEcdhKeyringItem")).build() ); - keyToGet.put("sort_key", AttributeValue.builder().n(ExampleUtils.SORT_KEY_VALUE).build()); + keyToGet.put("sort_key", AttributeValue.builder().n("0").build()); final GetItemRequest getRequest = GetItemRequest .builder() diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/KmsRsaKeyringExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/KmsRsaKeyringExample.java index 21fc1442a2..b80b994412 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/KmsRsaKeyringExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/KmsRsaKeyringExample.java @@ -202,9 +202,9 @@ public static void KmsRsaKeyringGetItemPutItem( final HashMap item = new HashMap<>(); item.put( "partition_key", - AttributeValue.builder().s("awsKmsRsaKeyringItem").build() + AttributeValue.builder().s(ExampleUtils.uniquePk("awsKmsRsaKeyringItem")).build() ); - item.put("sort_key", AttributeValue.builder().n(ExampleUtils.SORT_KEY_VALUE).build()); + item.put("sort_key", AttributeValue.builder().n("0").build()); item.put( "sensitive_data", AttributeValue.builder().s("encrypt and sign me!").build() @@ -227,9 +227,9 @@ public static void KmsRsaKeyringGetItemPutItem( final HashMap keyToGet = new HashMap<>(); keyToGet.put( "partition_key", - AttributeValue.builder().s("awsKmsRsaKeyringItem").build() + AttributeValue.builder().s(ExampleUtils.uniquePk("awsKmsRsaKeyringItem")).build() ); - keyToGet.put("sort_key", AttributeValue.builder().n(ExampleUtils.SORT_KEY_VALUE).build()); + keyToGet.put("sort_key", AttributeValue.builder().n("0").build()); final GetItemRequest getRequest = GetItemRequest .builder() diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/MrkDiscoveryMultiKeyringExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/MrkDiscoveryMultiKeyringExample.java index ccbf81eaf0..d834bfd22e 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/MrkDiscoveryMultiKeyringExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/MrkDiscoveryMultiKeyringExample.java @@ -158,9 +158,9 @@ public static void MultiMrkDiscoveryKeyringGetItemPutItem( final HashMap item = new HashMap<>(); item.put( "partition_key", - AttributeValue.builder().s("awsKmsMrkDiscoveryMultiKeyringItem").build() + AttributeValue.builder().s(ExampleUtils.uniquePk("awsKmsMrkDiscoveryMultiKeyringItem")).build() ); - item.put("sort_key", AttributeValue.builder().n(ExampleUtils.SORT_KEY_VALUE).build()); + item.put("sort_key", AttributeValue.builder().n("0").build()); item.put( "sensitive_data", AttributeValue.builder().s("encrypt and sign me!").build() @@ -251,9 +251,9 @@ public static void MultiMrkDiscoveryKeyringGetItemPutItem( final HashMap keyToGet = new HashMap<>(); keyToGet.put( "partition_key", - AttributeValue.builder().s("awsKmsMrkDiscoveryMultiKeyringItem").build() + AttributeValue.builder().s(ExampleUtils.uniquePk("awsKmsMrkDiscoveryMultiKeyringItem")).build() ); - keyToGet.put("sort_key", AttributeValue.builder().n(ExampleUtils.SORT_KEY_VALUE).build()); + keyToGet.put("sort_key", AttributeValue.builder().n("0").build()); final GetItemRequest getRequest = GetItemRequest .builder() diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/MultiKeyringExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/MultiKeyringExample.java index 753730532d..b5827315c8 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/MultiKeyringExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/MultiKeyringExample.java @@ -204,9 +204,9 @@ public static void MultiKeyringGetItemPutItem( final HashMap item = new HashMap<>(); item.put( "partition_key", - AttributeValue.builder().s("multiKeyringItem").build() + AttributeValue.builder().s(ExampleUtils.uniquePk("multiKeyringItem")).build() ); - item.put("sort_key", AttributeValue.builder().n(ExampleUtils.SORT_KEY_VALUE).build()); + item.put("sort_key", AttributeValue.builder().n("0").build()); item.put( "sensitive_data", AttributeValue.builder().s("encrypt and sign me!").build() @@ -231,9 +231,9 @@ public static void MultiKeyringGetItemPutItem( final HashMap keyToGet = new HashMap<>(); keyToGet.put( "partition_key", - AttributeValue.builder().s("multiKeyringItem").build() + AttributeValue.builder().s(ExampleUtils.uniquePk("multiKeyringItem")).build() ); - keyToGet.put("sort_key", AttributeValue.builder().n(ExampleUtils.SORT_KEY_VALUE).build()); + keyToGet.put("sort_key", AttributeValue.builder().n("0").build()); final GetItemRequest getRequest = GetItemRequest .builder() @@ -299,11 +299,11 @@ public static void MultiKeyringGetItemPutItem( new HashMap<>(); onlyAesKeyringKeyToGet.put( "partition_key", - AttributeValue.builder().s("multiKeyringItem").build() + AttributeValue.builder().s(ExampleUtils.uniquePk("multiKeyringItem")).build() ); onlyAesKeyringKeyToGet.put( "sort_key", - AttributeValue.builder().n(ExampleUtils.SORT_KEY_VALUE).build() + AttributeValue.builder().n("0").build() ); final GetItemRequest onlyAesKeyringGetRequest = GetItemRequest diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/MultiMrkKeyringExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/MultiMrkKeyringExample.java index 91ffe7cfb7..9f556c0d34 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/MultiMrkKeyringExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/MultiMrkKeyringExample.java @@ -188,9 +188,9 @@ public static void MultiMrkKeyringGetItemPutItem( final HashMap item = new HashMap<>(); item.put( "partition_key", - AttributeValue.builder().s("awsKmsMrkMultiKeyringItem").build() + AttributeValue.builder().s(ExampleUtils.uniquePk("awsKmsMrkMultiKeyringItem")).build() ); - item.put("sort_key", AttributeValue.builder().n(ExampleUtils.SORT_KEY_VALUE).build()); + item.put("sort_key", AttributeValue.builder().n("0").build()); item.put( "sensitive_data", AttributeValue.builder().s("encrypt and sign me!").build() @@ -215,9 +215,9 @@ public static void MultiMrkKeyringGetItemPutItem( final HashMap keyToGet = new HashMap<>(); keyToGet.put( "partition_key", - AttributeValue.builder().s("awsKmsMrkMultiKeyringItem").build() + AttributeValue.builder().s(ExampleUtils.uniquePk("awsKmsMrkMultiKeyringItem")).build() ); - keyToGet.put("sort_key", AttributeValue.builder().n(ExampleUtils.SORT_KEY_VALUE).build()); + keyToGet.put("sort_key", AttributeValue.builder().n("0").build()); final GetItemRequest getRequest = GetItemRequest .builder() @@ -297,11 +297,11 @@ public static void MultiMrkKeyringGetItemPutItem( new HashMap<>(); onlyReplicaKeyKeyToGet.put( "partition_key", - AttributeValue.builder().s("awsKmsMrkMultiKeyringItem").build() + AttributeValue.builder().s(ExampleUtils.uniquePk("awsKmsMrkMultiKeyringItem")).build() ); onlyReplicaKeyKeyToGet.put( "sort_key", - AttributeValue.builder().n(ExampleUtils.SORT_KEY_VALUE).build() + AttributeValue.builder().n("0").build() ); final GetItemRequest onlyReplicaKeyGetRequest = GetItemRequest @@ -379,9 +379,9 @@ public static void MultiMrkKeyringGetItemPutItem( final HashMap onlySrkKeyToGet = new HashMap<>(); onlySrkKeyToGet.put( "partition_key", - AttributeValue.builder().s("awsKmsMrkMultiKeyringItem").build() + AttributeValue.builder().s(ExampleUtils.uniquePk("awsKmsMrkMultiKeyringItem")).build() ); - onlySrkKeyToGet.put("sort_key", AttributeValue.builder().n(ExampleUtils.SORT_KEY_VALUE).build()); + onlySrkKeyToGet.put("sort_key", AttributeValue.builder().n("0").build()); final GetItemRequest onlySrkGetRequest = GetItemRequest .builder() diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/RawAesKeyringExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/RawAesKeyringExample.java index dac9f9b899..446001299a 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/RawAesKeyringExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/RawAesKeyringExample.java @@ -157,9 +157,9 @@ public static void RawAesKeyringGetItemPutItem( final HashMap item = new HashMap<>(); item.put( "partition_key", - AttributeValue.builder().s("rawAesKeyringItem").build() + AttributeValue.builder().s(ExampleUtils.uniquePk("rawAesKeyringItem")).build() ); - item.put("sort_key", AttributeValue.builder().n(ExampleUtils.SORT_KEY_VALUE).build()); + item.put("sort_key", AttributeValue.builder().n("0").build()); item.put( "sensitive_data", AttributeValue.builder().s("encrypt and sign me!").build() @@ -182,9 +182,9 @@ public static void RawAesKeyringGetItemPutItem( final HashMap keyToGet = new HashMap<>(); keyToGet.put( "partition_key", - AttributeValue.builder().s("rawAesKeyringItem").build() + AttributeValue.builder().s(ExampleUtils.uniquePk("rawAesKeyringItem")).build() ); - keyToGet.put("sort_key", AttributeValue.builder().n(ExampleUtils.SORT_KEY_VALUE).build()); + keyToGet.put("sort_key", AttributeValue.builder().n("0").build()); final GetItemRequest getRequest = GetItemRequest .builder() diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/RawEcdhKeyringExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/RawEcdhKeyringExample.java index 3b1ea3cdd4..db919d6538 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/RawEcdhKeyringExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/RawEcdhKeyringExample.java @@ -439,9 +439,9 @@ public static void PutGetExampleWithKeyring( final HashMap item = new HashMap<>(); item.put( "partition_key", - AttributeValue.builder().s("rawEcdhKeyringItem").build() + AttributeValue.builder().s(ExampleUtils.uniquePk("rawEcdhKeyringItem")).build() ); - item.put("sort_key", AttributeValue.builder().n(ExampleUtils.SORT_KEY_VALUE).build()); + item.put("sort_key", AttributeValue.builder().n("0").build()); item.put( "sensitive_data", AttributeValue.builder().s("encrypt and sign me!").build() @@ -464,9 +464,9 @@ public static void PutGetExampleWithKeyring( final HashMap keyToGet = new HashMap<>(); keyToGet.put( "partition_key", - AttributeValue.builder().s("rawEcdhKeyringItem").build() + AttributeValue.builder().s(ExampleUtils.uniquePk("rawEcdhKeyringItem")).build() ); - keyToGet.put("sort_key", AttributeValue.builder().n(ExampleUtils.SORT_KEY_VALUE).build()); + keyToGet.put("sort_key", AttributeValue.builder().n("0").build()); final GetItemRequest getRequest = GetItemRequest .builder() @@ -576,9 +576,9 @@ public static void PutExampleWithKeyring( final HashMap item = new HashMap<>(); item.put( "partition_key", - AttributeValue.builder().s("rawEcdhKeyringItem").build() + AttributeValue.builder().s(ExampleUtils.uniquePk("rawEcdhKeyringItem")).build() ); - item.put("sort_key", AttributeValue.builder().n(ExampleUtils.SORT_KEY_VALUE).build()); + item.put("sort_key", AttributeValue.builder().n("0").build()); item.put( "sensitive_data", AttributeValue.builder().s("encrypt and sign me!").build() @@ -686,9 +686,9 @@ public static void GetExampleWithKeyring( final HashMap keyToGet = new HashMap<>(); keyToGet.put( "partition_key", - AttributeValue.builder().s("rawEcdhKeyringItem").build() + AttributeValue.builder().s(ExampleUtils.uniquePk("rawEcdhKeyringItem")).build() ); - keyToGet.put("sort_key", AttributeValue.builder().n(ExampleUtils.SORT_KEY_VALUE).build()); + keyToGet.put("sort_key", AttributeValue.builder().n("0").build()); final GetItemRequest getRequest = GetItemRequest .builder() diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/RawRsaKeyringExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/RawRsaKeyringExample.java index a88c38dd64..e4a24a12c1 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/RawRsaKeyringExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/RawRsaKeyringExample.java @@ -211,9 +211,9 @@ public static void RawRsaKeyringGetItemPutItem(String ddbTableName) { final HashMap item = new HashMap<>(); item.put( "partition_key", - AttributeValue.builder().s("rawRsaKeyringItem").build() + AttributeValue.builder().s(ExampleUtils.uniquePk("rawRsaKeyringItem")).build() ); - item.put("sort_key", AttributeValue.builder().n(ExampleUtils.SORT_KEY_VALUE).build()); + item.put("sort_key", AttributeValue.builder().n("0").build()); item.put( "sensitive_data", AttributeValue.builder().s("encrypt and sign me!").build() @@ -236,9 +236,9 @@ public static void RawRsaKeyringGetItemPutItem(String ddbTableName) { final HashMap keyToGet = new HashMap<>(); keyToGet.put( "partition_key", - AttributeValue.builder().s("rawRsaKeyringItem").build() + AttributeValue.builder().s(ExampleUtils.uniquePk("rawRsaKeyringItem")).build() ); - keyToGet.put("sort_key", AttributeValue.builder().n(ExampleUtils.SORT_KEY_VALUE).build()); + keyToGet.put("sort_key", AttributeValue.builder().n("0").build()); final GetItemRequest getRequest = GetItemRequest .builder() diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/SharedCacheAcrossHierarchicalKeyringsExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/SharedCacheAcrossHierarchicalKeyringsExample.java index d4309fa07c..79670d516c 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/SharedCacheAcrossHierarchicalKeyringsExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/SharedCacheAcrossHierarchicalKeyringsExample.java @@ -360,8 +360,8 @@ public static void PutGetItems( // BranchKeyIdSupplier as per your use-case. See the HierarchicalKeyringsExample.java for more // information. final HashMap item = new HashMap<>(); - item.put("partition_key", AttributeValue.builder().s("id").build()); - item.put("sort_key", AttributeValue.builder().n(ExampleUtils.SORT_KEY_VALUE).build()); + item.put("partition_key", AttributeValue.builder().s(ExampleUtils.uniquePk("id")).build()); + item.put("sort_key", AttributeValue.builder().n("0").build()); item.put( "sensitive_data", AttributeValue.builder().s("encrypt and sign me!").build() @@ -385,8 +385,8 @@ public static void PutGetItems( // BranchKeyIdSupplier as per your use-case. See the HierarchicalKeyringsExample.java for more // information. final HashMap keyToGet = new HashMap<>(); - keyToGet.put("partition_key", AttributeValue.builder().s("id").build()); - keyToGet.put("sort_key", AttributeValue.builder().n(ExampleUtils.SORT_KEY_VALUE).build()); + keyToGet.put("partition_key", AttributeValue.builder().s(ExampleUtils.uniquePk("id")).build()); + keyToGet.put("sort_key", AttributeValue.builder().n("0").build()); final GetItemRequest getRequest = GetItemRequest .builder() diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/clientsupplier/TestClientSupplierExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/clientsupplier/TestClientSupplierExample.java index 6c7a4069ed..176bda438d 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/clientsupplier/TestClientSupplierExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/clientsupplier/TestClientSupplierExample.java @@ -5,6 +5,7 @@ import org.testng.annotations.Test; import software.amazon.awssdk.regions.Region; import software.amazon.cryptography.examples.TestUtils; +import software.amazon.cryptography.examples.keyring.MultiMrkKeyringExample; public class TestClientSupplierExample { @@ -15,6 +16,16 @@ public void TestClientSupplierExample() { ); List regions = Collections.singletonList(Region.EU_WEST_1.id()); + // ClientSupplierExample reads an item written by MultiMrkKeyringExample + // (partition_key = "awsKmsMrkMultiKeyringItem") to demonstrate discovery + // decryption with a client supplier. Ensure that item exists first. + MultiMrkKeyringExample.MultiMrkKeyringGetItemPutItem( + TestUtils.TEST_DDB_TABLE_NAME, + TestUtils.TEST_MRK_KEY_ID, + TestUtils.TEST_KMS_KEY_ID, + TestUtils.TEST_MRK_REPLICA_KEY_ID_US_EAST_1 + ); + ClientSupplierExample.ClientSupplierPutItemGetItem( TestUtils.TEST_DDB_TABLE_NAME, // Note that we pass in an MRK in us-east-1... diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/keyring/TestKmsEcdhKeyringExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/keyring/TestKmsEcdhKeyringExample.java index 7495261af3..e304715de4 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/keyring/TestKmsEcdhKeyringExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/keyring/TestKmsEcdhKeyringExample.java @@ -35,7 +35,7 @@ public void TestKmsEcdhKeyringExampleStatic() { ); } - @Test + @Test(dependsOnMethods = {"TestKmsEcdhKeyringExampleStatic"}) public void TestKmsEcdhKeyringExampleDiscovery() { // In this example you do not need to provide the recipient ECC Public Key. // On initialization, the keyring will call KMS:getPublicKey on the configured From b7109f33d47bd4331a7b398dfe2f878b12e28891 Mon Sep 17 00:00:00 2001 From: Bikram Sharma Date: Fri, 10 Apr 2026 14:24:02 -0700 Subject: [PATCH 3/5] chore(java): fixing bugs in test scenario leading to failures --- .../services/dynamodbv2/mapper/integration/ScanITCase.java | 3 ++- .../software/amazon/cryptography/examples/ExampleUtils.java | 5 +++-- .../examples/keyring/HierarchicalKeyringExample.java | 5 ++--- .../SharedCacheAcrossHierarchicalKeyringsExample.java | 5 ++--- .../examples/keyring/TestKmsEcdhKeyringExample.java | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/DynamoDbEncryption/runtimes/java/src/test/sdkv1/com/amazonaws/services/dynamodbv2/mapper/integration/ScanITCase.java b/DynamoDbEncryption/runtimes/java/src/test/sdkv1/com/amazonaws/services/dynamodbv2/mapper/integration/ScanITCase.java index 2f9a423399..93d74c8819 100644 --- a/DynamoDbEncryption/runtimes/java/src/test/sdkv1/com/amazonaws/services/dynamodbv2/mapper/integration/ScanITCase.java +++ b/DynamoDbEncryption/runtimes/java/src/test/sdkv1/com/amazonaws/services/dynamodbv2/mapper/integration/ScanITCase.java @@ -238,7 +238,8 @@ public void testParallelScanExceptionHandling() { assertNotNull(ase.getErrorType()); assertNotNull(ase.getMessage()); } catch (Exception e) { - fail("Should have seen the AmazonServiceException"); + fail("Should have seen the AmazonServiceException, but got: " + + e.getClass().getName() + ": " + e.getMessage()); } } diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/ExampleUtils.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/ExampleUtils.java index 20928b7bee..f4b8fb1a86 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/ExampleUtils.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/ExampleUtils.java @@ -18,8 +18,9 @@ */ public class ExampleUtils { - private static final String TEST_PREFIX = - String.valueOf(ThreadLocalRandom.current().nextInt(100000, 999999)); + private static final String TEST_PREFIX = String.valueOf( + ThreadLocalRandom.current().nextInt(100000, 999999) + ); /** * Returns a partition key value unique to this JVM process. diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/HierarchicalKeyringExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/HierarchicalKeyringExample.java index 1f93b1695c..a0ad297bb3 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/HierarchicalKeyringExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/HierarchicalKeyringExample.java @@ -1,7 +1,6 @@ package software.amazon.cryptography.examples.keyring; import java.util.HashMap; -import software.amazon.cryptography.examples.ExampleUtils; import java.util.Map; import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration; import software.amazon.awssdk.services.dynamodb.DynamoDbClient; @@ -236,7 +235,7 @@ public static void HierarchicalKeyringGetItemPutItem( // based on the code we wrote in the ExampleBranchKeySupplier, // `tenant1BranchKeyId` will be used to encrypt this item. final HashMap item = new HashMap<>(); - item.put("partition_key", AttributeValue.builder().s(ExampleUtils.uniquePk("tenant1Id")).build()); + item.put("partition_key", AttributeValue.builder().s("tenant1Id").build()); item.put("sort_key", AttributeValue.builder().n("0").build()); item.put( "tenant_sensitive_data", @@ -263,7 +262,7 @@ public static void HierarchicalKeyringGetItemPutItem( final HashMap keyToGet = new HashMap<>(); keyToGet.put( "partition_key", - AttributeValue.builder().s(ExampleUtils.uniquePk("tenant1Id")).build() + AttributeValue.builder().s("tenant1Id").build() ); keyToGet.put("sort_key", AttributeValue.builder().n("0").build()); diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/SharedCacheAcrossHierarchicalKeyringsExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/SharedCacheAcrossHierarchicalKeyringsExample.java index 79670d516c..dfed4b84de 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/SharedCacheAcrossHierarchicalKeyringsExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/SharedCacheAcrossHierarchicalKeyringsExample.java @@ -1,7 +1,6 @@ package software.amazon.cryptography.examples.keyring; import java.util.HashMap; -import software.amazon.cryptography.examples.ExampleUtils; import java.util.Map; import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration; import software.amazon.awssdk.services.dynamodb.DynamoDbClient; @@ -360,7 +359,7 @@ public static void PutGetItems( // BranchKeyIdSupplier as per your use-case. See the HierarchicalKeyringsExample.java for more // information. final HashMap item = new HashMap<>(); - item.put("partition_key", AttributeValue.builder().s(ExampleUtils.uniquePk("id")).build()); + item.put("partition_key", AttributeValue.builder().s("id").build()); item.put("sort_key", AttributeValue.builder().n("0").build()); item.put( "sensitive_data", @@ -385,7 +384,7 @@ public static void PutGetItems( // BranchKeyIdSupplier as per your use-case. See the HierarchicalKeyringsExample.java for more // information. final HashMap keyToGet = new HashMap<>(); - keyToGet.put("partition_key", AttributeValue.builder().s(ExampleUtils.uniquePk("id")).build()); + keyToGet.put("partition_key", AttributeValue.builder().s("id").build()); keyToGet.put("sort_key", AttributeValue.builder().n("0").build()); final GetItemRequest getRequest = GetItemRequest diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/keyring/TestKmsEcdhKeyringExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/keyring/TestKmsEcdhKeyringExample.java index e304715de4..ec426a6a1c 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/keyring/TestKmsEcdhKeyringExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/keyring/TestKmsEcdhKeyringExample.java @@ -35,7 +35,7 @@ public void TestKmsEcdhKeyringExampleStatic() { ); } - @Test(dependsOnMethods = {"TestKmsEcdhKeyringExampleStatic"}) + @Test(dependsOnMethods = { "TestKmsEcdhKeyringExampleStatic" }) public void TestKmsEcdhKeyringExampleDiscovery() { // In this example you do not need to provide the recipient ECC Public Key. // On initialization, the keyring will call KMS:getPublicKey on the configured From 614c08238a794b094bad19db4958c5972ff706a6 Mon Sep 17 00:00:00 2001 From: Bikram Sharma Date: Fri, 10 Apr 2026 14:49:10 -0700 Subject: [PATCH 4/5] chore(java): fixes format issue and also addressing ddb parallel test run failure --- .../mapper/integration/ScanITCase.java | 12 ++++++++-- .../clientsupplier/ClientSupplierExample.java | 17 ++++++++++---- .../enhanced/EnhancedPutGetExample.java | 7 +++--- .../enhanced/LombokPutGetExample.java | 4 ++-- .../examples/enhanced/SingleTableExample.java | 4 ++-- .../TableSchemaBuilderPutGetExample.java | 8 ++++--- .../keyring/KmsEcdhKeyringExample.java | 17 ++++++++++---- .../keyring/KmsRsaKeyringExample.java | 12 +++++++--- .../MrkDiscoveryMultiKeyringExample.java | 12 +++++++--- .../examples/keyring/MultiKeyringExample.java | 17 ++++++++++---- .../keyring/MultiMrkKeyringExample.java | 22 ++++++++++++++----- .../keyring/RawAesKeyringExample.java | 12 +++++++--- .../keyring/RawEcdhKeyringExample.java | 22 ++++++++++++++----- .../keyring/RawRsaKeyringExample.java | 12 +++++++--- 14 files changed, 132 insertions(+), 46 deletions(-) diff --git a/DynamoDbEncryption/runtimes/java/src/test/sdkv1/com/amazonaws/services/dynamodbv2/mapper/integration/ScanITCase.java b/DynamoDbEncryption/runtimes/java/src/test/sdkv1/com/amazonaws/services/dynamodbv2/mapper/integration/ScanITCase.java index 93d74c8819..5c2d240061 100644 --- a/DynamoDbEncryption/runtimes/java/src/test/sdkv1/com/amazonaws/services/dynamodbv2/mapper/integration/ScanITCase.java +++ b/DynamoDbEncryption/runtimes/java/src/test/sdkv1/com/amazonaws/services/dynamodbv2/mapper/integration/ScanITCase.java @@ -237,9 +237,17 @@ public void testParallelScanExceptionHandling() { assertNotNull(ase.getErrorCode()); assertNotNull(ase.getErrorType()); assertNotNull(ase.getMessage()); + } catch (java.util.concurrent.RejectedExecutionException e) { + // This is expected when the thread pool shuts down after the first + // segment fails with AmazonServiceException, causing the second + // segment's task to be rejected. } catch (Exception e) { - fail("Should have seen the AmazonServiceException, but got: " - + e.getClass().getName() + ": " + e.getMessage()); + fail( + "Should have seen AmazonServiceException or RejectedExecutionException, but got: " + + e.getClass().getName() + + ": " + + e.getMessage() + ); } } diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/clientsupplier/ClientSupplierExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/clientsupplier/ClientSupplierExample.java index 3eed398273..0e34c8cbfc 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/clientsupplier/ClientSupplierExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/clientsupplier/ClientSupplierExample.java @@ -1,7 +1,6 @@ package software.amazon.cryptography.examples.clientsupplier; import java.util.ArrayList; -import software.amazon.cryptography.examples.ExampleUtils; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -16,6 +15,7 @@ import software.amazon.cryptography.dbencryptionsdk.dynamodb.model.DynamoDbTableEncryptionConfig; import software.amazon.cryptography.dbencryptionsdk.dynamodb.model.DynamoDbTablesEncryptionConfig; import software.amazon.cryptography.dbencryptionsdk.structuredencryption.model.CryptoAction; +import software.amazon.cryptography.examples.ExampleUtils; import software.amazon.cryptography.materialproviders.IKeyring; import software.amazon.cryptography.materialproviders.MaterialProviders; import software.amazon.cryptography.materialproviders.model.CreateAwsKmsMrkDiscoveryMultiKeyringInput; @@ -167,7 +167,10 @@ public static void ClientSupplierPutItemGetItem( final HashMap item = new HashMap<>(); item.put( "partition_key", - AttributeValue.builder().s(ExampleUtils.uniquePk("clientSupplierItem")).build() + AttributeValue + .builder() + .s(ExampleUtils.uniquePk("clientSupplierItem")) + .build() ); item.put("sort_key", AttributeValue.builder().n("0").build()); item.put( @@ -192,7 +195,10 @@ public static void ClientSupplierPutItemGetItem( final HashMap keyToGet = new HashMap<>(); keyToGet.put( "partition_key", - AttributeValue.builder().s(ExampleUtils.uniquePk("clientSupplierItem")).build() + AttributeValue + .builder() + .s(ExampleUtils.uniquePk("clientSupplierItem")) + .build() ); keyToGet.put("sort_key", AttributeValue.builder().n("0").build()); @@ -290,7 +296,10 @@ public static void ClientSupplierPutItemGetItem( new HashMap<>(); onlyReplicaKeyKeyToGet.put( "partition_key", - AttributeValue.builder().s(ExampleUtils.uniquePk("awsKmsMrkMultiKeyringItem")).build() + AttributeValue + .builder() + .s(ExampleUtils.uniquePk("awsKmsMrkMultiKeyringItem")) + .build() ); onlyReplicaKeyKeyToGet.put( "sort_key", diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/enhanced/EnhancedPutGetExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/enhanced/EnhancedPutGetExample.java index e6c9169fa6..b3655011b1 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/enhanced/EnhancedPutGetExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/enhanced/EnhancedPutGetExample.java @@ -1,8 +1,6 @@ package software.amazon.cryptography.examples.enhanced; import java.util.ArrayList; -import software.amazon.cryptography.examples.ExampleUtils; -import software.amazon.cryptography.examples.ExampleUtils; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -19,6 +17,8 @@ import software.amazon.cryptography.dbencryptionsdk.dynamodb.enhancedclient.CreateDynamoDbEncryptionInterceptorInput; import software.amazon.cryptography.dbencryptionsdk.dynamodb.enhancedclient.DynamoDbEnhancedClientEncryption; import software.amazon.cryptography.dbencryptionsdk.dynamodb.enhancedclient.DynamoDbEnhancedTableEncryptionConfig; +import software.amazon.cryptography.examples.ExampleUtils; +import software.amazon.cryptography.examples.ExampleUtils; import software.amazon.cryptography.materialproviders.IKeyring; import software.amazon.cryptography.materialproviders.MaterialProviders; import software.amazon.cryptography.materialproviders.model.CreateAwsKmsMrkMultiKeyringInput; @@ -183,7 +183,8 @@ public static void PutItemGetItem(String kmsKeyId, String ddbTableName) { // retrieve the same record via a Query PageIterable items = table.query( - QueryConditional.keyEqualTo(k -> k.partitionValue(ExampleUtils.uniquePk("EnhancedPutGetExample")) + QueryConditional.keyEqualTo(k -> + k.partitionValue(ExampleUtils.uniquePk("EnhancedPutGetExample")) ) ); List itemList = new ArrayList(); diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/enhanced/LombokPutGetExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/enhanced/LombokPutGetExample.java index c638aea50c..8125eca64b 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/enhanced/LombokPutGetExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/enhanced/LombokPutGetExample.java @@ -1,8 +1,6 @@ package software.amazon.cryptography.examples.enhanced; import static software.amazon.cryptography.examples.ConfigUtils.fromEncryptionInterceptor; -import software.amazon.cryptography.examples.ExampleUtils; -import software.amazon.cryptography.examples.ExampleUtils; import static software.amazon.cryptography.examples.ManipulationUtils.assertManipulationProof; import static software.amazon.cryptography.examples.ManipulationUtils.assertNotManipulationProof; import static software.amazon.cryptography.examples.ManipulationUtils.assertProtectedByEncryptionContext; @@ -29,6 +27,8 @@ import software.amazon.cryptography.dbencryptionsdk.dynamodb.enhancedclient.DynamoDbEnhancedClientEncryption; import software.amazon.cryptography.dbencryptionsdk.dynamodb.enhancedclient.DynamoDbEnhancedTableEncryptionConfig; import software.amazon.cryptography.dbencryptionsdk.dynamodb.itemencryptor.DynamoDbItemEncryptor; +import software.amazon.cryptography.examples.ExampleUtils; +import software.amazon.cryptography.examples.ExampleUtils; import software.amazon.cryptography.materialproviders.IKeyring; import software.amazon.cryptography.materialproviders.MaterialProviders; import software.amazon.cryptography.materialproviders.model.CreateAwsKmsMrkMultiKeyringInput; diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/enhanced/SingleTableExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/enhanced/SingleTableExample.java index 306c166d38..44e7503412 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/enhanced/SingleTableExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/enhanced/SingleTableExample.java @@ -1,7 +1,5 @@ package software.amazon.cryptography.examples.enhanced; -import software.amazon.cryptography.examples.ExampleUtils; -import software.amazon.cryptography.examples.ExampleUtils; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -18,6 +16,8 @@ import software.amazon.cryptography.dbencryptionsdk.dynamodb.enhancedclient.CreateDynamoDbEncryptionInterceptorInput; import software.amazon.cryptography.dbencryptionsdk.dynamodb.enhancedclient.DynamoDbEnhancedClientEncryption; import software.amazon.cryptography.dbencryptionsdk.dynamodb.enhancedclient.DynamoDbEnhancedTableEncryptionConfig; +import software.amazon.cryptography.examples.ExampleUtils; +import software.amazon.cryptography.examples.ExampleUtils; import software.amazon.cryptography.materialproviders.IKeyring; import software.amazon.cryptography.materialproviders.MaterialProviders; import software.amazon.cryptography.materialproviders.model.CreateAwsKmsMrkMultiKeyringInput; diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/enhanced/TableSchemaBuilderPutGetExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/enhanced/TableSchemaBuilderPutGetExample.java index d9ff44ad4c..bae39f12ce 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/enhanced/TableSchemaBuilderPutGetExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/enhanced/TableSchemaBuilderPutGetExample.java @@ -1,8 +1,6 @@ package software.amazon.cryptography.examples.enhanced; import static software.amazon.awssdk.enhanced.dynamodb.mapper.StaticAttributeTags.primaryPartitionKey; -import software.amazon.cryptography.examples.ExampleUtils; -import software.amazon.cryptography.examples.ExampleUtils; import static software.amazon.awssdk.enhanced.dynamodb.mapper.StaticAttributeTags.primarySortKey; import static software.amazon.cryptography.examples.ManipulationUtils.assertManipulationProof; import static software.amazon.cryptography.examples.ManipulationUtils.assertNotManipulationProof; @@ -33,6 +31,8 @@ import software.amazon.cryptography.dbencryptionsdk.dynamodb.enhancedclient.SignOnlyTag; import software.amazon.cryptography.dbencryptionsdk.dynamodb.itemencryptor.DynamoDbItemEncryptor; import software.amazon.cryptography.examples.ConfigUtils; +import software.amazon.cryptography.examples.ExampleUtils; +import software.amazon.cryptography.examples.ExampleUtils; import software.amazon.cryptography.materialproviders.IKeyring; import software.amazon.cryptography.materialproviders.MaterialProviders; import software.amazon.cryptography.materialproviders.model.CreateAwsKmsMrkMultiKeyringInput; @@ -214,7 +214,9 @@ public static void PutItemGetItem(String kmsKeyId, String ddbTableName) { // The item will be encrypted client-side according to your // configuration above before it is sent to DynamoDb. final SimpleClass item = new SimpleClass(); - item.setPartitionKey(ExampleUtils.uniquePk("TableSchemaBuilderPutGetExample")); + item.setPartitionKey( + ExampleUtils.uniquePk("TableSchemaBuilderPutGetExample") + ); item.setSortKey(0); item.setAttribute1("encrypt and sign me!"); item.setAttribute2("sign me!"); diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/KmsEcdhKeyringExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/KmsEcdhKeyringExample.java index b2cb8e9ef8..022cabe7c4 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/KmsEcdhKeyringExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/KmsEcdhKeyringExample.java @@ -1,7 +1,6 @@ package software.amazon.cryptography.examples.keyring; import java.io.ByteArrayInputStream; -import software.amazon.cryptography.examples.ExampleUtils; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; @@ -41,6 +40,7 @@ import software.amazon.cryptography.dbencryptionsdk.dynamodb.model.DynamoDbTableEncryptionConfig; import software.amazon.cryptography.dbencryptionsdk.dynamodb.model.DynamoDbTablesEncryptionConfig; import software.amazon.cryptography.dbencryptionsdk.structuredencryption.model.CryptoAction; +import software.amazon.cryptography.examples.ExampleUtils; import software.amazon.cryptography.materialproviders.IKeyring; import software.amazon.cryptography.materialproviders.MaterialProviders; import software.amazon.cryptography.materialproviders.model.CreateAwsKmsEcdhKeyringInput; @@ -340,7 +340,10 @@ private static void GetItemWithKeyring( final HashMap keyToGet = new HashMap<>(); keyToGet.put( "partition_key", - AttributeValue.builder().s(ExampleUtils.uniquePk("awsKmsEcdhKeyringItem")).build() + AttributeValue + .builder() + .s(ExampleUtils.uniquePk("awsKmsEcdhKeyringItem")) + .build() ); keyToGet.put("sort_key", AttributeValue.builder().n("0").build()); @@ -457,7 +460,10 @@ private static void PutGetItemWithKeyring( final HashMap item = new HashMap<>(); item.put( "partition_key", - AttributeValue.builder().s(ExampleUtils.uniquePk("awsKmsEcdhKeyringItem")).build() + AttributeValue + .builder() + .s(ExampleUtils.uniquePk("awsKmsEcdhKeyringItem")) + .build() ); item.put("sort_key", AttributeValue.builder().n("0").build()); item.put( @@ -482,7 +488,10 @@ private static void PutGetItemWithKeyring( final HashMap keyToGet = new HashMap<>(); keyToGet.put( "partition_key", - AttributeValue.builder().s(ExampleUtils.uniquePk("awsKmsEcdhKeyringItem")).build() + AttributeValue + .builder() + .s(ExampleUtils.uniquePk("awsKmsEcdhKeyringItem")) + .build() ); keyToGet.put("sort_key", AttributeValue.builder().n("0").build()); diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/KmsRsaKeyringExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/KmsRsaKeyringExample.java index b80b994412..fe6f296075 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/KmsRsaKeyringExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/KmsRsaKeyringExample.java @@ -1,7 +1,6 @@ package software.amazon.cryptography.examples.keyring; import java.io.File; -import software.amazon.cryptography.examples.ExampleUtils; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; @@ -30,6 +29,7 @@ import software.amazon.cryptography.dbencryptionsdk.dynamodb.model.DynamoDbTableEncryptionConfig; import software.amazon.cryptography.dbencryptionsdk.dynamodb.model.DynamoDbTablesEncryptionConfig; import software.amazon.cryptography.dbencryptionsdk.structuredencryption.model.CryptoAction; +import software.amazon.cryptography.examples.ExampleUtils; import software.amazon.cryptography.materialproviders.IKeyring; import software.amazon.cryptography.materialproviders.MaterialProviders; import software.amazon.cryptography.materialproviders.model.CreateAwsKmsRsaKeyringInput; @@ -202,7 +202,10 @@ public static void KmsRsaKeyringGetItemPutItem( final HashMap item = new HashMap<>(); item.put( "partition_key", - AttributeValue.builder().s(ExampleUtils.uniquePk("awsKmsRsaKeyringItem")).build() + AttributeValue + .builder() + .s(ExampleUtils.uniquePk("awsKmsRsaKeyringItem")) + .build() ); item.put("sort_key", AttributeValue.builder().n("0").build()); item.put( @@ -227,7 +230,10 @@ public static void KmsRsaKeyringGetItemPutItem( final HashMap keyToGet = new HashMap<>(); keyToGet.put( "partition_key", - AttributeValue.builder().s(ExampleUtils.uniquePk("awsKmsRsaKeyringItem")).build() + AttributeValue + .builder() + .s(ExampleUtils.uniquePk("awsKmsRsaKeyringItem")) + .build() ); keyToGet.put("sort_key", AttributeValue.builder().n("0").build()); diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/MrkDiscoveryMultiKeyringExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/MrkDiscoveryMultiKeyringExample.java index d834bfd22e..4e85104c97 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/MrkDiscoveryMultiKeyringExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/MrkDiscoveryMultiKeyringExample.java @@ -1,7 +1,6 @@ package software.amazon.cryptography.examples.keyring; import java.util.ArrayList; -import software.amazon.cryptography.examples.ExampleUtils; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -17,6 +16,7 @@ import software.amazon.cryptography.dbencryptionsdk.dynamodb.model.DynamoDbTableEncryptionConfig; import software.amazon.cryptography.dbencryptionsdk.dynamodb.model.DynamoDbTablesEncryptionConfig; import software.amazon.cryptography.dbencryptionsdk.structuredencryption.model.CryptoAction; +import software.amazon.cryptography.examples.ExampleUtils; import software.amazon.cryptography.materialproviders.IKeyring; import software.amazon.cryptography.materialproviders.MaterialProviders; import software.amazon.cryptography.materialproviders.model.CreateAwsKmsMrkDiscoveryMultiKeyringInput; @@ -158,7 +158,10 @@ public static void MultiMrkDiscoveryKeyringGetItemPutItem( final HashMap item = new HashMap<>(); item.put( "partition_key", - AttributeValue.builder().s(ExampleUtils.uniquePk("awsKmsMrkDiscoveryMultiKeyringItem")).build() + AttributeValue + .builder() + .s(ExampleUtils.uniquePk("awsKmsMrkDiscoveryMultiKeyringItem")) + .build() ); item.put("sort_key", AttributeValue.builder().n("0").build()); item.put( @@ -251,7 +254,10 @@ public static void MultiMrkDiscoveryKeyringGetItemPutItem( final HashMap keyToGet = new HashMap<>(); keyToGet.put( "partition_key", - AttributeValue.builder().s(ExampleUtils.uniquePk("awsKmsMrkDiscoveryMultiKeyringItem")).build() + AttributeValue + .builder() + .s(ExampleUtils.uniquePk("awsKmsMrkDiscoveryMultiKeyringItem")) + .build() ); keyToGet.put("sort_key", AttributeValue.builder().n("0").build()); diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/MultiKeyringExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/MultiKeyringExample.java index b5827315c8..df74814793 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/MultiKeyringExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/MultiKeyringExample.java @@ -1,7 +1,6 @@ package software.amazon.cryptography.examples.keyring; import com.amazonaws.services.dynamodbv2.datamodeling.internal.Utils; -import software.amazon.cryptography.examples.ExampleUtils; import java.nio.ByteBuffer; import java.security.NoSuchAlgorithmException; import java.security.SecureRandom; @@ -22,6 +21,7 @@ import software.amazon.cryptography.dbencryptionsdk.dynamodb.model.DynamoDbTableEncryptionConfig; import software.amazon.cryptography.dbencryptionsdk.dynamodb.model.DynamoDbTablesEncryptionConfig; import software.amazon.cryptography.dbencryptionsdk.structuredencryption.model.CryptoAction; +import software.amazon.cryptography.examples.ExampleUtils; import software.amazon.cryptography.materialproviders.IKeyring; import software.amazon.cryptography.materialproviders.MaterialProviders; import software.amazon.cryptography.materialproviders.model.AesWrappingAlg; @@ -204,7 +204,10 @@ public static void MultiKeyringGetItemPutItem( final HashMap item = new HashMap<>(); item.put( "partition_key", - AttributeValue.builder().s(ExampleUtils.uniquePk("multiKeyringItem")).build() + AttributeValue + .builder() + .s(ExampleUtils.uniquePk("multiKeyringItem")) + .build() ); item.put("sort_key", AttributeValue.builder().n("0").build()); item.put( @@ -231,7 +234,10 @@ public static void MultiKeyringGetItemPutItem( final HashMap keyToGet = new HashMap<>(); keyToGet.put( "partition_key", - AttributeValue.builder().s(ExampleUtils.uniquePk("multiKeyringItem")).build() + AttributeValue + .builder() + .s(ExampleUtils.uniquePk("multiKeyringItem")) + .build() ); keyToGet.put("sort_key", AttributeValue.builder().n("0").build()); @@ -299,7 +305,10 @@ public static void MultiKeyringGetItemPutItem( new HashMap<>(); onlyAesKeyringKeyToGet.put( "partition_key", - AttributeValue.builder().s(ExampleUtils.uniquePk("multiKeyringItem")).build() + AttributeValue + .builder() + .s(ExampleUtils.uniquePk("multiKeyringItem")) + .build() ); onlyAesKeyringKeyToGet.put( "sort_key", diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/MultiMrkKeyringExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/MultiMrkKeyringExample.java index 9f556c0d34..c918c504d7 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/MultiMrkKeyringExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/MultiMrkKeyringExample.java @@ -1,7 +1,6 @@ package software.amazon.cryptography.examples.keyring; import java.util.Collections; -import software.amazon.cryptography.examples.ExampleUtils; import java.util.HashMap; import java.util.Map; import software.amazon.awssdk.arns.Arn; @@ -18,6 +17,7 @@ import software.amazon.cryptography.dbencryptionsdk.dynamodb.model.DynamoDbTableEncryptionConfig; import software.amazon.cryptography.dbencryptionsdk.dynamodb.model.DynamoDbTablesEncryptionConfig; import software.amazon.cryptography.dbencryptionsdk.structuredencryption.model.CryptoAction; +import software.amazon.cryptography.examples.ExampleUtils; import software.amazon.cryptography.materialproviders.IKeyring; import software.amazon.cryptography.materialproviders.MaterialProviders; import software.amazon.cryptography.materialproviders.model.CreateAwsKmsKeyringInput; @@ -188,7 +188,10 @@ public static void MultiMrkKeyringGetItemPutItem( final HashMap item = new HashMap<>(); item.put( "partition_key", - AttributeValue.builder().s(ExampleUtils.uniquePk("awsKmsMrkMultiKeyringItem")).build() + AttributeValue + .builder() + .s(ExampleUtils.uniquePk("awsKmsMrkMultiKeyringItem")) + .build() ); item.put("sort_key", AttributeValue.builder().n("0").build()); item.put( @@ -215,7 +218,10 @@ public static void MultiMrkKeyringGetItemPutItem( final HashMap keyToGet = new HashMap<>(); keyToGet.put( "partition_key", - AttributeValue.builder().s(ExampleUtils.uniquePk("awsKmsMrkMultiKeyringItem")).build() + AttributeValue + .builder() + .s(ExampleUtils.uniquePk("awsKmsMrkMultiKeyringItem")) + .build() ); keyToGet.put("sort_key", AttributeValue.builder().n("0").build()); @@ -297,7 +303,10 @@ public static void MultiMrkKeyringGetItemPutItem( new HashMap<>(); onlyReplicaKeyKeyToGet.put( "partition_key", - AttributeValue.builder().s(ExampleUtils.uniquePk("awsKmsMrkMultiKeyringItem")).build() + AttributeValue + .builder() + .s(ExampleUtils.uniquePk("awsKmsMrkMultiKeyringItem")) + .build() ); onlyReplicaKeyKeyToGet.put( "sort_key", @@ -379,7 +388,10 @@ public static void MultiMrkKeyringGetItemPutItem( final HashMap onlySrkKeyToGet = new HashMap<>(); onlySrkKeyToGet.put( "partition_key", - AttributeValue.builder().s(ExampleUtils.uniquePk("awsKmsMrkMultiKeyringItem")).build() + AttributeValue + .builder() + .s(ExampleUtils.uniquePk("awsKmsMrkMultiKeyringItem")) + .build() ); onlySrkKeyToGet.put("sort_key", AttributeValue.builder().n("0").build()); diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/RawAesKeyringExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/RawAesKeyringExample.java index 446001299a..9a4bb445a8 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/RawAesKeyringExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/RawAesKeyringExample.java @@ -1,7 +1,6 @@ package software.amazon.cryptography.examples.keyring; import java.nio.ByteBuffer; -import software.amazon.cryptography.examples.ExampleUtils; import java.security.NoSuchAlgorithmException; import java.security.SecureRandom; import java.util.HashMap; @@ -19,6 +18,7 @@ import software.amazon.cryptography.dbencryptionsdk.dynamodb.model.DynamoDbTableEncryptionConfig; import software.amazon.cryptography.dbencryptionsdk.dynamodb.model.DynamoDbTablesEncryptionConfig; import software.amazon.cryptography.dbencryptionsdk.structuredencryption.model.CryptoAction; +import software.amazon.cryptography.examples.ExampleUtils; import software.amazon.cryptography.materialproviders.IKeyring; import software.amazon.cryptography.materialproviders.MaterialProviders; import software.amazon.cryptography.materialproviders.model.AesWrappingAlg; @@ -157,7 +157,10 @@ public static void RawAesKeyringGetItemPutItem( final HashMap item = new HashMap<>(); item.put( "partition_key", - AttributeValue.builder().s(ExampleUtils.uniquePk("rawAesKeyringItem")).build() + AttributeValue + .builder() + .s(ExampleUtils.uniquePk("rawAesKeyringItem")) + .build() ); item.put("sort_key", AttributeValue.builder().n("0").build()); item.put( @@ -182,7 +185,10 @@ public static void RawAesKeyringGetItemPutItem( final HashMap keyToGet = new HashMap<>(); keyToGet.put( "partition_key", - AttributeValue.builder().s(ExampleUtils.uniquePk("rawAesKeyringItem")).build() + AttributeValue + .builder() + .s(ExampleUtils.uniquePk("rawAesKeyringItem")) + .build() ); keyToGet.put("sort_key", AttributeValue.builder().n("0").build()); diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/RawEcdhKeyringExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/RawEcdhKeyringExample.java index db919d6538..2fc2ecb84b 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/RawEcdhKeyringExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/RawEcdhKeyringExample.java @@ -1,7 +1,6 @@ package software.amazon.cryptography.examples.keyring; import java.io.ByteArrayInputStream; -import software.amazon.cryptography.examples.ExampleUtils; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; @@ -45,6 +44,7 @@ import software.amazon.cryptography.dbencryptionsdk.dynamodb.model.DynamoDbTableEncryptionConfig; import software.amazon.cryptography.dbencryptionsdk.dynamodb.model.DynamoDbTablesEncryptionConfig; import software.amazon.cryptography.dbencryptionsdk.structuredencryption.model.CryptoAction; +import software.amazon.cryptography.examples.ExampleUtils; import software.amazon.cryptography.materialproviders.IKeyring; import software.amazon.cryptography.materialproviders.MaterialProviders; import software.amazon.cryptography.materialproviders.model.CreateRawEcdhKeyringInput; @@ -439,7 +439,10 @@ public static void PutGetExampleWithKeyring( final HashMap item = new HashMap<>(); item.put( "partition_key", - AttributeValue.builder().s(ExampleUtils.uniquePk("rawEcdhKeyringItem")).build() + AttributeValue + .builder() + .s(ExampleUtils.uniquePk("rawEcdhKeyringItem")) + .build() ); item.put("sort_key", AttributeValue.builder().n("0").build()); item.put( @@ -464,7 +467,10 @@ public static void PutGetExampleWithKeyring( final HashMap keyToGet = new HashMap<>(); keyToGet.put( "partition_key", - AttributeValue.builder().s(ExampleUtils.uniquePk("rawEcdhKeyringItem")).build() + AttributeValue + .builder() + .s(ExampleUtils.uniquePk("rawEcdhKeyringItem")) + .build() ); keyToGet.put("sort_key", AttributeValue.builder().n("0").build()); @@ -576,7 +582,10 @@ public static void PutExampleWithKeyring( final HashMap item = new HashMap<>(); item.put( "partition_key", - AttributeValue.builder().s(ExampleUtils.uniquePk("rawEcdhKeyringItem")).build() + AttributeValue + .builder() + .s(ExampleUtils.uniquePk("rawEcdhKeyringItem")) + .build() ); item.put("sort_key", AttributeValue.builder().n("0").build()); item.put( @@ -686,7 +695,10 @@ public static void GetExampleWithKeyring( final HashMap keyToGet = new HashMap<>(); keyToGet.put( "partition_key", - AttributeValue.builder().s(ExampleUtils.uniquePk("rawEcdhKeyringItem")).build() + AttributeValue + .builder() + .s(ExampleUtils.uniquePk("rawEcdhKeyringItem")) + .build() ); keyToGet.put("sort_key", AttributeValue.builder().n("0").build()); diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/RawRsaKeyringExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/RawRsaKeyringExample.java index e4a24a12c1..a577918e1c 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/RawRsaKeyringExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/keyring/RawRsaKeyringExample.java @@ -1,7 +1,6 @@ package software.amazon.cryptography.examples.keyring; import java.io.File; -import software.amazon.cryptography.examples.ExampleUtils; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; @@ -30,6 +29,7 @@ import software.amazon.cryptography.dbencryptionsdk.dynamodb.model.DynamoDbTableEncryptionConfig; import software.amazon.cryptography.dbencryptionsdk.dynamodb.model.DynamoDbTablesEncryptionConfig; import software.amazon.cryptography.dbencryptionsdk.structuredencryption.model.CryptoAction; +import software.amazon.cryptography.examples.ExampleUtils; import software.amazon.cryptography.materialproviders.IKeyring; import software.amazon.cryptography.materialproviders.MaterialProviders; import software.amazon.cryptography.materialproviders.model.CreateRawRsaKeyringInput; @@ -211,7 +211,10 @@ public static void RawRsaKeyringGetItemPutItem(String ddbTableName) { final HashMap item = new HashMap<>(); item.put( "partition_key", - AttributeValue.builder().s(ExampleUtils.uniquePk("rawRsaKeyringItem")).build() + AttributeValue + .builder() + .s(ExampleUtils.uniquePk("rawRsaKeyringItem")) + .build() ); item.put("sort_key", AttributeValue.builder().n("0").build()); item.put( @@ -236,7 +239,10 @@ public static void RawRsaKeyringGetItemPutItem(String ddbTableName) { final HashMap keyToGet = new HashMap<>(); keyToGet.put( "partition_key", - AttributeValue.builder().s(ExampleUtils.uniquePk("rawRsaKeyringItem")).build() + AttributeValue + .builder() + .s(ExampleUtils.uniquePk("rawRsaKeyringItem")) + .build() ); keyToGet.put("sort_key", AttributeValue.builder().n("0").build()); From 38c14d6e26881c6e3f620f8c2a8c02d6e57dca90 Mon Sep 17 00:00:00 2001 From: Bikram Sharma Date: Mon, 13 Apr 2026 11:43:03 -0700 Subject: [PATCH 5/5] chore(java): Adds afterTest cleanup method to clean DDB items created in test run --- .../amazon/cryptography/examples/ExampleUtils.java | 8 ++++---- .../amazon/cryptography/examples/TestUtils.java | 14 ++++++++++++++ .../clientsupplier/TestClientSupplierExample.java | 7 +++++++ .../enhanced/TestEnhancedPutGetExample.java | 8 ++++++++ .../examples/enhanced/TestSingleTableExample.java | 8 ++++++++ .../keyring/TestKmsEcdhKeyringExample.java | 6 ++++++ .../examples/keyring/TestKmsRsaKeyringExample.java | 6 ++++++ .../TestMrkDiscoveryMultiKeyringExample.java | 6 ++++++ .../keyring/TestMrkMultiKeyringExample.java | 6 ++++++ .../examples/keyring/TestMultiKeyringExample.java | 6 ++++++ .../examples/keyring/TestRawAesKeyringExample.java | 6 ++++++ .../keyring/TestRawEcdhKeyringExample.java | 6 ++++++ .../examples/keyring/TestRawRsaKeyringExample.java | 6 ++++++ 13 files changed, 89 insertions(+), 4 deletions(-) diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/ExampleUtils.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/ExampleUtils.java index f4b8fb1a86..4377ec1459 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/ExampleUtils.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/ExampleUtils.java @@ -5,20 +5,20 @@ import java.util.concurrent.ThreadLocalRandom; /** - * Shared utilities for examples. The TEST_PREFIX provides a unique suffix + * Shared utilities for examples. The TEST_SUFFIX provides a unique suffix * per JVM process so that parallel CI matrix jobs (different Java versions / OS) * do not overwrite each other's items in the shared DynamoDB test table. * * Each example uses a hardcoded partition key like "rawEcdhKeyringItem". * In CI, multiple JVMs run in parallel against the same table. Without * isolation, one JVM can overwrite another's item, causing decrypt failures. - * By appending a random prefix, each JVM writes to its own partition key + * By appending a random suffix, each JVM writes to its own partition key * (e.g., "rawEcdhKeyringItem-482913") while keeping cross-example reads * working within the same JVM. */ public class ExampleUtils { - private static final String TEST_PREFIX = String.valueOf( + private static final String TEST_SUFFIX = String.valueOf( ThreadLocalRandom.current().nextInt(100000, 999999) ); @@ -27,6 +27,6 @@ public class ExampleUtils { * Example: "rawEcdhKeyringItem" becomes "rawEcdhKeyringItem-482913" */ public static String uniquePk(String base) { - return base + "-" + TEST_PREFIX; + return base + "-" + TEST_SUFFIX; } } diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/TestUtils.java b/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/TestUtils.java index c43b994542..583859e9bc 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/TestUtils.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/TestUtils.java @@ -42,6 +42,20 @@ public class TestUtils { public static final String TEST_DDB_TABLE_NAME = "DynamoDbEncryptionInterceptorTestTable"; + /** + * Deletes a test item using the standard table schema (partition_key S, sort_key N). + * Use this for items written by examples that use ExampleUtils.uniquePk(). + */ + public static void cleanUpExampleItem(final String partitionKeyBase) { + cleanUpDDBItem( + TEST_DDB_TABLE_NAME, + "partition_key", + "sort_key", + ExampleUtils.uniquePk(partitionKeyBase), + "0" + ); + } + /** * Deletes an item from a DynamoDB table. * diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/clientsupplier/TestClientSupplierExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/clientsupplier/TestClientSupplierExample.java index 176bda438d..6040d44572 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/clientsupplier/TestClientSupplierExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/clientsupplier/TestClientSupplierExample.java @@ -2,6 +2,7 @@ import java.util.Collections; import java.util.List; +import org.testng.annotations.AfterTest; import org.testng.annotations.Test; import software.amazon.awssdk.regions.Region; import software.amazon.cryptography.examples.TestUtils; @@ -35,4 +36,10 @@ public void TestClientSupplierExample() { regions ); } + + @AfterTest + public void cleanup() { + TestUtils.cleanUpExampleItem("clientSupplierItem"); + TestUtils.cleanUpExampleItem("awsKmsMrkMultiKeyringItem"); + } } diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/enhanced/TestEnhancedPutGetExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/enhanced/TestEnhancedPutGetExample.java index 0bf211d424..a6eb3cb522 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/enhanced/TestEnhancedPutGetExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/enhanced/TestEnhancedPutGetExample.java @@ -1,5 +1,6 @@ package software.amazon.cryptography.examples.enhanced; +import org.testng.annotations.AfterTest; import org.testng.annotations.Test; import software.amazon.cryptography.examples.TestUtils; @@ -28,4 +29,11 @@ public void TestTableSchemaBuilderPutGet() { TestUtils.TEST_DDB_TABLE_NAME ); } + + @AfterTest + public void cleanup() { + TestUtils.cleanUpExampleItem("EnhancedPutGetExample"); + TestUtils.cleanUpExampleItem("LombokPutGetExample"); + TestUtils.cleanUpExampleItem("TableSchemaBuilderPutGetExample"); + } } diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/enhanced/TestSingleTableExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/enhanced/TestSingleTableExample.java index 7b64a049f9..10e1c94974 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/enhanced/TestSingleTableExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/enhanced/TestSingleTableExample.java @@ -1,5 +1,6 @@ package software.amazon.cryptography.examples.enhanced; +import org.testng.annotations.AfterTest; import org.testng.annotations.Test; import software.amazon.cryptography.examples.TestUtils; @@ -12,4 +13,11 @@ public void TestEnhancedSingleTable() { TestUtils.TEST_DDB_TABLE_NAME ); } + + @AfterTest + public void cleanup() { + TestUtils.cleanUpExampleItem("EnhancedPutGetExample1"); + TestUtils.cleanUpExampleItem("EnhancedPutGetExample2"); + TestUtils.cleanUpExampleItem("EnhancedPutGetExample3"); + } } diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/keyring/TestKmsEcdhKeyringExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/keyring/TestKmsEcdhKeyringExample.java index ec426a6a1c..259dc1adf7 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/keyring/TestKmsEcdhKeyringExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/keyring/TestKmsEcdhKeyringExample.java @@ -5,6 +5,7 @@ import static software.amazon.cryptography.examples.keyring.KmsEcdhKeyringExample.shouldGetNewPublicKeys; import static software.amazon.cryptography.examples.keyring.KmsEcdhKeyringExample.writePublicKeyPemForEccKey; +import org.testng.annotations.AfterTest; import org.testng.annotations.Test; import software.amazon.cryptography.examples.TestUtils; @@ -46,4 +47,9 @@ public void TestKmsEcdhKeyringExampleDiscovery() { TestUtils.TEST_KMS_ECDH_KEY_ID_P256_RECIPIENT ); } + + @AfterTest + public void cleanup() { + TestUtils.cleanUpExampleItem("awsKmsEcdhKeyringItem"); + } } diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/keyring/TestKmsRsaKeyringExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/keyring/TestKmsRsaKeyringExample.java index 9f0156d9d3..f5de14e739 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/keyring/TestKmsRsaKeyringExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/keyring/TestKmsRsaKeyringExample.java @@ -3,6 +3,7 @@ import static software.amazon.cryptography.examples.keyring.KmsRsaKeyringExample.shouldGetNewPublicKey; import static software.amazon.cryptography.examples.keyring.KmsRsaKeyringExample.writePublicKeyPemForRsaKey; +import org.testng.annotations.AfterTest; import org.testng.annotations.Test; import software.amazon.cryptography.examples.TestUtils; @@ -22,4 +23,9 @@ public void TestKmsRsaKeyringExample() { TestUtils.TEST_KMS_RSA_KEY_ID ); } + + @AfterTest + public void cleanup() { + TestUtils.cleanUpExampleItem("awsKmsRsaKeyringItem"); + } } diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/keyring/TestMrkDiscoveryMultiKeyringExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/keyring/TestMrkDiscoveryMultiKeyringExample.java index ceace75fa3..e1f3a539f9 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/keyring/TestMrkDiscoveryMultiKeyringExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/keyring/TestMrkDiscoveryMultiKeyringExample.java @@ -2,6 +2,7 @@ import java.util.Collections; import java.util.List; +import org.testng.annotations.AfterTest; import org.testng.annotations.Test; import software.amazon.cryptography.examples.TestUtils; @@ -21,4 +22,9 @@ public void TestMrkDiscoveryMultiKeyringExample() { regions ); } + + @AfterTest + public void cleanup() { + TestUtils.cleanUpExampleItem("awsKmsMrkDiscoveryMultiKeyringItem"); + } } diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/keyring/TestMrkMultiKeyringExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/keyring/TestMrkMultiKeyringExample.java index c4f313ac4b..d8f9b45961 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/keyring/TestMrkMultiKeyringExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/keyring/TestMrkMultiKeyringExample.java @@ -1,5 +1,6 @@ package software.amazon.cryptography.examples.keyring; +import org.testng.annotations.AfterTest; import org.testng.annotations.Test; import software.amazon.cryptography.examples.TestUtils; @@ -14,4 +15,9 @@ public void TestMrkMultiKeyringExample() { TestUtils.TEST_MRK_REPLICA_KEY_ID_US_EAST_1 ); } + + @AfterTest + public void cleanup() { + TestUtils.cleanUpExampleItem("awsKmsMrkMultiKeyringItem"); + } } diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/keyring/TestMultiKeyringExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/keyring/TestMultiKeyringExample.java index 0c54c4a89d..d96f61e847 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/keyring/TestMultiKeyringExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/keyring/TestMultiKeyringExample.java @@ -1,6 +1,7 @@ package software.amazon.cryptography.examples.keyring; import java.nio.ByteBuffer; +import org.testng.annotations.AfterTest; import org.testng.annotations.Test; import software.amazon.cryptography.examples.TestUtils; @@ -17,4 +18,9 @@ public void TestMultiKeyringExample() { aesKeyBytes ); } + + @AfterTest + public void cleanup() { + TestUtils.cleanUpExampleItem("multiKeyringItem"); + } } diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/keyring/TestRawAesKeyringExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/keyring/TestRawAesKeyringExample.java index 4f31ef9a7c..0440129eb9 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/keyring/TestRawAesKeyringExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/keyring/TestRawAesKeyringExample.java @@ -1,6 +1,7 @@ package software.amazon.cryptography.examples.keyring; import java.nio.ByteBuffer; +import org.testng.annotations.AfterTest; import org.testng.annotations.Test; import software.amazon.cryptography.examples.TestUtils; @@ -16,4 +17,9 @@ public void TestRawAesKeyringExample() { aesKeyBytes ); } + + @AfterTest + public void cleanup() { + TestUtils.cleanUpExampleItem("rawAesKeyringItem"); + } } diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/keyring/TestRawEcdhKeyringExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/keyring/TestRawEcdhKeyringExample.java index a6ee1aff65..3c09c7b577 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/keyring/TestRawEcdhKeyringExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/keyring/TestRawEcdhKeyringExample.java @@ -2,6 +2,7 @@ import java.nio.ByteBuffer; import java.security.spec.ECGenParameterSpec; +import org.testng.annotations.AfterTest; import org.testng.annotations.Test; import software.amazon.cryptography.examples.TestUtils; import software.amazon.cryptography.primitives.model.ECDHCurveSpec; @@ -80,4 +81,9 @@ public void TestDiscoveryRawEcdhKeyringExample() { ECDHCurveSpec.ECC_NIST_P256 ); } + + @AfterTest + public void cleanup() { + TestUtils.cleanUpExampleItem("rawEcdhKeyringItem"); + } } diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/keyring/TestRawRsaKeyringExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/keyring/TestRawRsaKeyringExample.java index 5baea772c2..919857b9b0 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/keyring/TestRawRsaKeyringExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/keyring/TestRawRsaKeyringExample.java @@ -1,5 +1,6 @@ package software.amazon.cryptography.examples.keyring; +import org.testng.annotations.AfterTest; import org.testng.annotations.Test; import software.amazon.cryptography.examples.TestUtils; @@ -19,4 +20,9 @@ public void TestRawRsaKeyringExample() { TestUtils.TEST_DDB_TABLE_NAME ); } + + @AfterTest + public void cleanup() { + TestUtils.cleanUpExampleItem("rawRsaKeyringItem"); + } }