From aca5a42d9477418742a5b10a2762d59a448740ba Mon Sep 17 00:00:00 2001 From: rishav-karanjit Date: Fri, 10 Jan 2025 10:26:16 -0800 Subject: [PATCH 1/8] Add multithreading test --- AwsEncryptionSDK/runtimes/go/examples/go.mod | 2 +- AwsEncryptionSDK/runtimes/go/examples/main.go | 9 +- .../go/examples/multithreading/kmskeyring.go | 200 ++++++++++++++++++ .../go/examples/utils/exampleUtils.go | 15 ++ 4 files changed, 224 insertions(+), 2 deletions(-) create mode 100644 AwsEncryptionSDK/runtimes/go/examples/multithreading/kmskeyring.go diff --git a/AwsEncryptionSDK/runtimes/go/examples/go.mod b/AwsEncryptionSDK/runtimes/go/examples/go.mod index 10303df09..81221e5f2 100644 --- a/AwsEncryptionSDK/runtimes/go/examples/go.mod +++ b/AwsEncryptionSDK/runtimes/go/examples/go.mod @@ -20,6 +20,7 @@ require ( github.com/aws/aws-sdk-go-v2/service/dynamodb v1.35.1 github.com/aws/aws-sdk-go-v2/service/kms v1.36.0 github.com/aws/aws-sdk-go-v2/service/sts v1.31.1 + github.com/google/uuid v1.6.0 ) require ( @@ -38,6 +39,5 @@ require ( github.com/aws/smithy-go v1.21.0 // indirect github.com/dafny-lang/DafnyRuntimeGo/v4 v4.9.1 // indirect github.com/dafny-lang/DafnyStandardLibGo v0.0.0 // indirect - github.com/google/uuid v1.6.0 // indirect github.com/jmespath/go-jmespath v0.4.0 // indirect ) diff --git a/AwsEncryptionSDK/runtimes/go/examples/main.go b/AwsEncryptionSDK/runtimes/go/examples/main.go index 434034783..fab8a3a15 100644 --- a/AwsEncryptionSDK/runtimes/go/examples/main.go +++ b/AwsEncryptionSDK/runtimes/go/examples/main.go @@ -23,16 +23,18 @@ import ( "github.com/aws/aws-encryption-sdk/examples/keyring/rawaeskeyring" "github.com/aws/aws-encryption-sdk/examples/keyring/rawrsakeyring" "github.com/aws/aws-encryption-sdk/examples/misc" + "github.com/aws/aws-encryption-sdk/examples/multithreading" "github.com/aws/aws-encryption-sdk/examples/utils" ) func main() { const stringToEncrypt = "Text To encrypt" + const numOfString = 10000 clientsupplier.ClientSupplierExample( stringToEncrypt, utils.DefaultRegionMrkKeyArn(), utils.DefaultKMSKeyAccountID(), - []string{"eu-west-1"}) + []string{utils.AlternateRegionMrkKeyRegion()}) misc.CommitmentPolicyExample( stringToEncrypt, utils.DefaultKMSKeyId(), @@ -158,4 +160,9 @@ func main() { utils.DefaultKMSKeyId(), utils.DefaultKmsKeyRegion(), ) + // Example with multithreading + multithreading.MultiThreadTest( + utils.GenerateUUIDTestData(numOfString), + utils.DefaultKMSKeyId(), + utils.DefaultKmsKeyRegion()) } diff --git a/AwsEncryptionSDK/runtimes/go/examples/multithreading/kmskeyring.go b/AwsEncryptionSDK/runtimes/go/examples/multithreading/kmskeyring.go new file mode 100644 index 000000000..5bef76a03 --- /dev/null +++ b/AwsEncryptionSDK/runtimes/go/examples/multithreading/kmskeyring.go @@ -0,0 +1,200 @@ +// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 + +/* +This example sets up the AWS KMS Keyring in an multithreaded environment. +The AWS KMS keyring uses symmetric encryption KMS keys to generate, encrypt and +decrypt data keys. This example creates a KMS Keyring and then encrypts a custom input exampleText +with an encryption context. This example also includes some sanity checks for demonstration: +1. Ciphertext and plaintext data are not the same +2. Decrypted plaintext value matches exampleText +These sanity checks are for demonstration in the example only. You do not need these in your code. +AWS KMS keyrings can be used independently or in a multi-keyring with other keyrings +of the same or a different type. +For more information on how to use KMS keyrings, see +https://docs.aws.amazon.com/encryption-sdk/latest/developer-guide/use-kms-keyring.html +For more information on KMS Key identifiers, see +https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#key-id +*/ + +package multithreading + +import ( + "context" + "fmt" + "runtime" + "sync" + + mpl "github.com/aws/aws-cryptographic-material-providers-library/mpl/awscryptographymaterialproviderssmithygenerated" + mpltypes "github.com/aws/aws-cryptographic-material-providers-library/mpl/awscryptographymaterialproviderssmithygeneratedtypes" + client "github.com/aws/aws-encryption-sdk/awscryptographyencryptionsdksmithygenerated" + esdktypes "github.com/aws/aws-encryption-sdk/awscryptographyencryptionsdksmithygeneratedtypes" + "github.com/aws/aws-sdk-go-v2/config" + "github.com/aws/aws-sdk-go-v2/service/kms" +) + +// Structure to hold operation results +type OperationResult struct { + EncryptOutput *esdktypes.EncryptOutput + DecryptOutput *esdktypes.DecryptOutput + Error error +} + +// Function to handle encryption +func encryptData( + ctx context.Context, + encryptionClient *client.Client, + plaintext string, + encryptionContext map[string]string, + keyring mpltypes.IKeyring) OperationResult { + res, err := encryptionClient.Encrypt(ctx, esdktypes.EncryptInput{ + Plaintext: []byte(plaintext), + EncryptionContext: encryptionContext, + Keyring: keyring, + }) + return OperationResult{ + EncryptOutput: res, + Error: err, + } +} + +// Function to handle decryption +func decryptData( + ctx context.Context, + encryptionClient *client.Client, + ciphertext []byte, + encryptionContext map[string]string, + keyring mpltypes.IKeyring) OperationResult { + res, err := encryptionClient.Decrypt(ctx, esdktypes.DecryptInput{ + EncryptionContext: encryptionContext, + Keyring: keyring, + Ciphertext: ciphertext, + }) + return OperationResult{ + DecryptOutput: res, + Error: err, + } +} + +func processEncryptionWorker( + wg *sync.WaitGroup, + jobs <-chan string, + encryptionClient *client.Client, + awsKmsKeyring mpltypes.IKeyring, + encryptionContext map[string]string, +) { + defer wg.Done() + for plaintext := range jobs { + ctx := context.Background() + // Perform encryption + encryptResult := encryptData(ctx, encryptionClient, plaintext, encryptionContext, awsKmsKeyring) + if encryptResult.Error != nil { + panic(encryptResult.Error) + } + // Verify ciphertext is different from plaintext + if string(encryptResult.EncryptOutput.Ciphertext) == plaintext { + panic("Ciphertext and Plaintext before encryption are the same") + } + // Perform decryption + decryptResult := decryptData( + ctx, + encryptionClient, + encryptResult.EncryptOutput.Ciphertext, + encryptionContext, + awsKmsKeyring, + ) + if decryptResult.Error != nil { + panic(decryptResult.Error) + } + // If you do not specify the encryption context on Decrypt, it's recommended to check if the resulting encryption context matches. + // The encryption context was specified on decrypt; we are validating the encryption context for demonstration only. + // Before your application uses plaintext data, verify that the encryption context that + // you used to encrypt the message is included in the encryption context that was used to + // decrypt the message. The AWS Encryption SDK can add pairs, so don't require an exact match. + if err := validateEncryptionContext(encryptionContext, decryptResult.DecryptOutput.EncryptionContext); err != nil { + panic(err) + } + if string(decryptResult.DecryptOutput.Plaintext) != plaintext { + panic("Plaintext after decryption and Plaintext before encryption are NOT the same") + } + } +} + +func MultiThreadTest(texts []string, defaultKmsKeyID, defaultKmsKeyRegion string) { + // Create the AWS KMS client + cfg, err := config.LoadDefaultConfig(context.TODO()) + if err != nil { + panic(err) + } + kmsClient := kms.NewFromConfig(cfg, func(o *kms.Options) { + o.Region = defaultKmsKeyRegion + }) + // Initialize the mpl client + matProv, err := mpl.NewClient(mpltypes.MaterialProvidersConfig{}) + if err != nil { + panic(err) + } + // Create the keyring + awsKmsKeyringInput := mpltypes.CreateAwsKmsKeyringInput{ + KmsClient: kmsClient, + KmsKeyId: defaultKmsKeyID, + } + awsKmsKeyring, err := matProv.CreateAwsKmsKeyring(context.Background(), awsKmsKeyringInput) + if err != nil { + panic(err) + } + // Instantiate the encryption SDK client. + // This builds the default client with the RequireEncryptRequireDecrypt commitment policy, + // which enforces that this client only encrypts using committing algorithm suites and enforces + // that this client will only decrypt encrypted messages that were created with a committing + // algorithm suite. + encryptionClient, err := client.NewClient(esdktypes.AwsEncryptionSdkConfig{}) + if err != nil { + panic(err) + } + // Create your encryption context (Optional). + // Remember that your encryption context is NOT SECRET. + // https://docs.aws.amazon.com/encryption-sdk/latest/developer-guide/concepts.html#encryption-context + encryptionContext := map[string]string{ + "encryption": "context", + "is not": "secret", + "but adds": "useful metadata", + "that can help you": "be confident that", + "the data you are handling": "is what you think it is", + } + // Create buffered channels to handle multiple operations + numWorkers := runtime.NumCPU() - 1 // Leave one CPU free for system tasks + + // Create a wait group to track all goroutines + var wg sync.WaitGroup + + // Create a channel to send a plaintext + jobs := make(chan string, len(texts)) + + // Start worker pool + for range numWorkers { + wg.Add(1) + go processEncryptionWorker(&wg, jobs, encryptionClient, awsKmsKeyring, encryptionContext) + } + + // Send jobs to workers + for _, text := range texts { + jobs <- text + } + close(jobs) + // Wait for all workers to complete + wg.Wait() + fmt.Println("AWS KMS Keyring example in multithreaded environment completed successfully.") +} + +// This function only does subset matching because AWS Encryption SDK can add pairs, so don't require an exact match. +func validateEncryptionContext(expected, actual map[string]string) error { + for expectedKey, expectedValue := range expected { + actualValue, exists := actual[expectedKey] + if !exists || actualValue != expectedValue { + return fmt.Errorf("encryption context mismatch: expected key '%s' with value '%s'", + expectedKey, expectedValue) + } + } + return nil +} diff --git a/AwsEncryptionSDK/runtimes/go/examples/utils/exampleUtils.go b/AwsEncryptionSDK/runtimes/go/examples/utils/exampleUtils.go index ddc75bf1b..a9093af43 100644 --- a/AwsEncryptionSDK/runtimes/go/examples/utils/exampleUtils.go +++ b/AwsEncryptionSDK/runtimes/go/examples/utils/exampleUtils.go @@ -1,3 +1,6 @@ +// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 + package utils import ( @@ -13,6 +16,7 @@ import ( "github.com/aws/aws-cryptographic-material-providers-library/primitives/awscryptographyprimitivessmithygeneratedtypes" "github.com/aws/aws-sdk-go-v2/service/kms" + "github.com/google/uuid" ) const ( @@ -319,3 +323,14 @@ func GenerateKmsEccPublicKey(eccKeyArn string, kmsClient *kms.Client) ([]byte, e } return response.PublicKey, nil } + +// generateUUIDTestData creates an array of random UUID strings +func GenerateUUIDTestData(count int) []string { + testData := make([]string, count) + for i := 0; i < count; i++ { + // Generate a random UUID + uuid := uuid.New() + testData[i] = uuid.String() + } + return testData +} From 789a42f1df1de9321ae698f9172ed416b3d6d06d Mon Sep 17 00:00:00 2001 From: rishav-karanjit Date: Fri, 10 Jan 2025 10:32:04 -0800 Subject: [PATCH 2/8] auto commit --- AwsEncryptionSDK/runtimes/go/examples/main.go | 2 +- .../examples/multithreading/{kmskeyring.go => awskmskeyring.go} | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename AwsEncryptionSDK/runtimes/go/examples/multithreading/{kmskeyring.go => awskmskeyring.go} (98%) diff --git a/AwsEncryptionSDK/runtimes/go/examples/main.go b/AwsEncryptionSDK/runtimes/go/examples/main.go index fab8a3a15..d7812a2b8 100644 --- a/AwsEncryptionSDK/runtimes/go/examples/main.go +++ b/AwsEncryptionSDK/runtimes/go/examples/main.go @@ -161,7 +161,7 @@ func main() { utils.DefaultKmsKeyRegion(), ) // Example with multithreading - multithreading.MultiThreadTest( + multithreading.AWSKMSMultiThreadTest( utils.GenerateUUIDTestData(numOfString), utils.DefaultKMSKeyId(), utils.DefaultKmsKeyRegion()) diff --git a/AwsEncryptionSDK/runtimes/go/examples/multithreading/kmskeyring.go b/AwsEncryptionSDK/runtimes/go/examples/multithreading/awskmskeyring.go similarity index 98% rename from AwsEncryptionSDK/runtimes/go/examples/multithreading/kmskeyring.go rename to AwsEncryptionSDK/runtimes/go/examples/multithreading/awskmskeyring.go index 5bef76a03..7c722db03 100644 --- a/AwsEncryptionSDK/runtimes/go/examples/multithreading/kmskeyring.go +++ b/AwsEncryptionSDK/runtimes/go/examples/multithreading/awskmskeyring.go @@ -120,7 +120,7 @@ func processEncryptionWorker( } } -func MultiThreadTest(texts []string, defaultKmsKeyID, defaultKmsKeyRegion string) { +func AWSKMSMultiThreadTest(texts []string, defaultKmsKeyID, defaultKmsKeyRegion string) { // Create the AWS KMS client cfg, err := config.LoadDefaultConfig(context.TODO()) if err != nil { From b19728549adb0c95a13bd515e38b87c82a925ebe Mon Sep 17 00:00:00 2001 From: Rishav karanjit Date: Fri, 10 Jan 2025 11:15:53 -0800 Subject: [PATCH 3/8] Update AwsEncryptionSDK/runtimes/go/examples/utils/exampleUtils.go --- AwsEncryptionSDK/runtimes/go/examples/utils/exampleUtils.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AwsEncryptionSDK/runtimes/go/examples/utils/exampleUtils.go b/AwsEncryptionSDK/runtimes/go/examples/utils/exampleUtils.go index a9093af43..d037b53e4 100644 --- a/AwsEncryptionSDK/runtimes/go/examples/utils/exampleUtils.go +++ b/AwsEncryptionSDK/runtimes/go/examples/utils/exampleUtils.go @@ -324,7 +324,7 @@ func GenerateKmsEccPublicKey(eccKeyArn string, kmsClient *kms.Client) ([]byte, e return response.PublicKey, nil } -// generateUUIDTestData creates an array of random UUID strings +// GenerateUUIDTestData creates an array of random UUID strings func GenerateUUIDTestData(count int) []string { testData := make([]string, count) for i := 0; i < count; i++ { From 4d612fa38fe3732f171d852073822ffc9735f044 Mon Sep 17 00:00:00 2001 From: rishav-karanjit Date: Tue, 14 Jan 2025 14:09:53 -0800 Subject: [PATCH 4/8] auto commit --- .../examples/multithreading/awskmskeyring.go | 56 ++++++++----------- 1 file changed, 24 insertions(+), 32 deletions(-) diff --git a/AwsEncryptionSDK/runtimes/go/examples/multithreading/awskmskeyring.go b/AwsEncryptionSDK/runtimes/go/examples/multithreading/awskmskeyring.go index 7c722db03..5878af5a1 100644 --- a/AwsEncryptionSDK/runtimes/go/examples/multithreading/awskmskeyring.go +++ b/AwsEncryptionSDK/runtimes/go/examples/multithreading/awskmskeyring.go @@ -22,7 +22,6 @@ package multithreading import ( "context" "fmt" - "runtime" "sync" mpl "github.com/aws/aws-cryptographic-material-providers-library/mpl/awscryptographymaterialproviderssmithygenerated" @@ -33,29 +32,19 @@ import ( "github.com/aws/aws-sdk-go-v2/service/kms" ) -// Structure to hold operation results -type OperationResult struct { - EncryptOutput *esdktypes.EncryptOutput - DecryptOutput *esdktypes.DecryptOutput - Error error -} - // Function to handle encryption func encryptData( ctx context.Context, encryptionClient *client.Client, plaintext string, encryptionContext map[string]string, - keyring mpltypes.IKeyring) OperationResult { + keyring mpltypes.IKeyring) (*esdktypes.EncryptOutput, error) { res, err := encryptionClient.Encrypt(ctx, esdktypes.EncryptInput{ Plaintext: []byte(plaintext), EncryptionContext: encryptionContext, Keyring: keyring, }) - return OperationResult{ - EncryptOutput: res, - Error: err, - } + return res, err } // Function to handle decryption @@ -64,19 +53,17 @@ func decryptData( encryptionClient *client.Client, ciphertext []byte, encryptionContext map[string]string, - keyring mpltypes.IKeyring) OperationResult { + keyring mpltypes.IKeyring) (*esdktypes.DecryptOutput, error) { res, err := encryptionClient.Decrypt(ctx, esdktypes.DecryptInput{ EncryptionContext: encryptionContext, Keyring: keyring, Ciphertext: ciphertext, }) - return OperationResult{ - DecryptOutput: res, - Error: err, - } + return res, err } func processEncryptionWorker( + ctx context.Context, wg *sync.WaitGroup, jobs <-chan string, encryptionClient *client.Client, @@ -85,36 +72,40 @@ func processEncryptionWorker( ) { defer wg.Done() for plaintext := range jobs { - ctx := context.Background() // Perform encryption - encryptResult := encryptData(ctx, encryptionClient, plaintext, encryptionContext, awsKmsKeyring) - if encryptResult.Error != nil { - panic(encryptResult.Error) + encryptResult, err := encryptData( + ctx, + encryptionClient, + plaintext, + encryptionContext, + awsKmsKeyring) + if err != nil { + panic(err) } // Verify ciphertext is different from plaintext - if string(encryptResult.EncryptOutput.Ciphertext) == plaintext { + if string(encryptResult.Ciphertext) == plaintext { panic("Ciphertext and Plaintext before encryption are the same") } // Perform decryption - decryptResult := decryptData( + decryptResult, err := decryptData( ctx, encryptionClient, - encryptResult.EncryptOutput.Ciphertext, + encryptResult.Ciphertext, encryptionContext, awsKmsKeyring, ) - if decryptResult.Error != nil { - panic(decryptResult.Error) + if err != nil { + panic(err) } // If you do not specify the encryption context on Decrypt, it's recommended to check if the resulting encryption context matches. // The encryption context was specified on decrypt; we are validating the encryption context for demonstration only. // Before your application uses plaintext data, verify that the encryption context that // you used to encrypt the message is included in the encryption context that was used to // decrypt the message. The AWS Encryption SDK can add pairs, so don't require an exact match. - if err := validateEncryptionContext(encryptionContext, decryptResult.DecryptOutput.EncryptionContext); err != nil { + if err := validateEncryptionContext(encryptionContext, decryptResult.EncryptionContext); err != nil { panic(err) } - if string(decryptResult.DecryptOutput.Plaintext) != plaintext { + if string(decryptResult.Plaintext) != plaintext { panic("Plaintext after decryption and Plaintext before encryption are NOT the same") } } @@ -135,11 +126,12 @@ func AWSKMSMultiThreadTest(texts []string, defaultKmsKeyID, defaultKmsKeyRegion panic(err) } // Create the keyring + ctx := context.Background() awsKmsKeyringInput := mpltypes.CreateAwsKmsKeyringInput{ KmsClient: kmsClient, KmsKeyId: defaultKmsKeyID, } - awsKmsKeyring, err := matProv.CreateAwsKmsKeyring(context.Background(), awsKmsKeyringInput) + awsKmsKeyring, err := matProv.CreateAwsKmsKeyring(ctx, awsKmsKeyringInput) if err != nil { panic(err) } @@ -163,7 +155,7 @@ func AWSKMSMultiThreadTest(texts []string, defaultKmsKeyID, defaultKmsKeyRegion "the data you are handling": "is what you think it is", } // Create buffered channels to handle multiple operations - numWorkers := runtime.NumCPU() - 1 // Leave one CPU free for system tasks + numWorkers := 10 // Create a wait group to track all goroutines var wg sync.WaitGroup @@ -174,7 +166,7 @@ func AWSKMSMultiThreadTest(texts []string, defaultKmsKeyID, defaultKmsKeyRegion // Start worker pool for range numWorkers { wg.Add(1) - go processEncryptionWorker(&wg, jobs, encryptionClient, awsKmsKeyring, encryptionContext) + go processEncryptionWorker(ctx, &wg, jobs, encryptionClient, awsKmsKeyring, encryptionContext) } // Send jobs to workers From c885592d361d637c7c9ea257935169de099d79b1 Mon Sep 17 00:00:00 2001 From: rishav-karanjit Date: Tue, 14 Jan 2025 14:27:08 -0800 Subject: [PATCH 5/8] Ohh no its 5 --- AwsEncryptionSDK/runtimes/go/examples/main.go | 11 ++++++----- .../go/examples/multithreading/awskmskeyring.go | 3 +++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/AwsEncryptionSDK/runtimes/go/examples/main.go b/AwsEncryptionSDK/runtimes/go/examples/main.go index d7812a2b8..b7918860d 100644 --- a/AwsEncryptionSDK/runtimes/go/examples/main.go +++ b/AwsEncryptionSDK/runtimes/go/examples/main.go @@ -29,7 +29,11 @@ import ( func main() { const stringToEncrypt = "Text To encrypt" - const numOfString = 10000 + //const numOfString = 10000 + multithreading.AWSKMSMultiThreadTest( + []string{"1", "2", "3", "4", "5", "6", "7", "8", "9"}, + utils.DefaultKMSKeyId(), + utils.DefaultKmsKeyRegion()) clientsupplier.ClientSupplierExample( stringToEncrypt, utils.DefaultRegionMrkKeyArn(), @@ -161,8 +165,5 @@ func main() { utils.DefaultKmsKeyRegion(), ) // Example with multithreading - multithreading.AWSKMSMultiThreadTest( - utils.GenerateUUIDTestData(numOfString), - utils.DefaultKMSKeyId(), - utils.DefaultKmsKeyRegion()) + } diff --git a/AwsEncryptionSDK/runtimes/go/examples/multithreading/awskmskeyring.go b/AwsEncryptionSDK/runtimes/go/examples/multithreading/awskmskeyring.go index 5878af5a1..474f787f5 100644 --- a/AwsEncryptionSDK/runtimes/go/examples/multithreading/awskmskeyring.go +++ b/AwsEncryptionSDK/runtimes/go/examples/multithreading/awskmskeyring.go @@ -72,6 +72,9 @@ func processEncryptionWorker( ) { defer wg.Done() for plaintext := range jobs { + if plaintext == "5" { + panic("Ohh no its 5") + } // Perform encryption encryptResult, err := encryptData( ctx, From 2a0e4625eb3b831e0149f3e7a41f6398938e1841 Mon Sep 17 00:00:00 2001 From: rishav-karanjit Date: Tue, 14 Jan 2025 14:27:34 -0800 Subject: [PATCH 6/8] Revert "Ohh no its 5" This reverts commit c885592d361d637c7c9ea257935169de099d79b1. --- AwsEncryptionSDK/runtimes/go/examples/main.go | 11 +++++------ .../go/examples/multithreading/awskmskeyring.go | 3 --- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/AwsEncryptionSDK/runtimes/go/examples/main.go b/AwsEncryptionSDK/runtimes/go/examples/main.go index b7918860d..d7812a2b8 100644 --- a/AwsEncryptionSDK/runtimes/go/examples/main.go +++ b/AwsEncryptionSDK/runtimes/go/examples/main.go @@ -29,11 +29,7 @@ import ( func main() { const stringToEncrypt = "Text To encrypt" - //const numOfString = 10000 - multithreading.AWSKMSMultiThreadTest( - []string{"1", "2", "3", "4", "5", "6", "7", "8", "9"}, - utils.DefaultKMSKeyId(), - utils.DefaultKmsKeyRegion()) + const numOfString = 10000 clientsupplier.ClientSupplierExample( stringToEncrypt, utils.DefaultRegionMrkKeyArn(), @@ -165,5 +161,8 @@ func main() { utils.DefaultKmsKeyRegion(), ) // Example with multithreading - + multithreading.AWSKMSMultiThreadTest( + utils.GenerateUUIDTestData(numOfString), + utils.DefaultKMSKeyId(), + utils.DefaultKmsKeyRegion()) } diff --git a/AwsEncryptionSDK/runtimes/go/examples/multithreading/awskmskeyring.go b/AwsEncryptionSDK/runtimes/go/examples/multithreading/awskmskeyring.go index 474f787f5..5878af5a1 100644 --- a/AwsEncryptionSDK/runtimes/go/examples/multithreading/awskmskeyring.go +++ b/AwsEncryptionSDK/runtimes/go/examples/multithreading/awskmskeyring.go @@ -72,9 +72,6 @@ func processEncryptionWorker( ) { defer wg.Done() for plaintext := range jobs { - if plaintext == "5" { - panic("Ohh no its 5") - } // Perform encryption encryptResult, err := encryptData( ctx, From 88f5a3c97083f1b60baed9d035e96cff56390a2f Mon Sep 17 00:00:00 2001 From: rishav-karanjit Date: Tue, 14 Jan 2025 14:34:10 -0800 Subject: [PATCH 7/8] Add a comment --- .../runtimes/go/examples/multithreading/awskmskeyring.go | 1 + 1 file changed, 1 insertion(+) diff --git a/AwsEncryptionSDK/runtimes/go/examples/multithreading/awskmskeyring.go b/AwsEncryptionSDK/runtimes/go/examples/multithreading/awskmskeyring.go index 5878af5a1..b190f3992 100644 --- a/AwsEncryptionSDK/runtimes/go/examples/multithreading/awskmskeyring.go +++ b/AwsEncryptionSDK/runtimes/go/examples/multithreading/awskmskeyring.go @@ -155,6 +155,7 @@ func AWSKMSMultiThreadTest(texts []string, defaultKmsKeyID, defaultKmsKeyRegion "the data you are handling": "is what you think it is", } // Create buffered channels to handle multiple operations + // As an example, we will have 10 workers, adjust this number as needed." numWorkers := 10 // Create a wait group to track all goroutines From fb0a657b5b8bc2857941b0af366b6d1eea203e76 Mon Sep 17 00:00:00 2001 From: rishav-karanjit Date: Tue, 14 Jan 2025 14:37:11 -0800 Subject: [PATCH 8/8] nit --- .../runtimes/go/examples/multithreading/awskmskeyring.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AwsEncryptionSDK/runtimes/go/examples/multithreading/awskmskeyring.go b/AwsEncryptionSDK/runtimes/go/examples/multithreading/awskmskeyring.go index b190f3992..1b3358b6b 100644 --- a/AwsEncryptionSDK/runtimes/go/examples/multithreading/awskmskeyring.go +++ b/AwsEncryptionSDK/runtimes/go/examples/multithreading/awskmskeyring.go @@ -155,7 +155,7 @@ func AWSKMSMultiThreadTest(texts []string, defaultKmsKeyID, defaultKmsKeyRegion "the data you are handling": "is what you think it is", } // Create buffered channels to handle multiple operations - // As an example, we will have 10 workers, adjust this number as needed." + // As an example, we will have 10 workers, adjust this number as needed. numWorkers := 10 // Create a wait group to track all goroutines