Skip to content

Commit

Permalink
Merge branch 'mainline' into rishav-exampleReadme
Browse files Browse the repository at this point in the history
  • Loading branch information
rishav-karanjit authored Feb 3, 2025
2 parents f407dce + 7e492d7 commit a3d343b
Show file tree
Hide file tree
Showing 1,518 changed files with 145,716 additions and 127,457 deletions.
2 changes: 1 addition & 1 deletion AwsEncryptionSDK/runtimes/rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "aws-esdk"
version = "0.2.0"
version = "1.0.0"
edition = "2021"
rust-version = "1.81.0"
keywords = ["cryptography", "security", "dynamodb", "encryption", "client-side"]
Expand Down
6 changes: 1 addition & 5 deletions SUPPORT_POLICY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,7 @@ This table describes the current support status of each major version of the AWS
- Current status
- Next status
- Next status date
* - 0.x
- Beta Version
- End of Support
- 2024-12-14
* - 4.x
* - 1.x
- Generally Available
-
-
Expand Down
22 changes: 11 additions & 11 deletions releases/rust/esdk/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "aws-esdk"
version = "0.2.0"
version = "1.0.0"
edition = "2021"
rust-version = "1.81.0"
keywords = ["cryptography", "security", "dynamodb", "encryption", "client-side"]
Expand All @@ -16,21 +16,21 @@ readme = "README.md"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
aws-config = "1.5.11"
aws-lc-rs = "1.12.0"
aws-lc-sys = "0.24.0"
aws-sdk-dynamodb = "1.55.0"
aws-sdk-kms = "1.51.0"
aws-config = "1.5.15"
aws-lc-rs = "1.12.2"
aws-lc-sys = "0.25.0"
aws-sdk-dynamodb = "1.62.0"
aws-sdk-kms = "1.57.0"
aws-smithy-runtime-api = {version = "1.7.3", features = ["client"] }
aws-smithy-types = "1.2.10"
aws-smithy-types = "1.2.12"
chrono = "0.4.39"
cpu-time = "1.0.0"
dafny-runtime = "0.1.1"
dafny-runtime = { version = "0.2.0", features = ["sync"] }
dashmap = "6.1.0"
pem = "3.0.4"
rand = "0.8.5"
tokio = {version = "1.42.0", features = ["full"] }
uuid = { version = "1.11.0", features = ["v4"] }
rand = "0.9.0"
tokio = {version = "1.43.0", features = ["full"] }
uuid = { version = "1.12.1", features = ["v4"] }

[[example]]
name = "main"
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@

use super::regional_role_client_supplier::RegionalRoleClientSupplier;
use aws_esdk::client as esdk_client;
use aws_esdk::types::aws_encryption_sdk_config::AwsEncryptionSdkConfig;
use aws_esdk::material_providers::types::error::Error::AwsCryptographicMaterialProvidersException;
use aws_esdk::material_providers::client as mpl_client;
use aws_esdk::material_providers::types::error::Error::AwsCryptographicMaterialProvidersException;
use aws_esdk::material_providers::types::material_providers_config::MaterialProvidersConfig;
use aws_esdk::material_providers::types::DiscoveryFilter;
use aws_esdk::types::aws_encryption_sdk_config::AwsEncryptionSdkConfig;
use std::collections::HashMap;

pub async fn encrypt_and_decrypt_with_keyring(
Expand All @@ -46,8 +46,14 @@ pub async fn encrypt_and_decrypt_with_keyring(
("encryption".to_string(), "context".to_string()),
("is not".to_string(), "secret".to_string()),
("but adds".to_string(), "useful metadata".to_string()),
("that can help you".to_string(), "be confident that".to_string()),
("the data you are handling".to_string(), "is what you think it is".to_string()),
(
"that can help you".to_string(),
"be confident that".to_string(),
),
(
"the data you are handling".to_string(),
"is what you think it is".to_string(),
),
]);

// 3. Create a single MRK multi-keyring.
Expand All @@ -74,21 +80,25 @@ pub async fn encrypt_and_decrypt_with_keyring(
// 4. Encrypt the data with the encryption_context using the encrypt_keyring.
let plaintext = example_data.as_bytes();

let encryption_response = esdk_client.encrypt()
let encryption_response = esdk_client
.encrypt()
.plaintext(plaintext)
.keyring(mrk_keyring_with_client_supplier)
.encryption_context(encryption_context.clone())
.send()
.await?;

let ciphertext = encryption_response
.ciphertext
.expect("Unable to unwrap ciphertext from encryption response");
.ciphertext
.expect("Unable to unwrap ciphertext from encryption response");

// 5. Demonstrate that the ciphertext and plaintext are different.
// (This is an example for demonstration; you do not need to do this in your own code.)
assert_ne!(ciphertext, aws_smithy_types::Blob::new(plaintext),
"Ciphertext and plaintext data are the same. Invalid encryption");
assert_ne!(
ciphertext,
aws_smithy_types::Blob::new(plaintext),
"Ciphertext and plaintext data are the same. Invalid encryption"
);

// 6. Create a MRK discovery multi-keyring with a custom client supplier.
// A discovery MRK multi-keyring will be composed of
Expand Down Expand Up @@ -123,7 +133,8 @@ pub async fn encrypt_and_decrypt_with_keyring(
// All of this is done serially, until a success occurs or all keyrings have failed
// all (filtered) EDKs. KMS MRK Discovery Keyrings will attempt to decrypt
// Multi Region Keys (MRKs) and regular KMS Keys.
let decryption_response = esdk_client.decrypt()
let decryption_response = esdk_client
.decrypt()
.ciphertext(ciphertext)
.keyring(mrk_discovery_client_supplier_keyring)
// Provide the encryption context that was supplied to the encrypt method
Expand All @@ -132,13 +143,16 @@ pub async fn encrypt_and_decrypt_with_keyring(
.await?;

let decrypted_plaintext = decryption_response
.plaintext
.expect("Unable to unwrap plaintext from decryption response");
.plaintext
.expect("Unable to unwrap plaintext from decryption response");

// 8. Demonstrate that the decrypted plaintext is identical to the original plaintext.
// (This is an example for demonstration; you do not need to do this in your own code.)
assert_eq!(decrypted_plaintext, aws_smithy_types::Blob::new(plaintext),
"Decrypted plaintext should be identical to the original plaintext. Invalid decryption");
assert_eq!(
decrypted_plaintext,
aws_smithy_types::Blob::new(plaintext),
"Decrypted plaintext should be identical to the original plaintext. Invalid decryption"
);

// 9. Test the Missing Region Exception
// (This is an example for demonstration; you do not need to do this in your own code.)
Expand All @@ -153,8 +167,10 @@ pub async fn encrypt_and_decrypt_with_keyring(
// Swallow the exception
// (This is an example for demonstration; you do not need to do this in your own code.)
match mrk_discovery_client_supplier_keyring_missing_region {
Ok(_) => panic!("Decryption using discovery keyring with missing region MUST \
raise AwsCryptographicMaterialProvidersException"),
Ok(_) => panic!(
"Decryption using discovery keyring with missing region MUST \
raise AwsCryptographicMaterialProvidersException"
),
Err(AwsCryptographicMaterialProvidersException { message: _e }) => (),
_ => panic!("Unexpected error type"),
}
Expand All @@ -180,7 +196,8 @@ pub async fn test_encrypt_and_decrypt_with_keyring() -> Result<(), crate::BoxErr
utils::TEST_MRK_KEY_ID_US_EAST_1,
utils::TEST_DEFAULT_KMS_KEY_ACCOUNT_ID,
aws_regions,
).await?;
)
.await?;

Ok(())
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

use super::regional_role_client_supplier_config;
use aws_config::Region;
use aws_esdk::material_providers::types::ClientSupplier;
use aws_esdk::com_amazonaws_kms::client::Client as kms_client;
use aws_esdk::material_providers::operation::get_client::GetClientInput;
use aws_esdk::material_providers::types::error::Error;
use aws_esdk::com_amazonaws_kms::client::Client as kms_client;
use super::regional_role_client_supplier_config;
use aws_esdk::material_providers::types::ClientSupplier;

/*
Example class demonstrating an implementation of a custom client supplier.
Expand All @@ -24,7 +24,8 @@ impl ClientSupplier for RegionalRoleClientSupplier {

if !region_iam_role_map.contains_key(&region) {
return Err(Error::AwsCryptographicMaterialProvidersException {
message: format!("Region {} is not supported by this client supplier", region).to_string(),
message: format!("Region {} is not supported by this client supplier", region)
.to_string(),
});
}

Expand Down
Loading

0 comments on commit a3d343b

Please sign in to comment.