Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ebf6564

Browse files
committedNov 25, 2024··
m
1 parent d638ee9 commit ebf6564

File tree

8 files changed

+183
-10
lines changed

8 files changed

+183
-10
lines changed
 

‎.github/workflows/library_rust_tests.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
strategy:
2020
fail-fast: false
2121
matrix:
22-
library: [DynamoDbEncryption] # , TestVectors]
22+
library: [DynamoDbEncryption, TestVectors]
2323
# removed windows-latest because somehow it can't build aws-lc in CI
2424
os: [ubuntu-latest, macos-13]
2525
runs-on: ${{ matrix.os }}
@@ -54,11 +54,10 @@ jobs:
5454
# - name: Rustfmt Check
5555
# uses: actions-rust-lang/rustfmt@v1
5656

57-
# Use setup-dafny-actions with correct version when Dafny releases 4.8.2
5857
- name: Setup Dafny
5958
uses: dafny-lang/setup-dafny-action@v1.7.0
6059
with:
61-
dafny-version: 4.9.0
60+
dafny-version: nightly-latest
6261

6362
# Remove this after the formatting in Rust starts working
6463
- name: smithy-dafny Rust hacks
@@ -97,6 +96,13 @@ jobs:
9796
CORES=$(node -e 'console.log(os.cpus().length)')
9897
make transpile_rust TRANSPILE_TESTS_IN_RUST=1 CORES=$CORES
9998
99+
- name: Copy ${{ matrix.library }} Vector Files
100+
if: ${{ matrix.library == TestVectors' }}
101+
shell: bash
102+
working-directory: ./${{ matrix.library }}
103+
run: |
104+
cp runtimes/java/*.json runtimes/rust/
105+
100106
- name: Test ${{ matrix.library }} Rust
101107
shell: bash
102108
working-directory: ./${{ matrix.library }}

‎TestVectors/Makefile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# SPDX-License-Identifier: Apache-2.0
33

44
CORES=2
5+
TRANSPILE_TESTS_IN_RUST=1
56

67
include ../SharedMakefile.mk
78

@@ -27,11 +28,13 @@ PROJECT_DEPENDENCIES := \
2728
submodules/MaterialProviders/TestVectorsAwsCryptographicMaterialProviders \
2829
DynamoDbEncryption \
2930

31+
3032
RUST_OTHER_FILES := \
3133
runtimes/rust/src/aes_gcm.rs \
3234
runtimes/rust/src/aes_kdf_ctr.rs \
3335
runtimes/rust/src/ddb.rs \
3436
runtimes/rust/src/concurrent_call.rs \
37+
runtimes/rust/src/create_client.rs \
3538
runtimes/rust/src/dafny_libraries.rs \
3639
runtimes/rust/src/digest.rs \
3740
runtimes/rust/src/ecdh.rs \
@@ -77,9 +80,6 @@ SERVICE_DEPS_DDBEncryption := \
7780
DynamoDbEncryption/dafny/DynamoDbEncryption \
7881
submodules/MaterialProviders/TestVectorsAwsCryptographicMaterialProviders/dafny/TestVectorsAwsCryptographicMaterialProviders \
7982

80-
81-
format_net:
82-
pushd runtimes/net && dotnet format && popd
83-
84-
clean:
85-
rm -f runtimes/java/WriteTests1.json runtimes/java/decrypt.json runtimes/java/encrypt.json runtimes/net/*.json
83+
_remove_wrapped_client_rust:
84+
$(MAKE) _sed_file SED_FILE_PATH="runtimes/rust/src/deps/aws_cryptography_materialProviders.rs" \
85+
SED_BEFORE_STRING=' \#\[cfg(feature = "wrapped-client")\]' SED_AFTER_STRING='\/\/ Removed cfg(feature = "wrapped-client")'

‎TestVectors/dafny/DDBEncryption/src/CreateInterceptedDDBClient.dfy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
include "../Model/AwsCryptographyDynamoDbEncryptionTypesWrapped.dfy"
55

6-
module CreateInterceptedDDBClient {
6+
module {:extern} CreateInterceptedDDBClient {
77
import opened Wrappers
88
import AwsCryptographyDbEncryptionSdkDynamoDbTypes
99
import ComAmazonawsDynamodbTypes

‎TestVectors/dafny/DDBEncryption/src/TestVectors.dfy

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ module {:options "-functionSyntax:4"} DdbEncryptionTestVectors {
9797
}
9898
Validate();
9999
StringOrdering();
100+
var skipLocal := FileIO.ReadBytesFromFile("SkipLocal.txt");
101+
if skipLocal.Success? {
102+
return;
103+
}
100104
BasicIoTest();
101105
RunIoTests();
102106
BasicQueryTest();

‎TestVectors/runtimes/rust/Cargo.toml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[package]
2+
name = "aws-db-esdk-test-vectors"
3+
version = "0.1.0"
4+
edition = "2021"
5+
rust-version = "1.80.0"
6+
7+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
8+
9+
[dependencies]
10+
aws-config = "1.5.8"
11+
aws-lc-rs = "1.10.0"
12+
aws-lc-sys = "0.22.0"
13+
aws-sdk-dynamodb = "1.50.0"
14+
aws-sdk-kms = "1.47.0"
15+
aws-smithy-runtime-api = {version = "1.7.2", features = ["client"] }
16+
aws-smithy-types = "1.2.8"
17+
chrono = "0.4.38"
18+
dafny_runtime = { path = "../../../submodules/MaterialProviders/smithy-dafny/TestModels/dafny-dependencies/dafny_runtime_rust"}
19+
dashmap = "6.1.0"
20+
pem = "3.0.4"
21+
tokio = {version = "1.41.0", features = ["full"] }
22+
uuid = { version = "1.11.0", features = ["v4"] }
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Rust can't deal with wrapped DDB Client yet.
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
use std::rc::Rc;
2+
use dafny_runtime::Object;
3+
use crate::implementation_from_dafny::software::amazon::cryptography::services::dynamodb::internaldafny::types::IDynamoDBClient;
4+
use crate::implementation_from_dafny::software::amazon::cryptography::dbencryptionsdk::dynamodb::internaldafny::types::Error;
5+
use crate::implementation_from_dafny::_Wrappers_Compile;
6+
use std::sync::LazyLock;
7+
// use crate::intercept::DbEsdkInterceptor;
8+
9+
static DAFNY_TOKIO_RUNTIME: LazyLock<tokio::runtime::Runtime> = LazyLock::new(|| {
10+
tokio::runtime::Builder::new_multi_thread()
11+
.enable_all()
12+
.build()
13+
.unwrap()
14+
});
15+
16+
pub mod _CreateInterceptedDDBClient_Compile {
17+
pub struct _default {}
18+
}
19+
impl _CreateInterceptedDDBClient_Compile::_default {
20+
21+
pub fn CreateInterceptedDDBClient(config : &Rc<crate::implementation_from_dafny::software::amazon::cryptography::dbencryptionsdk::dynamodb::internaldafny::types::DynamoDbTablesEncryptionConfig>)
22+
-> Rc<_Wrappers_Compile::Result<Object<dyn IDynamoDBClient>, Rc<Error>>>
23+
{
24+
let shared_config = DAFNY_TOKIO_RUNTIME.block_on(aws_config::load_defaults(
25+
aws_config::BehaviorVersion::v2024_03_28()));
26+
27+
let shared_config = shared_config
28+
.to_builder()
29+
.endpoint_url("http://localhost:8000")
30+
.build();
31+
32+
let dynamo_config = aws_sdk_dynamodb::config::Builder::from(&shared_config)
33+
// .interceptor(DbEsdkInterceptor::new(table_configs))
34+
.build();
35+
let inner = aws_sdk_dynamodb::Client::from_conf(dynamo_config);
36+
37+
let client = crate::deps::com_amazonaws_dynamodb::client::Client { inner };
38+
let dafny_client = ::dafny_runtime::upcast_object()(::dafny_runtime::object::new(client));
39+
std::rc::Rc::new(crate::r#_Wrappers_Compile::Result::Success {
40+
value: dafny_client,
41+
})
42+
}
43+
pub fn CreateVanillaDDBClient()
44+
-> Rc<_Wrappers_Compile::Result<Object<dyn IDynamoDBClient>, Rc<Error>>>
45+
{
46+
let shared_config = DAFNY_TOKIO_RUNTIME.block_on(aws_config::load_defaults(
47+
aws_config::BehaviorVersion::v2024_03_28()));
48+
49+
let shared_config = shared_config
50+
.to_builder()
51+
.endpoint_url("http://localhost:8000")
52+
.build();
53+
let inner = aws_sdk_dynamodb::Client::new(&shared_config);
54+
let client = crate::deps::com_amazonaws_dynamodb::client::Client { inner };
55+
let dafny_client = ::dafny_runtime::upcast_object()(::dafny_runtime::object::new(client));
56+
std::rc::Rc::new(crate::r#_Wrappers_Compile::Result::Success {
57+
value: dafny_client,
58+
})
59+
}
60+
61+
}
62+
63+
64+
// public static _IResult<IDynamoDBClient, _IError> CreateInterceptedDDBClient(software.amazon.cryptography.dbencryptionsdk.dynamodb.internaldafny.types._IDynamoDbTablesEncryptionConfig config)
65+
// {
66+
// var clientConfig = new AmazonDynamoDBConfig();
67+
// clientConfig.ServiceURL = "http://localhost:8000";
68+
69+
// var native = AWS.Cryptography.DbEncryptionSDK.DynamoDb.Transforms.TypeConversion
70+
// .FromDafny_N3_aws__N12_cryptography__N15_dbEncryptionSdk__N8_dynamoDb__S30_DynamoDbTablesEncryptionConfig(
71+
// config);
72+
73+
// var client = new Client.DynamoDbClient(clientConfig, native);
74+
// var c2 = new Com.Amazonaws.Dynamodb.DynamoDBv2Shim(client);
75+
// return new Result_Success<IDynamoDBClient, _IError>(c2);
76+
// }

‎TestVectors/runtimes/rust/src/lib.rs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#![allow(warnings, unconditional_panic)]
2+
#![allow(nonstandard_style)]
3+
4+
pub mod client;
5+
pub mod conversions;
6+
pub mod deps;
7+
/// Common errors and error handling utilities.
8+
pub mod error;
9+
/// All operations that this crate can perform.
10+
pub mod operation;
11+
pub mod types;
12+
13+
#[cfg(feature = "wrapped-client")]
14+
pub mod wrapped;
15+
16+
mod standard_library_conversions;
17+
mod standard_library_externs;
18+
19+
pub use client::Client;
20+
21+
// pub use crate::deps::aws_cryptography_dbEncryptionSdk_dynamoDb;
22+
// pub use crate::deps::aws_cryptography_dbEncryptionSdk_dynamoDb_itemEncryptor;
23+
pub use crate::deps::aws_cryptography_dbEncryptionSdk_structuredEncryption;
24+
pub use crate::deps::aws_cryptography_keyStore;
25+
pub use crate::deps::aws_cryptography_materialProviders;
26+
pub use crate::deps::aws_cryptography_primitives;
27+
28+
pub(crate) mod implementation_from_dafny;
29+
pub(crate) use crate::implementation_from_dafny::r#_Wrappers_Compile;
30+
pub(crate) use crate::implementation_from_dafny::software;
31+
pub(crate) use crate::implementation_from_dafny::AesKdfCtr;
32+
pub(crate) use crate::implementation_from_dafny::ConcurrentCall;
33+
pub(crate) use crate::implementation_from_dafny::DafnyLibraries;
34+
pub(crate) use crate::implementation_from_dafny::ExternDigest;
35+
pub(crate) use crate::implementation_from_dafny::ExternRandom;
36+
pub(crate) use crate::implementation_from_dafny::Signature;
37+
pub(crate) use crate::implementation_from_dafny::Time;
38+
pub(crate) use crate::implementation_from_dafny::_LocalCMC_Compile;
39+
pub(crate) use crate::implementation_from_dafny::_StormTracker_Compile;
40+
pub(crate) use crate::implementation_from_dafny::ECDH;
41+
pub(crate) use crate::implementation_from_dafny::HMAC;
42+
pub(crate) use crate::implementation_from_dafny::UTF8;
43+
pub(crate) use crate::implementation_from_dafny::UUID;
44+
45+
pub mod aes_gcm;
46+
pub mod aes_kdf_ctr;
47+
pub mod concurrent_call;
48+
pub mod dafny_libraries;
49+
pub mod ddb;
50+
pub mod digest;
51+
pub mod ecdh;
52+
pub mod ecdsa;
53+
pub mod hmac;
54+
pub mod kms;
55+
pub mod local_cmc;
56+
pub mod random;
57+
pub mod rsa;
58+
pub mod sets;
59+
pub mod software_externs;
60+
pub mod storm_tracker;
61+
pub mod time;
62+
pub mod uuid;
63+
64+
pub mod create_client;

0 commit comments

Comments
 (0)
Please sign in to comment.