diff --git a/AwsEncryptionSDK/Makefile b/AwsEncryptionSDK/Makefile index 8cde280e2..69c9b7dd1 100644 --- a/AwsEncryptionSDK/Makefile +++ b/AwsEncryptionSDK/Makefile @@ -9,6 +9,28 @@ DIR_STRUCTURE_V2=V2 PROJECT_SERVICES := \ AwsEncryptionSdk \ +MAIN_SERVICE_FOR_RUST := AwsEncryptionSdk + +RUST_OTHER_FILES := \ + runtimes/rust/src/aes_gcm.rs \ + runtimes/rust/src/aes_kdf_ctr.rs \ + runtimes/rust/src/ddb.rs \ + runtimes/rust/src/concurrent_call.rs \ + runtimes/rust/src/dafny_libraries.rs \ + runtimes/rust/src/digest.rs \ + runtimes/rust/src/ecdh.rs \ + runtimes/rust/src/ecdsa.rs \ + runtimes/rust/src/hmac.rs \ + runtimes/rust/src/kms.rs \ + runtimes/rust/src/local_cmc.rs \ + runtimes/rust/src/random.rs \ + runtimes/rust/src/rsa.rs \ + runtimes/rust/src/sets.rs \ + runtimes/rust/src/software_externs.rs \ + runtimes/rust/src/storm_tracker.rs \ + runtimes/rust/src/time.rs \ + runtimes/rust/src/uuid.rs + SERVICE_NAMESPACE_AwsEncryptionSdk=aws.cryptography.encryptionSdk MAX_RESOURCE_COUNT=90000000 # Order is important diff --git a/AwsEncryptionSDK/runtimes/rust/src/ddb.rs b/AwsEncryptionSDK/runtimes/rust/src/ddb.rs index c2ce5e0d4..2032916b5 100644 --- a/AwsEncryptionSDK/runtimes/rust/src/ddb.rs +++ b/AwsEncryptionSDK/runtimes/rust/src/ddb.rs @@ -6,6 +6,14 @@ #![deny(clippy::all)] use aws_config::Region; +use std::sync::LazyLock; + +static DAFNY_TOKIO_RUNTIME: LazyLock = LazyLock::new(|| { + tokio::runtime::Builder::new_multi_thread() + .enable_all() + .build() + .unwrap() +}); #[allow(non_snake_case)] impl crate::r#software::amazon::cryptography::services::dynamodb::internaldafny::_default { @@ -19,11 +27,16 @@ impl crate::r#software::amazon::cryptography::services::dynamodb::internaldafny: dafny_runtime::dafny_runtime_conversions::unicode_chars_false::dafny_string_to_string( region, ); - let shared_config = tokio::task::block_in_place(|| { - tokio::runtime::Handle::current().block_on(async { - aws_config::load_defaults(aws_config::BehaviorVersion::v2024_03_28()).await - }) - }); + let shared_config = match tokio::runtime::Handle::try_current() { + Ok(curr) => tokio::task::block_in_place(|| { + curr.block_on(async { + aws_config::load_defaults(aws_config::BehaviorVersion::v2024_03_28()).await + }) + }), + Err(_) => DAFNY_TOKIO_RUNTIME.block_on(aws_config::load_defaults( + aws_config::BehaviorVersion::v2024_03_28(), + )), + }; let shared_config = shared_config .to_builder() .region(Region::new(region)) @@ -42,11 +55,16 @@ impl crate::r#software::amazon::cryptography::services::dynamodb::internaldafny: ::std::rc::Rc > >{ - let shared_config = tokio::task::block_in_place(|| { - tokio::runtime::Handle::current().block_on(async { - aws_config::load_defaults(aws_config::BehaviorVersion::v2024_03_28()).await - }) - }); + let shared_config = match tokio::runtime::Handle::try_current() { + Ok(curr) => tokio::task::block_in_place(|| { + curr.block_on(async { + aws_config::load_defaults(aws_config::BehaviorVersion::v2024_03_28()).await + }) + }), + Err(_) => DAFNY_TOKIO_RUNTIME.block_on(aws_config::load_defaults( + aws_config::BehaviorVersion::v2024_03_28(), + )), + }; let inner = aws_sdk_dynamodb::Client::new(&shared_config); let client = crate::deps::com_amazonaws_dynamodb::client::Client { inner }; let dafny_client = ::dafny_runtime::upcast_object()(::dafny_runtime::object::new(client)); diff --git a/AwsEncryptionSDK/runtimes/rust/src/kms.rs b/AwsEncryptionSDK/runtimes/rust/src/kms.rs index d395ed757..571a3b3fa 100644 --- a/AwsEncryptionSDK/runtimes/rust/src/kms.rs +++ b/AwsEncryptionSDK/runtimes/rust/src/kms.rs @@ -6,6 +6,14 @@ #![deny(clippy::all)] use aws_config::Region; +use std::sync::LazyLock; + +static DAFNY_TOKIO_RUNTIME: LazyLock = LazyLock::new(|| { + tokio::runtime::Builder::new_multi_thread() + .enable_all() + .build() + .unwrap() +}); impl crate::r#software::amazon::cryptography::services::kms::internaldafny::_default { #[allow(non_snake_case)] @@ -14,11 +22,17 @@ impl crate::r#software::amazon::cryptography::services::kms::internaldafny::_def dafny_runtime::dafny_runtime_conversions::unicode_chars_false::dafny_string_to_string( region, ); - let shared_config = tokio::task::block_in_place(|| { - tokio::runtime::Handle::current().block_on(async { - aws_config::load_defaults(aws_config::BehaviorVersion::v2024_03_28()).await - }) - }); + + let shared_config = match tokio::runtime::Handle::try_current() { + Ok(curr) => tokio::task::block_in_place(|| { + curr.block_on(async { + aws_config::load_defaults(aws_config::BehaviorVersion::v2024_03_28()).await + }) + }), + Err(_) => DAFNY_TOKIO_RUNTIME.block_on(aws_config::load_defaults( + aws_config::BehaviorVersion::v2024_03_28(), + )), + }; let shared_config = shared_config .to_builder() @@ -34,11 +48,17 @@ impl crate::r#software::amazon::cryptography::services::kms::internaldafny::_def #[allow(non_snake_case)] pub fn KMSClient() -> ::std::rc::Rc, ::std::rc::Rc>>{ - let shared_config = tokio::task::block_in_place(|| { - tokio::runtime::Handle::current().block_on(async { - aws_config::load_defaults(aws_config::BehaviorVersion::v2024_03_28()).await - }) - }); + let shared_config = match tokio::runtime::Handle::try_current() { + Ok(curr) => tokio::task::block_in_place(|| { + curr.block_on(async { + aws_config::load_defaults(aws_config::BehaviorVersion::v2024_03_28()).await + }) + }), + Err(_) => DAFNY_TOKIO_RUNTIME.block_on(aws_config::load_defaults( + aws_config::BehaviorVersion::v2024_03_28(), + )), + }; + let inner = aws_sdk_kms::Client::new(&shared_config); let client = crate::deps::com_amazonaws_kms::client::Client { inner }; let dafny_client = ::dafny_runtime::upcast_object()(::dafny_runtime::object::new(client)); diff --git a/AwsEncryptionSDK/runtimes/rust/src/software_externs.rs b/AwsEncryptionSDK/runtimes/rust/src/software_externs.rs index b0eb2e080..5ff57e57f 100644 --- a/AwsEncryptionSDK/runtimes/rust/src/software_externs.rs +++ b/AwsEncryptionSDK/runtimes/rust/src/software_externs.rs @@ -17,83 +17,6 @@ pub mod software { pub use crate::local_cmc::internal_SynchronizedLocalCMC::*; } } - pub mod dbencryptionsdk { - pub mod dynamodb { - pub mod itemencryptor { - pub mod internaldafny { - pub mod legacy { - use crate::software::amazon::cryptography::dbencryptionsdk::dynamodb::itemencryptor::internaldafny::types::Error as DafnyError; - use crate::software::amazon::cryptography::dbencryptionsdk::dynamodb::internaldafny::types::LegacyPolicy; - use ::std::rc::Rc; - type Legacy = ::dafny_runtime::Object; - - fn error(s: &str) -> Rc { - Rc::new(DafnyError::DynamoDbItemEncryptorException { - message: - dafny_runtime::dafny_runtime_conversions::unicode_chars_false::string_to_dafny_string(s), - }) - } - pub struct InternalLegacyOverride { - pub r#__i_policy: Rc, - } - fn fail_override() -> Rc< - crate::_Wrappers_Compile::Result< - Rc>, - Rc, - >, - > { - Rc::new(crate::_Wrappers_Compile::Result::Failure { - error: error("Legacy configuration unsupported."), - }) - } - fn success_override() -> Rc< - crate::_Wrappers_Compile::Result< - Rc>, - Rc, - >, - > { - Rc::new(crate::_Wrappers_Compile::Result::Success { - value: Rc::new(crate::_Wrappers_Compile::Option::None {}), - }) - } - - impl InternalLegacyOverride { - pub fn Build( - config: &Rc, - ) -> Rc< - crate::_Wrappers_Compile::Result< - Rc>, - Rc, - >, - > { - match &**config.legacyOverride() { - crate::_Wrappers_Compile::Option::Some{value} => { - match &**value.policy() { - LegacyPolicy::FORBID_LEGACY_ENCRYPT_FORBID_LEGACY_DECRYPT{} => success_override(), - _ => fail_override() - } - } - crate::_Wrappers_Compile::Option::None{} => success_override() - } - } - pub fn EncryptItem(&mut self, _input: &Rc) -> Rc, Rc>>{ - todo!("InternalLLegacyOverride::EncryptItem") - } - pub fn DecryptItem(&mut self, _input: &Rc) -> Rc, Rc>>{ - todo!("InternalLLegacyOverride::DecryptItem") - } - pub fn IsLegacyInput( - &self, - _input: &Rc, - ) -> bool { - false - } - } - } - } - } - } - } } } }