Skip to content

Commit 537e32b

Browse files
committed
m
1 parent 2f29200 commit 537e32b

40 files changed

+611
-666
lines changed

AwsEncryptionSDK/runtimes/rust/esdk_rust/esdk/Cargo.toml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,17 @@ name = "main"
3535
[[bin]]
3636
name = "test_vector"
3737
path = "src/bin/test_vector/main.rs"
38-
required-features = ["test_vectors"] # Only build binary when cli feature is enabled
38+
required-features = ["test_vectors"] # Only build binary when test_vectors feature is enabled
39+
40+
[package.metadata.docs.rs]
41+
features = ["test_vectors"]
42+
rustdoc-args = [
43+
"--generate-link-to-definition",
44+
"--generate-macro-expansion",
45+
]
3946

4047
[features]
4148
# default = []
4249
default = ["test_vectors"]
4350
test_vectors = ["clap", "serde_json", "anyhow", "base64", "aws-sdk-kms", "aws-config"] # Users can enable with --features test_vectors
51+
fips = ["aws-mpl-primitives/fips"]

AwsEncryptionSDK/runtimes/rust/esdk_rust/esdk/examples/client_supplier/client_supplier_example.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
*/
1717

1818
use super::regional_role_client_supplier::RegionalRoleClientSupplier;
19-
use aws_esdk::Client as EsdkClient;
2019
use aws_esdk::*;
2120
use aws_mpl_rs::client as mpl_client;
2221
use aws_mpl_rs::types::DiscoveryFilter;
@@ -29,14 +28,6 @@ pub async fn encrypt_and_decrypt_with_keyring(
2928
aws_account_id: &str,
3029
aws_regions: Vec<String>,
3130
) -> Result<(), crate::BoxError> {
32-
// 1. Instantiate the encryption SDK client.
33-
// This builds the default client with the RequireEncryptRequireDecrypt commitment policy,
34-
// which enforces that this client only encrypts using committing algorithm suites and enforces
35-
// that this client will only decrypt encrypted messages that were created with a committing
36-
// algorithm suite.
37-
let esdk_config = AwsEncryptionSdkConfig::default();
38-
let esdk_client = EsdkClient::from_conf(esdk_config)?;
39-
4031
// 2. Create encryption context.
4132
// Remember that your encryption context is NOT SECRET.
4233
// For more information, see
@@ -84,7 +75,7 @@ pub async fn encrypt_and_decrypt_with_keyring(
8475
.keyring(mrk_keyring_with_client_supplier)
8576
.encryption_context(&encryption_context)
8677
.build()?;
87-
let encryption_response = esdk_client.encrypt(&encrypt_input).await?;
78+
let encryption_response = encrypt(&encrypt_input).await?;
8879

8980
let ciphertext = encryption_response.ciphertext;
9081

@@ -134,7 +125,7 @@ pub async fn encrypt_and_decrypt_with_keyring(
134125
// Provide the encryption context that was supplied to the encrypt method
135126
.encryption_context(&encryption_context)
136127
.build()?;
137-
let decryption_response = esdk_client.decrypt(&decrypt_input).await?;
128+
let decryption_response = decrypt(&decrypt_input).await?;
138129

139130
let decrypted_plaintext = decryption_response.plaintext;
140131

AwsEncryptionSDK/runtimes/rust/esdk_rust/esdk/examples/cryptographic_materials_manager/required_encryption_context/required_encryption_context_example.rs

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ on encrypt such that they will not be stored on the message, but WILL be include
88
On decrypt, the client MUST supply the key/value pair(s) that were not stored to successfully decrypt the message.
99
*/
1010

11-
use aws_esdk::Client as EsdkClient;
1211
use aws_esdk::*;
1312
use aws_mpl_rs::client as mpl_client;
1413
use aws_mpl_rs::types::material_providers_config::MaterialProvidersConfig;
@@ -18,14 +17,6 @@ pub async fn encrypt_and_decrypt_with_cmm(
1817
example_data: &str,
1918
kms_key_id: &str,
2019
) -> Result<(), crate::BoxError> {
21-
// 1. Instantiate the encryption SDK client.
22-
// This builds the default client with the RequireEncryptRequireDecrypt commitment policy,
23-
// which enforces that this client only encrypts using committing algorithm suites and enforces
24-
// that this client will only decrypt encrypted messages that were created with a committing
25-
// algorithm suite.
26-
let esdk_config = AwsEncryptionSdkConfig::default();
27-
let esdk_client = EsdkClient::from_conf(esdk_config)?;
28-
2920
// 2. Create a KMS client.
3021
let sdk_config = aws_config::load_defaults(aws_config::BehaviorVersion::latest()).await;
3122
let kms_client = aws_sdk_kms::Client::new(&sdk_config);
@@ -93,7 +84,7 @@ pub async fn encrypt_and_decrypt_with_cmm(
9384
.materials_manager(required_ec_cmm.clone())
9485
.encryption_context(&encryption_context)
9586
.build()?;
96-
let encryption_response = esdk_client.encrypt(&encrypt_input).await?;
87+
let encryption_response = encrypt(&encrypt_input).await?;
9788

9889
let ciphertext = encryption_response.ciphertext;
9990

@@ -111,7 +102,7 @@ pub async fn encrypt_and_decrypt_with_cmm(
111102
// Provide the encryption context that was supplied to the encrypt method
112103
.encryption_context(&encryption_context)
113104
.build()?;
114-
let decryption_response = esdk_client.decrypt(&decrypt_input).await?;
105+
let decryption_response = decrypt(&decrypt_input).await?;
115106

116107
let decrypted_plaintext = decryption_response.plaintext;
117108

@@ -126,8 +117,8 @@ pub async fn encrypt_and_decrypt_with_cmm(
126117
// you used on encrypt, but we won't pass the encryption context we DID NOT store on the message.
127118
// This will fail
128119
decrypt_input.materials_manager = Some(required_ec_cmm.clone());
129-
decrypt_input.encryption_context = None;
130-
let decryption_response_without_ec = esdk_client.decrypt(&decrypt_input).await;
120+
decrypt_input.encryption_context = empty_ec();
121+
let decryption_response_without_ec = decrypt(&decrypt_input).await;
131122

132123
if decryption_response_without_ec.is_ok() {
133124
panic!(
@@ -144,9 +135,9 @@ pub async fn encrypt_and_decrypt_with_cmm(
144135
]);
145136

146137
decrypt_input.materials_manager = Some(required_ec_cmm);
147-
decrypt_input.encryption_context = Some(&reproduced_encryption_context);
138+
decrypt_input.encryption_context = &reproduced_encryption_context;
148139

149-
let decryption_response_with_reproduced_ec = esdk_client.decrypt(&decrypt_input).await?;
140+
let decryption_response_with_reproduced_ec = decrypt(&decrypt_input).await?;
150141

151142
let decrypted_plaintext_with_reproduced_ec = decryption_response_with_reproduced_ec.plaintext;
152143

@@ -162,8 +153,8 @@ pub async fn encrypt_and_decrypt_with_cmm(
162153

163154
// This will pass
164155
decrypt_input.materials_manager = Some(underlying_cmm);
165-
decrypt_input.encryption_context = Some(&encryption_context);
166-
let decryption_response_with_ec_underlying_cmm = esdk_client.decrypt(&decrypt_input).await?;
156+
decrypt_input.encryption_context = &encryption_context;
157+
let decryption_response_with_ec_underlying_cmm = decrypt(&decrypt_input).await?;
167158

168159
let decrypted_plaintext_with_ec_underlying_cmm =
169160
decryption_response_with_ec_underlying_cmm.plaintext;
@@ -176,8 +167,8 @@ pub async fn encrypt_and_decrypt_with_cmm(
176167
);
177168

178169
// This will fail
179-
decrypt_input.encryption_context = None;
180-
let decryption_response_without_ec_underlying_cmm = esdk_client.decrypt(&decrypt_input).await;
170+
decrypt_input.encryption_context = empty_ec();
171+
let decryption_response_without_ec_underlying_cmm = decrypt(&decrypt_input).await;
181172

182173
if decryption_response_without_ec_underlying_cmm.is_ok() {
183174
panic!(

AwsEncryptionSDK/runtimes/rust/esdk_rust/esdk/examples/cryptographic_materials_manager/restrict_algorithm_suite/signing_only_example.rs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
*/
88

99
use super::signing_suite_only_cmm::SigningSuiteOnlyCMM;
10-
use aws_esdk::Client as EsdkClient;
1110
use aws_esdk::*;
1211
use aws_mpl_rs::client as mpl_client;
1312
use aws_mpl_rs::types::EsdkAlgorithmSuiteId;
@@ -18,14 +17,6 @@ pub async fn encrypt_and_decrypt_with_cmm(
1817
example_data: &str,
1918
kms_key_id: &str,
2019
) -> Result<(), crate::BoxError> {
21-
// 1. Instantiate the encryption SDK client.
22-
// This builds the default client with the RequireEncryptRequireDecrypt commitment policy,
23-
// which enforces that this client only encrypts using committing algorithm suites and enforces
24-
// that this client will only decrypt encrypted messages that were created with a committing
25-
// algorithm suite.
26-
let esdk_config = AwsEncryptionSdkConfig::default();
27-
let esdk_client = EsdkClient::from_conf(esdk_config)?;
28-
2920
// 2. Create a KMS client.
3021
let sdk_config = aws_config::load_defaults(aws_config::BehaviorVersion::latest()).await;
3122
let kms_client = aws_sdk_kms::Client::new(&sdk_config);
@@ -75,7 +66,7 @@ pub async fn encrypt_and_decrypt_with_cmm(
7566
.encryption_context(&encryption_context)
7667
.algorithm_suite_id(EsdkAlgorithmSuiteId::AlgAes256GcmHkdfSha512CommitKeyEcdsaP384)
7768
.build()?;
78-
let encryption_response = esdk_client.encrypt(&encrypt_input).await?;
69+
let encryption_response = encrypt(&encrypt_input).await?;
7970

8071
let ciphertext = encryption_response.ciphertext;
8172

@@ -93,7 +84,7 @@ pub async fn encrypt_and_decrypt_with_cmm(
9384
// Provide the encryption context that was supplied to the encrypt method
9485
.encryption_context(&encryption_context)
9586
.build()?;
96-
let decryption_response = esdk_client.decrypt(&decrypt_input).await?;
87+
let decryption_response = decrypt(&decrypt_input).await?;
9788

9889
let decrypted_plaintext = decryption_response.plaintext;
9990

@@ -107,7 +98,7 @@ pub async fn encrypt_and_decrypt_with_cmm(
10798
// 9. Demonstrate that a Non Signing Algorithm Suite will be rejected
10899
// by the CMM.
109100
encrypt_input.algorithm_suite_id = Some(EsdkAlgorithmSuiteId::AlgAes256GcmHkdfSha512CommitKey);
110-
let encryption_response_non_signing = esdk_client.encrypt(&encrypt_input).await;
101+
let encryption_response_non_signing = encrypt(&encrypt_input).await;
111102

112103
if encryption_response_non_signing.is_ok() {
113104
panic!(

AwsEncryptionSDK/runtimes/rust/esdk_rust/esdk/examples/keyring/aws_kms_discovery_keyring_example.rs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ For more information on KMS Key identifiers, see
3636
https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#key-id
3737
*/
3838

39-
use aws_esdk::Client as EsdkClient;
4039
use aws_esdk::*;
4140
use aws_mpl_rs::types::DiscoveryFilter;
4241

@@ -46,13 +45,6 @@ pub async fn encrypt_and_decrypt_with_keyring(
4645
aws_account_id: &str,
4746
// ) -> Result<(), crate::BoxError> {
4847
) -> Result<(), Error> {
49-
// 1. Instantiate the encryption SDK client.
50-
// This builds the default client with the RequireEncryptRequireDecrypt commitment policy,
51-
// which enforces that this client only encrypts using committing algorithm suites and enforces
52-
// that this client will only decrypt encrypted messages that were created with a committing
53-
// algorithm suite.
54-
let esdk_client = EsdkClient::default();
55-
5648
// 2. Create a KMS client.
5749
let sdk_config = aws_config::load_defaults(aws_config::BehaviorVersion::latest()).await;
5850
let kms_client = aws_sdk_kms::Client::new(&sdk_config);
@@ -78,7 +70,7 @@ pub async fn encrypt_and_decrypt_with_keyring(
7870
// 4. Create the keyring that determines how your data keys are protected.
7971
// Although this example highlights Discovery keyrings, Discovery keyrings cannot
8072
// be used to encrypt, so for encryption we create a KMS keyring without discovery mode.
81-
let mpl = EsdkClient::mpl()?;
73+
let mpl = mpl()?;
8274

8375
let encrypt_kms_keyring = mpl
8476
.create_aws_kms_keyring()
@@ -95,7 +87,7 @@ pub async fn encrypt_and_decrypt_with_keyring(
9587
.keyring(encrypt_kms_keyring)
9688
.encryption_context(&encryption_context)
9789
.build()?;
98-
let encryption_response = esdk_client.encrypt(&encrypt_input).await?;
90+
let encryption_response = encrypt(&encrypt_input).await?;
9991

10092
let ciphertext = encryption_response.ciphertext;
10193

@@ -139,7 +131,7 @@ pub async fn encrypt_and_decrypt_with_keyring(
139131
.keyring(discovery_keyring)
140132
.encryption_context(&encryption_context)
141133
.build()?;
142-
let decryption_response = esdk_client.decrypt(&decrypt_input).await?;
134+
let decryption_response = decrypt(&decrypt_input).await?;
143135

144136
let decrypted_plaintext = decryption_response.plaintext;
145137

@@ -170,7 +162,7 @@ pub async fn encrypt_and_decrypt_with_keyring(
170162
// Account ID's for the KMS keyring used for encryption.
171163
// This should throw an AwsCryptographicMaterialProvidersError exception
172164
decrypt_input.keyring = Some(discovery_keyring_bob);
173-
let decryption_response_bob = esdk_client.decrypt(&decrypt_input).await;
165+
let decryption_response_bob = decrypt(&decrypt_input).await;
174166

175167
if decryption_response_bob.is_ok() {
176168
panic!(

AwsEncryptionSDK/runtimes/rust/esdk_rust/esdk/examples/keyring/aws_kms_discovery_multi_keyring_example.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ For more information on KMS Key identifiers, see
3333
https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#key-id
3434
*/
3535

36-
use aws_esdk::Client as EsdkClient;
3736
use aws_esdk::*;
3837
use aws_mpl_rs::client as mpl_client;
3938
use aws_mpl_rs::types::DiscoveryFilter;
@@ -46,13 +45,6 @@ pub async fn encrypt_and_decrypt_with_keyring(
4645
aws_account_id: &str,
4746
aws_regions: Vec<String>,
4847
) -> Result<(), crate::BoxError> {
49-
// 1. Instantiate the encryption SDK client.
50-
// This builds the default client with the RequireEncryptRequireDecrypt commitment policy,
51-
// which enforces that this client only encrypts using committing algorithm suites and enforces
52-
// that this client will only decrypt encrypted messages that were created with a committing
53-
// algorithm suite.
54-
let esdk_client = EsdkClient::default();
55-
5648
// 2. Create a KMS client.
5749
let sdk_config = aws_config::load_defaults(aws_config::BehaviorVersion::latest()).await;
5850
let kms_client = aws_sdk_kms::Client::new(&sdk_config);
@@ -96,7 +88,7 @@ pub async fn encrypt_and_decrypt_with_keyring(
9688
.keyring(encrypt_kms_keyring)
9789
.encryption_context(&encryption_context)
9890
.build()?;
99-
let encryption_response = esdk_client.encrypt(&encrypt_input).await?;
91+
let encryption_response = encrypt(&encrypt_input).await?;
10092

10193
let ciphertext = encryption_response.ciphertext;
10294

@@ -143,7 +135,7 @@ pub async fn encrypt_and_decrypt_with_keyring(
143135
// Provide the encryption context that was supplied to the encrypt method
144136
.encryption_context(&encryption_context)
145137
.build()?;
146-
let decryption_response = esdk_client.decrypt(&decrypt_input).await?;
138+
let decryption_response = decrypt(&decrypt_input).await?;
147139

148140
let decrypted_plaintext = decryption_response.plaintext;
149141

AwsEncryptionSDK/runtimes/rust/esdk_rust/esdk/examples/keyring/aws_kms_hierarchical/aws_kms_hierarchical_keyring_example.rs

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939

4040
use super::create_branch_key_id::create_branch_key_id;
4141
use super::example_branch_key_id_supplier::ExampleBranchKeyIdSupplier;
42-
use aws_esdk::Client as EsdkClient;
4342
use aws_esdk::*;
4443
use aws_mpl_rs::aws_cryptography_keyStore::client as keystore_client;
4544
use aws_mpl_rs::aws_cryptography_keyStore::types::KmsConfiguration;
@@ -53,14 +52,6 @@ pub async fn encrypt_and_decrypt_with_keyring(
5352
logical_key_store_name: &str,
5453
key_store_kms_key_id: &str,
5554
) -> Result<(), crate::BoxError> {
56-
// 1. Instantiate the encryption SDK client.
57-
// This builds the default client with the RequireEncryptRequireDecrypt commitment policy,
58-
// which enforces that this client only encrypts using committing algorithm suites and enforces
59-
// that this client will only decrypt encrypted messages that were created with a committing
60-
// algorithm suite.
61-
let esdk_config = AwsEncryptionSdkConfig::default();
62-
let esdk_client = EsdkClient::from_conf(esdk_config)?;
63-
6455
// 2. Create a KMS client and DynamoDB client.
6556
let sdk_config = aws_config::load_defaults(aws_config::BehaviorVersion::latest()).await;
6657
let kms_client = aws_sdk_kms::Client::new(&sdk_config);
@@ -158,12 +149,12 @@ pub async fn encrypt_and_decrypt_with_keyring(
158149
.keyring(hierarchical_keyring.clone())
159150
.encryption_context(&encryption_context_a)
160151
.build()?;
161-
let encryption_response_a = esdk_client.encrypt(&encrypt_input).await?;
152+
let encryption_response_a = encrypt(&encrypt_input).await?;
162153

163154
let ciphertext_a = encryption_response_a.ciphertext;
164155

165-
encrypt_input.encryption_context = Some(&encryption_context_b);
166-
let encryption_response_b = esdk_client.encrypt(&encrypt_input).await?;
156+
encrypt_input.encryption_context = &encryption_context_b;
157+
let encryption_response_b = encrypt(&encrypt_input).await?;
167158

168159
let ciphertext_b = encryption_response_b.ciphertext;
169160

@@ -209,7 +200,7 @@ pub async fn encrypt_and_decrypt_with_keyring(
209200
// Provide the encryption context that was supplied to the encrypt method
210201
.encryption_context(&encryption_context_a)
211202
.build()?;
212-
let decryption_response_mismatch_1 = esdk_client.decrypt(&decrypt_input).await;
203+
let decryption_response_mismatch_1 = decrypt(&decrypt_input).await;
213204

214205
if decryption_response_mismatch_1.is_ok() {
215206
panic!(
@@ -222,8 +213,8 @@ pub async fn encrypt_and_decrypt_with_keyring(
222213
// which we swallow ONLY for demonstration purposes.
223214
decrypt_input.ciphertext = &ciphertext_b;
224215
decrypt_input.keyring = Some(hierarchical_keyring_a.clone());
225-
decrypt_input.encryption_context = Some(&encryption_context_b);
226-
let decryption_response_mismatch_2 = esdk_client.decrypt(&decrypt_input).await;
216+
decrypt_input.encryption_context = &encryption_context_b;
217+
let decryption_response_mismatch_2 = decrypt(&decrypt_input).await;
227218

228219
if decryption_response_mismatch_2.is_ok() {
229220
panic!(
@@ -234,8 +225,8 @@ pub async fn encrypt_and_decrypt_with_keyring(
234225
// 12. Demonstrate that data encrypted by one tenant's branch key can be decrypted by that tenant,
235226
// and that the decrypted data matches the input data.
236227
decrypt_input.ciphertext = &ciphertext_a;
237-
decrypt_input.encryption_context = Some(&encryption_context_a);
238-
let decryption_response_a = esdk_client.decrypt(&decrypt_input).await?;
228+
decrypt_input.encryption_context = &encryption_context_a;
229+
let decryption_response_a = decrypt(&decrypt_input).await?;
239230

240231
let decrypted_plaintext_a = decryption_response_a.plaintext;
241232

@@ -248,9 +239,9 @@ pub async fn encrypt_and_decrypt_with_keyring(
248239

249240
// Similarly for TenantB
250241
decrypt_input.ciphertext = &ciphertext_b;
251-
decrypt_input.encryption_context = Some(&encryption_context_b);
242+
decrypt_input.encryption_context = &encryption_context_b;
252243
decrypt_input.keyring = Some(hierarchical_keyring_b.clone());
253-
let decryption_response_b = esdk_client.decrypt(&decrypt_input).await?;
244+
let decryption_response_b = decrypt(&decrypt_input).await?;
254245
let decrypted_plaintext_b = decryption_response_b.plaintext;
255246

256247
// Demonstrate that the decrypted plaintext is identical to the original plaintext.

0 commit comments

Comments
 (0)