Skip to content

Commit e2b46f3

Browse files
committed
m
1 parent 0c613ce commit e2b46f3

File tree

8 files changed

+43
-34
lines changed

8 files changed

+43
-34
lines changed

DynamoDbEncryption/Makefile

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ include ../SharedMakefile.mk
77

88
DIR_STRUCTURE_V2=V2
99

10+
TRANSPILE_TESTS_IN_RUST=1
11+
1012
PROJECT_SERVICES := \
1113
DynamoDbEncryption \
1214
DynamoDbItemEncryptor \

DynamoDbEncryption/runtimes/rust/examples/clientsupplier/client_supplier_example.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ pub async fn put_item_get_item() -> Result<(), crate::BoxError> {
5454
// defined in the RegionalRoleClientSupplier class in this directory.
5555
// Note: RegionalRoleClientSupplier will internally use the key_arn's region
5656
// to retrieve the correct IAM role.
57-
// let supplier_ref = ClientSupplierRef {
58-
// inner: std::rc::Rc::new(std::cell::RefCell::new(RegionalRoleClientSupplier {})),
59-
// };
57+
// let supplier_ref = ClientSupplierRef {
58+
// inner: std::rc::Rc::new(std::cell::RefCell::new(RegionalRoleClientSupplier {})),
59+
// };
6060

6161
let mrk_keyring_with_client_supplier = mpl
6262
.create_aws_kms_mrk_multi_keyring()

DynamoDbEncryption/runtimes/rust/examples/clientsupplier/regional_role_client_supplier.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use aws_db_esdk::deps::com_amazonaws_kms::client::Client as kms_client;
1313
pub struct RegionalRoleClientSupplier {}
1414

1515
impl ClientSupplier for RegionalRoleClientSupplier {
16-
fn get_client(&mut self, input: GetClientInput) -> Result<kms_client, Error> {
16+
fn get_client(&self, input: GetClientInput) -> Result<kms_client, Error> {
1717
let region = input.region.unwrap();
1818
let arn =
1919
super::regional_role_client_supplier_config::region_iam_role_map()[&region].clone();

DynamoDbEncryption/runtimes/rust/examples/keyring/branch_key_id_supplier.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ impl ExampleBranchKeyIdSupplier {
3030

3131
impl DynamoDbKeyBranchKeyIdSupplier for ExampleBranchKeyIdSupplier {
3232
fn get_branch_key_id_from_ddb_key(
33-
&mut self,
33+
&self,
3434
input: GetBranchKeyIdFromDdbKeyInput,
3535
) -> Result<GetBranchKeyIdFromDdbKeyOutput, Error> {
3636
let key = input.ddb_key.unwrap();

DynamoDbEncryption/runtimes/rust/examples/keyring/hierarchical_keyring.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

4+
use super::branch_key_id_supplier::ExampleBranchKeyIdSupplier;
45
use crate::test_utils;
5-
use aws_db_esdk::aws_cryptography_keyStore::types::KmsConfiguration;
6-
use aws_db_esdk::aws_cryptography_keyStore::types::key_store_config::KeyStoreConfig;
7-
use aws_db_esdk::aws_cryptography_materialProviders::client as mpl_client;
86
use aws_db_esdk::aws_cryptography_dbEncryptionSdk_dynamoDb::client as dbesdk_client;
9-
use aws_db_esdk::aws_cryptography_keyStore::client as keystore_client;
107
use aws_db_esdk::aws_cryptography_dbEncryptionSdk_dynamoDb::types::dynamo_db_encryption_config::DynamoDbEncryptionConfig;
11-
use super::branch_key_id_supplier::ExampleBranchKeyIdSupplier;
8+
use aws_db_esdk::aws_cryptography_keyStore::client as keystore_client;
9+
use aws_db_esdk::aws_cryptography_keyStore::types::key_store_config::KeyStoreConfig;
10+
use aws_db_esdk::aws_cryptography_keyStore::types::KmsConfiguration;
11+
use aws_db_esdk::aws_cryptography_materialProviders::client as mpl_client;
1212
use aws_db_esdk::aws_cryptography_materialProviders::types::material_providers_config::MaterialProvidersConfig;
1313
//use aws_db_esdk::aws_cryptography_dbEncryptionSdk_dynamoDb::types::dynamo_db_key_branch_key_id_supplier::DynamoDbKeyBranchKeyIdSupplierRef;
14-
use aws_db_esdk::aws_cryptography_dbEncryptionSdk_structuredEncryption::types::CryptoAction;
15-
use std::collections::HashMap;
1614
use aws_db_esdk::aws_cryptography_dbEncryptionSdk_dynamoDb::types::DynamoDbTableEncryptionConfig;
17-
use aws_db_esdk::DynamoDbTablesEncryptionConfig;
15+
use aws_db_esdk::aws_cryptography_dbEncryptionSdk_structuredEncryption::types::CryptoAction;
1816
use aws_db_esdk::intercept::DbEsdkInterceptor;
17+
use aws_db_esdk::DynamoDbTablesEncryptionConfig;
1918
use aws_sdk_dynamodb::types::AttributeValue;
19+
use std::collections::HashMap;
2020

2121
/*
2222
This example sets up DynamoDb Encryption for the AWS SDK client
@@ -94,9 +94,9 @@ pub async fn put_item_get_item(
9494
let dbesdk_config = DynamoDbEncryptionConfig::builder().build()?;
9595
let dbesdk = dbesdk_client::Client::from_conf(dbesdk_config)?;
9696
let supplier = ExampleBranchKeyIdSupplier::new(tenant1_branch_key_id, tenant2_branch_key_id);
97-
// let supplier_ref = DynamoDbKeyBranchKeyIdSupplierRef {
98-
// inner: ::std::rc::Rc::new(std::cell::RefCell::new(supplier)),
99-
// };
97+
// let supplier_ref = DynamoDbKeyBranchKeyIdSupplierRef {
98+
// inner: ::std::rc::Rc::new(std::cell::RefCell::new(supplier)),
99+
// };
100100
let branch_key_id_supplier = dbesdk
101101
.create_dynamo_db_encryption_branch_key_id_supplier()
102102
.ddb_key_branch_key_id_supplier(supplier)

DynamoDbEncryption/runtimes/rust/src/hmac.rs

+23-16
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ pub mod HMAC {
5555
}
5656
pub struct HMac {
5757
algorithm: hmac::Algorithm,
58-
inner: RefCell<HMacInner>
58+
inner: RefCell<HMacInner>,
5959
}
6060

6161
impl dafny_runtime::UpcastObject<dyn std::any::Any> for HMac {
@@ -66,10 +66,14 @@ pub mod HMAC {
6666
pub fn Init(&self, salt: &::dafny_runtime::Sequence<u8>) {
6767
let salt: Vec<u8> = salt.iter().collect();
6868
self.inner.borrow_mut().key = Some(hmac::Key::new(self.algorithm, &salt));
69-
self.inner.borrow_mut().context = Some(hmac::Context::with_key(self.inner.borrow().key.as_ref().unwrap()));
69+
let context = Some(hmac::Context::with_key(self.inner.borrow().key.as_ref().unwrap()));
70+
self.inner.borrow_mut().context = context;
7071
}
7172
pub fn re_init(&self) {
72-
self.inner.borrow_mut().context = Some(hmac::Context::with_key(self.inner.borrow().key.as_ref().unwrap()));
73+
let context = Some(hmac::Context::with_key(
74+
self.inner.borrow().key.as_ref().unwrap(),
75+
));
76+
self.inner.borrow_mut().context = context;
7377
}
7478
pub fn Build(
7579
input: &::std::rc::Rc<
@@ -85,30 +89,33 @@ pub mod HMAC {
8589
> {
8690
let inner = dafny_runtime::Object::new(Self {
8791
algorithm: super::convert_algorithm(input),
88-
inner : RefCell::new(HMacInner {
92+
inner: RefCell::new(HMacInner {
8993
context: None,
9094
key: None,
91-
})
95+
}),
9296
});
9397

9498
::std::rc::Rc::new(_Wrappers_Compile::Result::Success { value: inner })
9599
}
96100
pub fn BlockUpdate(&self, block: &::dafny_runtime::Sequence<u8>) {
97101
let part: Vec<u8> = block.iter().collect();
98-
self.inner.borrow_mut().context.as_mut().unwrap().update(&part);
102+
self.inner
103+
.borrow_mut()
104+
.context
105+
.as_mut()
106+
.unwrap()
107+
.update(&part);
99108
}
100109
pub fn GetResult(&self) -> ::dafny_runtime::Sequence<u8> {
101-
let inner = self.inner.borrow_mut().context.take();
102-
match inner {
103-
Some(x) => {
104-
let tag = x.sign();
105-
// other languages allow you to call BlockUpdate after GetResult
106-
// so we re-initialize to mimic that behavior
107-
self.re_init();
108-
tag.as_ref().iter().cloned().collect()
109-
}
110-
None => [].iter().cloned().collect(),
110+
let is_empty = self.inner.borrow().context.is_none();
111+
if is_empty {
112+
return [].iter().cloned().collect();
111113
}
114+
let tag = self.inner.borrow_mut().context.take().unwrap().sign();
115+
// other languages allow you to call BlockUpdate after GetResult
116+
// so we re-initialize to mimic that behavior
117+
self.re_init();
118+
tag.as_ref().iter().cloned().collect()
112119
}
113120
}
114121
}

submodules/smithy-dafny

0 commit comments

Comments
 (0)