diff --git a/AwsEncryptionSDK/runtimes/rust/Cargo.toml b/AwsEncryptionSDK/runtimes/rust/Cargo.toml index 68d145783..8daf117ca 100644 --- a/AwsEncryptionSDK/runtimes/rust/Cargo.toml +++ b/AwsEncryptionSDK/runtimes/rust/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "aws-esdk" -version = "1.1.1" +version = "1.2.0" edition = "2021" rust-version = "1.86.0" keywords = ["cryptography", "security", "dynamodb", "encryption", "client-side"] diff --git a/AwsEncryptionSDK/runtimes/rust/start_release.sh b/AwsEncryptionSDK/runtimes/rust/start_release.sh index 3b5b2c4bf..2396103b0 100755 --- a/AwsEncryptionSDK/runtimes/rust/start_release.sh +++ b/AwsEncryptionSDK/runtimes/rust/start_release.sh @@ -25,8 +25,10 @@ echo echo sleep 2 +VERSION=$1 + # Update the version in Cargo.toml -perl -pe "s/^version = .*$/version = \"$1\"/" < Cargo.toml > new_Cargo.toml +perl -pe "s/^version = .*$/version = \"$VERSION\"/" < Cargo.toml > new_Cargo.toml mv new_Cargo.toml Cargo.toml set -v @@ -75,3 +77,13 @@ cargo test --release --examples # Remove Cargo.lock and .pem files after testing the examples rm -f Cargo.lock *.pem + +set +v + +echo +echo Next Steps: +echo cd $(realpath ${PWD}/../../../releases/rust/esdk) +echo Make a PR +echo Get it merged +echo cargo publish +echo diff --git a/releases/rust/esdk/Cargo.toml b/releases/rust/esdk/Cargo.toml index 45ee94c93..14a415cca 100644 --- a/releases/rust/esdk/Cargo.toml +++ b/releases/rust/esdk/Cargo.toml @@ -1,8 +1,8 @@ [package] name = "aws-esdk" -version = "1.1.1" +version = "1.2.0" edition = "2021" -rust-version = "1.81.0" +rust-version = "1.86.0" keywords = ["cryptography", "security", "dynamodb", "encryption", "client-side"] license = "ISC AND (Apache-2.0 OR ISC)" description = "aws-esdk is a library for implementing client side encryption." @@ -16,21 +16,27 @@ readme = "README.md" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -aws-config = "1.6.3" -aws-lc-rs = "=1.13.1" -aws-lc-sys = "=0.29.0" -aws-sdk-dynamodb = "1.73.0" -aws-sdk-kms = "1.67.0" -aws-smithy-runtime-api = {version = "1.8.0", features = ["client"] } -aws-smithy-types = "1.3.1" +aws-config = "1.8.5" +aws-lc-rs = {version = "1.13.3"} +aws-lc-sys = { version = "0.30", optional = true } +aws-lc-fips-sys = { version = "0.13", optional = true } +aws-sdk-dynamodb = "1.90.0" +aws-sdk-kms = "1.84.0" +aws-smithy-runtime-api = {version = "1.9.0", features = ["client"] } +aws-smithy-types = "1.3.2" chrono = "0.4.41" cpu-time = "1.0.0" -dafny-runtime = { version = "0.3.1", features = ["sync", "small-int"] } dashmap = "6.1.0" pem = "3.0.5" -rand = "0.9.1" -tokio = {version = "1.45.1", features = ["full"] } -uuid = { version = "1.17.0", features = ["v4"] } +rand = "0.9.2" +tokio = {version = "1.47.1", features = ["full"] } +uuid = { version = "1.18.0", features = ["v4"] } +dafny-runtime = { version = "0.3.1", features = ["sync", "small-int"] } [[example]] name = "main" + +[features] +fips = ["aws-lc-rs/fips", "dep:aws-lc-fips-sys"] +non-fips = ["aws-lc-rs/aws-lc-sys", "dep:aws-lc-sys"] +default = ["non-fips"] diff --git a/releases/rust/esdk/examples/client_supplier/regional_role_client_supplier.rs b/releases/rust/esdk/examples/client_supplier/regional_role_client_supplier.rs index df314f190..e3eef8e0d 100644 --- a/releases/rust/esdk/examples/client_supplier/regional_role_client_supplier.rs +++ b/releases/rust/esdk/examples/client_supplier/regional_role_client_supplier.rs @@ -24,7 +24,7 @@ impl ClientSupplier for RegionalRoleClientSupplier { if !region_iam_role_map.contains_key(®ion) { return Err(Error::AwsCryptographicMaterialProvidersException { - message: format!("Region {} is not supported by this client supplier", region) + message: format!("Region {region} is not supported by this client supplier") .to_string(), }); } diff --git a/releases/rust/esdk/examples/example_utils/utils.rs b/releases/rust/esdk/examples/example_utils/utils.rs index 9d47152de..5e78faab3 100644 --- a/releases/rust/esdk/examples/example_utils/utils.rs +++ b/releases/rust/esdk/examples/example_utils/utils.rs @@ -205,18 +205,18 @@ fn generate_raw_ecc_key_pair( // P256, P384, or P521. // This key is created here for example purposes only. let private_key = aws_lc_rs::agreement::PrivateKey::generate(get_alg(ecdh_curve_spec)) - .map_err(|e| format!("{:?}", e))?; + .map_err(|e| format!("{e:?}"))?; let public_key = private_key .compute_public_key() - .map_err(|e| format!("{:?}", e))?; + .map_err(|e| format!("{e:?}"))?; let public_key: Vec = x962_to_x509(public_key.as_ref(), get_nid(ecdh_curve_spec))?; let public_key = pem::Pem::new("PUBLIC KEY", public_key); let public_key = pem::encode(&public_key); let private_key_der = - AsDer::::as_der(&private_key).map_err(|e| format!("{:?}", e))?; + AsDer::::as_der(&private_key).map_err(|e| format!("{e:?}"))?; let private_key = pem::Pem::new("PRIVATE KEY", private_key_der.as_ref()); let private_key = pem::encode(&private_key); diff --git a/releases/rust/esdk/examples/main.rs b/releases/rust/esdk/examples/main.rs index ee976087a..70f9dd9a6 100644 --- a/releases/rust/esdk/examples/main.rs +++ b/releases/rust/esdk/examples/main.rs @@ -37,7 +37,7 @@ impl From for BoxError2 { impl From for BoxError { fn from(error: T) -> Self { - let my_str = format!("{:?}", error); + let my_str = format!("{error:?}"); BoxError(my_str) } } diff --git a/releases/rust/esdk/src/aes_gcm.rs b/releases/rust/esdk/src/aes_gcm.rs index 0f5b0aba4..a7e3cdf6b 100644 --- a/releases/rust/esdk/src/aes_gcm.rs +++ b/releases/rust/esdk/src/aes_gcm.rs @@ -73,13 +73,13 @@ impl AES_GCM { ) -> Result { let alg = self.get_alg()?; let mut in_out_buffer = Vec::from(msg); - let key = UnboundKey::new(alg, key).map_err(|e| format!("new {:?}", e))?; + let key = UnboundKey::new(alg, key).map_err(|e| format!("new {e:?}"))?; let nonce = Nonce::assume_unique_for_key(iv.try_into().unwrap()); let key = LessSafeKey::new(key); let aad = Aad::from(aad); let tag = key .seal_in_place_separate_tag(nonce, aad, &mut in_out_buffer) - .map_err(|e| format!("Seal {:?}", e))?; + .map_err(|e| format!("Seal {e:?}"))?; Ok(DoAESEncryptOutput { cipher_text: in_out_buffer, auth_tag: Vec::from(tag.as_ref()), @@ -96,12 +96,12 @@ impl AES_GCM { ) -> Result, String> { let alg = self.get_alg()?; let mut out_buffer = Vec::from(cipher_text); - let key = UnboundKey::new(alg, key).map_err(|e| format!("new {:?}", e))?; + let key = UnboundKey::new(alg, key).map_err(|e| format!("new {e:?}"))?; let nonce = Nonce::assume_unique_for_key(iv.try_into().unwrap()); let key = LessSafeKey::new(key); let aad = Aad::from(aad); key.open_separate_gather(nonce, aad, cipher_text, auth_tag, &mut out_buffer) - .map_err(|e| format!("gather {:?}", e))?; + .map_err(|e| format!("gather {e:?}"))?; Ok(out_buffer) } @@ -143,7 +143,7 @@ impl AES_GCM { }), }), Err(e) => { - let msg = format!("AES Encrypt : {}", e); + let msg = format!("AES Encrypt : {e}"); enc_result(&msg) } } @@ -196,7 +196,7 @@ impl AES_GCM { value: dafny_runtime::Sequence::from_array_owned(x), }), Err(e) => { - let msg = format!("AES Decrypt : {}", e); + let msg = format!("AES Decrypt : {e}"); dec_result(&msg) } } @@ -229,7 +229,7 @@ mod tests { let cipher = match &*alg.AESEncryptExtern(&iv, &key, &msg, &aad) { _Wrappers_Compile::Result::Success { value } => value.clone(), _Wrappers_Compile::Result::Failure { error } => { - panic!("AESEncryptExtern Failed : {:?}", error); + panic!("AESEncryptExtern Failed : {error:?}"); } }; @@ -240,10 +240,10 @@ mod tests { } => (cipherText, authTag), }; - let output = match &*alg.AESDecryptExtern(&key, &cipher_text, &auth_tag, &iv, &aad) { + let output = match &*alg.AESDecryptExtern(&key, cipher_text, auth_tag, &iv, &aad) { _Wrappers_Compile::Result::Success { value } => value.clone(), _Wrappers_Compile::Result::Failure { error } => { - panic!("AESEncryptExtern Failed : {:?}", error); + panic!("AESEncryptExtern Failed : {error:?}"); } }; diff --git a/releases/rust/esdk/src/aes_kdf_ctr.rs b/releases/rust/esdk/src/aes_kdf_ctr.rs index cb940bbbc..b639cb4ce 100644 --- a/releases/rust/esdk/src/aes_kdf_ctr.rs +++ b/releases/rust/esdk/src/aes_kdf_ctr.rs @@ -36,13 +36,13 @@ pub mod AesKdfCtr { let mut in_out_buffer = vec![0; length as usize]; - let key = UnboundCipherKey::new(&AES_256, key).map_err(|e| format!("new {:?}", e))?; - let encrypting_key = EncryptingKey::ctr(key).map_err(|e| format!("new {:?}", e))?; + let key = UnboundCipherKey::new(&AES_256, key).map_err(|e| format!("new {e:?}"))?; + let encrypting_key = EncryptingKey::ctr(key).map_err(|e| format!("new {e:?}"))?; let nonce = aws_lc_rs::iv::FixedLength::<16>::from(as_array(nonce)); let context = EncryptionContext::Iv128(nonce); encrypting_key .less_safe_encrypt(&mut in_out_buffer, context) - .map_err(|e| format!("new {:?}", e))?; + .map_err(|e| format!("new {e:?}"))?; Ok(in_out_buffer) } @@ -65,7 +65,7 @@ pub mod AesKdfCtr { value: dafny_runtime::Sequence::from_array_owned(x), }), Err(e) => { - let msg = format!("Aes Kdf Ctr : {}", e); + let msg = format!("Aes Kdf Ctr : {e}"); Rc::new(_Wrappers_Compile::Result::Failure { error: error(&msg) }) } } diff --git a/releases/rust/esdk/src/dafny_libraries.rs b/releases/rust/esdk/src/dafny_libraries.rs index 75cefe7b8..7c54f14d7 100644 --- a/releases/rust/esdk/src/dafny_libraries.rs +++ b/releases/rust/esdk/src/dafny_libraries.rs @@ -17,7 +17,9 @@ pub mod DafnyLibraries { } impl MutableMap { - pub fn _allocate_object() -> ::dafny_runtime::Object { + // bytesKeys should be set using ctor but it does not because of Dafny bug + // https://github.com/dafny-lang/dafny/issues/6333 + pub fn _allocate_object(_bytes_keys: bool) -> ::dafny_runtime::Object { ::dafny_runtime::Object::new(MutableMap { map: DashMap::new(), }) diff --git a/releases/rust/esdk/src/deps/aws_cryptography_materialProviders/validation.rs b/releases/rust/esdk/src/deps/aws_cryptography_materialProviders/validation.rs index b6ff22520..b29fcc87f 100644 --- a/releases/rust/esdk/src/deps/aws_cryptography_materialProviders/validation.rs +++ b/releases/rust/esdk/src/deps/aws_cryptography_materialProviders/validation.rs @@ -1706,7 +1706,7 @@ pub(crate) fn validate_aws_Pcryptography_PmaterialProviders_HCreateKeyringOutput ))?; Ok(()) } -pub(crate) fn validate_aws_Pcryptography_PmaterialProviders_HCreateKeyringOutput_for_AwsCryptographicMaterialProviders_CreateAwsKmsHierarchicalKeyring( +pub(crate) fn validate_aws_Pcryptography_PmaterialProviders_HCreateKeyringOutput_for_AwsCryptographicMaterialProviders_CreateRawEcdhKeyring( input: &crate::deps::aws_cryptography_materialProviders::types::keyring::KeyringRef, ) -> ::std::result::Result<(), ::aws_smithy_types::error::operation::BuildError> { validate_aws_Pcryptography_PmaterialProviders_HCreateKeyringOutput_Dkeyring(&Some( @@ -1722,7 +1722,7 @@ pub(crate) fn validate_aws_Pcryptography_PmaterialProviders_HCreateKeyringOutput ))?; Ok(()) } -pub(crate) fn validate_aws_Pcryptography_PmaterialProviders_HCreateKeyringOutput_for_AwsCryptographicMaterialProviders_CreateRawAesKeyring( +pub(crate) fn validate_aws_Pcryptography_PmaterialProviders_HCreateKeyringOutput_for_AwsCryptographicMaterialProviders_CreateRawRsaKeyring( input: &crate::deps::aws_cryptography_materialProviders::types::keyring::KeyringRef, ) -> ::std::result::Result<(), ::aws_smithy_types::error::operation::BuildError> { validate_aws_Pcryptography_PmaterialProviders_HCreateKeyringOutput_Dkeyring(&Some( @@ -1730,7 +1730,7 @@ pub(crate) fn validate_aws_Pcryptography_PmaterialProviders_HCreateKeyringOutput ))?; Ok(()) } -pub(crate) fn validate_aws_Pcryptography_PmaterialProviders_HCreateKeyringOutput_for_AwsCryptographicMaterialProviders_CreateAwsKmsMrkDiscoveryKeyring( +pub(crate) fn validate_aws_Pcryptography_PmaterialProviders_HCreateKeyringOutput_for_AwsCryptographicMaterialProviders_CreateAwsKmsHierarchicalKeyring( input: &crate::deps::aws_cryptography_materialProviders::types::keyring::KeyringRef, ) -> ::std::result::Result<(), ::aws_smithy_types::error::operation::BuildError> { validate_aws_Pcryptography_PmaterialProviders_HCreateKeyringOutput_Dkeyring(&Some( @@ -1738,7 +1738,7 @@ pub(crate) fn validate_aws_Pcryptography_PmaterialProviders_HCreateKeyringOutput ))?; Ok(()) } -pub(crate) fn validate_aws_Pcryptography_PmaterialProviders_HCreateKeyringOutput_for_AwsCryptographicMaterialProviders_CreateRawRsaKeyring( +pub(crate) fn validate_aws_Pcryptography_PmaterialProviders_HCreateKeyringOutput_for_AwsCryptographicMaterialProviders_CreateAwsKmsMrkDiscoveryKeyring( input: &crate::deps::aws_cryptography_materialProviders::types::keyring::KeyringRef, ) -> ::std::result::Result<(), ::aws_smithy_types::error::operation::BuildError> { validate_aws_Pcryptography_PmaterialProviders_HCreateKeyringOutput_Dkeyring(&Some( @@ -1746,7 +1746,7 @@ pub(crate) fn validate_aws_Pcryptography_PmaterialProviders_HCreateKeyringOutput ))?; Ok(()) } -pub(crate) fn validate_aws_Pcryptography_PmaterialProviders_HCreateKeyringOutput_for_AwsCryptographicMaterialProviders_CreateRawEcdhKeyring( +pub(crate) fn validate_aws_Pcryptography_PmaterialProviders_HCreateKeyringOutput_for_AwsCryptographicMaterialProviders_CreateRawAesKeyring( input: &crate::deps::aws_cryptography_materialProviders::types::keyring::KeyringRef, ) -> ::std::result::Result<(), ::aws_smithy_types::error::operation::BuildError> { validate_aws_Pcryptography_PmaterialProviders_HCreateKeyringOutput_Dkeyring(&Some( @@ -1754,7 +1754,7 @@ pub(crate) fn validate_aws_Pcryptography_PmaterialProviders_HCreateKeyringOutput ))?; Ok(()) } -pub(crate) fn validate_aws_Pcryptography_PmaterialProviders_HCreateKeyringOutput_for_AwsCryptographicMaterialProviders_CreateAwsKmsMrkMultiKeyring( +pub(crate) fn validate_aws_Pcryptography_PmaterialProviders_HCreateKeyringOutput_for_AwsCryptographicMaterialProviders_CreateAwsKmsRsaKeyring( input: &crate::deps::aws_cryptography_materialProviders::types::keyring::KeyringRef, ) -> ::std::result::Result<(), ::aws_smithy_types::error::operation::BuildError> { validate_aws_Pcryptography_PmaterialProviders_HCreateKeyringOutput_Dkeyring(&Some( @@ -1770,7 +1770,7 @@ pub(crate) fn validate_aws_Pcryptography_PmaterialProviders_HCreateKeyringOutput ))?; Ok(()) } -pub(crate) fn validate_aws_Pcryptography_PmaterialProviders_HCreateKeyringOutput_for_AwsCryptographicMaterialProviders_CreateAwsKmsDiscoveryMultiKeyring( +pub(crate) fn validate_aws_Pcryptography_PmaterialProviders_HCreateKeyringOutput_for_AwsCryptographicMaterialProviders_CreateAwsKmsDiscoveryKeyring( input: &crate::deps::aws_cryptography_materialProviders::types::keyring::KeyringRef, ) -> ::std::result::Result<(), ::aws_smithy_types::error::operation::BuildError> { validate_aws_Pcryptography_PmaterialProviders_HCreateKeyringOutput_Dkeyring(&Some( @@ -1778,7 +1778,7 @@ pub(crate) fn validate_aws_Pcryptography_PmaterialProviders_HCreateKeyringOutput ))?; Ok(()) } -pub(crate) fn validate_aws_Pcryptography_PmaterialProviders_HCreateKeyringOutput_for_AwsCryptographicMaterialProviders_CreateMultiKeyring( +pub(crate) fn validate_aws_Pcryptography_PmaterialProviders_HCreateKeyringOutput_for_AwsCryptographicMaterialProviders_CreateAwsKmsMrkMultiKeyring( input: &crate::deps::aws_cryptography_materialProviders::types::keyring::KeyringRef, ) -> ::std::result::Result<(), ::aws_smithy_types::error::operation::BuildError> { validate_aws_Pcryptography_PmaterialProviders_HCreateKeyringOutput_Dkeyring(&Some( @@ -1786,7 +1786,7 @@ pub(crate) fn validate_aws_Pcryptography_PmaterialProviders_HCreateKeyringOutput ))?; Ok(()) } -pub(crate) fn validate_aws_Pcryptography_PmaterialProviders_HCreateKeyringOutput_for_AwsCryptographicMaterialProviders_CreateAwsKmsMrkDiscoveryMultiKeyring( +pub(crate) fn validate_aws_Pcryptography_PmaterialProviders_HCreateKeyringOutput_for_AwsCryptographicMaterialProviders_CreateAwsKmsDiscoveryMultiKeyring( input: &crate::deps::aws_cryptography_materialProviders::types::keyring::KeyringRef, ) -> ::std::result::Result<(), ::aws_smithy_types::error::operation::BuildError> { validate_aws_Pcryptography_PmaterialProviders_HCreateKeyringOutput_Dkeyring(&Some( @@ -1794,7 +1794,7 @@ pub(crate) fn validate_aws_Pcryptography_PmaterialProviders_HCreateKeyringOutput ))?; Ok(()) } -pub(crate) fn validate_aws_Pcryptography_PmaterialProviders_HCreateKeyringOutput_for_AwsCryptographicMaterialProviders_CreateAwsKmsDiscoveryKeyring( +pub(crate) fn validate_aws_Pcryptography_PmaterialProviders_HCreateKeyringOutput_for_AwsCryptographicMaterialProviders_CreateAwsKmsEcdhKeyring( input: &crate::deps::aws_cryptography_materialProviders::types::keyring::KeyringRef, ) -> ::std::result::Result<(), ::aws_smithy_types::error::operation::BuildError> { validate_aws_Pcryptography_PmaterialProviders_HCreateKeyringOutput_Dkeyring(&Some( @@ -1802,7 +1802,7 @@ pub(crate) fn validate_aws_Pcryptography_PmaterialProviders_HCreateKeyringOutput ))?; Ok(()) } -pub(crate) fn validate_aws_Pcryptography_PmaterialProviders_HCreateKeyringOutput_for_AwsCryptographicMaterialProviders_CreateAwsKmsRsaKeyring( +pub(crate) fn validate_aws_Pcryptography_PmaterialProviders_HCreateKeyringOutput_for_AwsCryptographicMaterialProviders_CreateAwsKmsMultiKeyring( input: &crate::deps::aws_cryptography_materialProviders::types::keyring::KeyringRef, ) -> ::std::result::Result<(), ::aws_smithy_types::error::operation::BuildError> { validate_aws_Pcryptography_PmaterialProviders_HCreateKeyringOutput_Dkeyring(&Some( @@ -1810,7 +1810,7 @@ pub(crate) fn validate_aws_Pcryptography_PmaterialProviders_HCreateKeyringOutput ))?; Ok(()) } -pub(crate) fn validate_aws_Pcryptography_PmaterialProviders_HCreateKeyringOutput_for_AwsCryptographicMaterialProviders_CreateAwsKmsMultiKeyring( +pub(crate) fn validate_aws_Pcryptography_PmaterialProviders_HCreateKeyringOutput_for_AwsCryptographicMaterialProviders_CreateMultiKeyring( input: &crate::deps::aws_cryptography_materialProviders::types::keyring::KeyringRef, ) -> ::std::result::Result<(), ::aws_smithy_types::error::operation::BuildError> { validate_aws_Pcryptography_PmaterialProviders_HCreateKeyringOutput_Dkeyring(&Some( @@ -1818,7 +1818,7 @@ pub(crate) fn validate_aws_Pcryptography_PmaterialProviders_HCreateKeyringOutput ))?; Ok(()) } -pub(crate) fn validate_aws_Pcryptography_PmaterialProviders_HCreateKeyringOutput_for_AwsCryptographicMaterialProviders_CreateAwsKmsEcdhKeyring( +pub(crate) fn validate_aws_Pcryptography_PmaterialProviders_HCreateKeyringOutput_for_AwsCryptographicMaterialProviders_CreateAwsKmsMrkDiscoveryMultiKeyring( input: &crate::deps::aws_cryptography_materialProviders::types::keyring::KeyringRef, ) -> ::std::result::Result<(), ::aws_smithy_types::error::operation::BuildError> { validate_aws_Pcryptography_PmaterialProviders_HCreateKeyringOutput_Dkeyring(&Some( diff --git a/releases/rust/esdk/src/ecdh.rs b/releases/rust/esdk/src/ecdh.rs index 111542371..ecadb87bb 100644 --- a/releases/rust/esdk/src/ecdh.rs +++ b/releases/rust/esdk/src/ecdh.rs @@ -22,14 +22,14 @@ pub mod ECDH { use crate::software::amazon::cryptography::primitives::internaldafny::types::ECDHCurveSpec; use crate::software::amazon::cryptography::primitives::internaldafny::types::Error as DafnyError; use crate::*; - use aws_lc_sys; + use aws_lc_sys_impl; use dafny_runtime::Rc; fn get_nid(x: &ECDHCurveSpec) -> i32 { match x { - ECDHCurveSpec::ECC_NIST_P256 {} => aws_lc_sys::NID_X9_62_prime256v1, - ECDHCurveSpec::ECC_NIST_P384 {} => aws_lc_sys::NID_secp384r1, - ECDHCurveSpec::ECC_NIST_P521 {} => aws_lc_sys::NID_secp521r1, + ECDHCurveSpec::ECC_NIST_P256 {} => aws_lc_sys_impl::NID_X9_62_prime256v1, + ECDHCurveSpec::ECC_NIST_P384 {} => aws_lc_sys_impl::NID_secp384r1, + ECDHCurveSpec::ECC_NIST_P521 {} => aws_lc_sys_impl::NID_secp521r1, ECDHCurveSpec::SM2 {} => panic!("No SM2 in Rust"), } } @@ -45,29 +45,29 @@ pub mod ECDH { } } - use aws_lc_sys::CBB_finish; - use aws_lc_sys::CBB_init; - use aws_lc_sys::EC_GROUP_get_curve_name; - use aws_lc_sys::EC_GROUP_new_by_curve_name; - use aws_lc_sys::EC_KEY_get0_group; - use aws_lc_sys::EC_KEY_get0_public_key; - use aws_lc_sys::EC_KEY_new_by_curve_name; - use aws_lc_sys::EC_KEY_set_public_key; - use aws_lc_sys::EC_POINT_free; - use aws_lc_sys::EC_POINT_new; - use aws_lc_sys::EC_POINT_oct2point; - use aws_lc_sys::EC_POINT_point2oct; - use aws_lc_sys::EVP_PKEY_assign_EC_KEY; - use aws_lc_sys::EVP_PKEY_free; - use aws_lc_sys::EVP_PKEY_get0_EC_KEY; - use aws_lc_sys::EVP_PKEY_new; - use aws_lc_sys::EVP_PKEY_size; - use aws_lc_sys::EVP_marshal_public_key; - use aws_lc_sys::EVP_parse_public_key; - use aws_lc_sys::OPENSSL_free; - use aws_lc_sys::CBB; - use aws_lc_sys::CBS; - use aws_lc_sys::EVP_PKEY_EC; + use aws_lc_sys_impl::CBB_finish; + use aws_lc_sys_impl::CBB_init; + use aws_lc_sys_impl::EC_GROUP_get_curve_name; + use aws_lc_sys_impl::EC_GROUP_new_by_curve_name; + use aws_lc_sys_impl::EC_KEY_get0_group; + use aws_lc_sys_impl::EC_KEY_get0_public_key; + use aws_lc_sys_impl::EC_KEY_new_by_curve_name; + use aws_lc_sys_impl::EC_KEY_set_public_key; + use aws_lc_sys_impl::EC_POINT_free; + use aws_lc_sys_impl::EC_POINT_new; + use aws_lc_sys_impl::EC_POINT_oct2point; + use aws_lc_sys_impl::EC_POINT_point2oct; + use aws_lc_sys_impl::EVP_PKEY_assign_EC_KEY; + use aws_lc_sys_impl::EVP_PKEY_free; + use aws_lc_sys_impl::EVP_PKEY_get0_EC_KEY; + use aws_lc_sys_impl::EVP_PKEY_new; + use aws_lc_sys_impl::EVP_PKEY_size; + use aws_lc_sys_impl::EVP_marshal_public_key; + use aws_lc_sys_impl::EVP_parse_public_key; + use aws_lc_sys_impl::OPENSSL_free; + use aws_lc_sys_impl::CBB; + use aws_lc_sys_impl::CBS; + use aws_lc_sys_impl::EVP_PKEY_EC; use std::ptr::null_mut; const ELEM_MAX_BITS: usize = 521; @@ -106,9 +106,9 @@ pub mod ECDH { } let comp = if compress { - aws_lc_sys::point_conversion_form_t::POINT_CONVERSION_COMPRESSED + aws_lc_sys_impl::point_conversion_form_t::POINT_CONVERSION_COMPRESSED } else { - aws_lc_sys::point_conversion_form_t::POINT_CONVERSION_UNCOMPRESSED + aws_lc_sys_impl::point_conversion_form_t::POINT_CONVERSION_UNCOMPRESSED }; let mut out_buf = [0u8; PUBLIC_KEY_MAX_LEN]; @@ -184,7 +184,7 @@ pub mod ECDH { ) -> Result, String> { let mut out = null_mut(); let evp_pkey = unsafe { - aws_lc_sys::d2i_PrivateKey( + aws_lc_sys_impl::d2i_PrivateKey( EVP_PKEY_EC, &mut out, &mut key_bytes.as_ptr(), @@ -234,8 +234,8 @@ pub mod ECDH { Ok(slice) } fn get_public_key(alg: &ECDHCurveSpec, pem: &[u8]) -> Result, String> { - let pem = std::str::from_utf8(pem).map_err(|e| format!("{:?}", e))?; - let private_key = pem::parse(pem).map_err(|e| format!("{:?}", e))?; + let pem = std::str::from_utf8(pem).map_err(|e| format!("{e:?}"))?; + let private_key = pem::parse(pem).map_err(|e| format!("{e:?}"))?; inner_get_public_key(private_key.contents(), get_nid(alg)) } @@ -319,7 +319,7 @@ pub mod ECDH { value: dafny_runtime::Sequence::from_array_owned(x), }), Err(e) => { - let msg = format!("ECDH Get Public Key : {}", e); + let msg = format!("ECDH Get Public Key : {e}"); Rc::new(_Wrappers_Compile::Result::Failure { error: super::error(&msg), }) @@ -340,7 +340,7 @@ pub mod ECDH { } let ec_key = unsafe { EVP_PKEY_get0_EC_KEY(evp_pkey) }; - if unsafe { aws_lc_sys::EC_KEY_check_fips(ec_key) } != 1 { + if unsafe { aws_lc_sys_impl::EC_KEY_check_fips(ec_key) } != 1 { return Err(INVALID_KEY.to_string()); } let ec_group = unsafe { EC_KEY_get0_group(ec_key) }; @@ -378,7 +378,7 @@ pub mod ECDH { value: dafny_runtime::Sequence::from_array_owned(v), }), Err(e) => { - let msg = format!("ECDH Compress Public Key {}", e); + let msg = format!("ECDH Compress Public Key {e}"); Rc::new(_Wrappers_Compile::Result::Failure { error: super::error(&msg), }) @@ -396,7 +396,7 @@ pub mod ECDH { value: dafny_runtime::Sequence::from_array_owned(v), }), Err(e) => { - let msg = format!("ECDH Decompress Public Key {}", e); + let msg = format!("ECDH Decompress Public Key {e}"); Rc::new(_Wrappers_Compile::Result::Failure { error: super::error(&msg), }) @@ -429,13 +429,13 @@ pub mod ECDH { private_key_pem: &[u8], public_key_der: &[u8], ) -> Result, String> { - let pem = std::str::from_utf8(private_key_pem).map_err(|e| format!("{:?}", e))?; - let private_key = pem::parse(pem).map_err(|e| format!("{:?}", e))?; + let pem = std::str::from_utf8(private_key_pem).map_err(|e| format!("{e:?}"))?; + let private_key = pem::parse(pem).map_err(|e| format!("{e:?}"))?; let private_key = aws_lc_rs::agreement::PrivateKey::from_private_key_der( super::ECCUtils::get_alg(curve_algorithm), private_key.contents(), ) - .map_err(|e| format!("{:?}", e))?; + .map_err(|e| format!("{e:?}"))?; let public_key = super::ECCUtils::X509_to_X962(public_key_der, false, None)?; let public_key = aws_lc_rs::agreement::UnparsedPublicKey::new( super::ECCUtils::get_alg(curve_algorithm), @@ -458,7 +458,7 @@ pub mod ECDH { value: dafny_runtime::Sequence::from_array_owned(v), }), Err(e) => { - let msg = format!("ECDH Calculate Shared Secret : {}", e); + let msg = format!("ECDH Calculate Shared Secret : {e}"); Rc::new(_Wrappers_Compile::Result::Failure { error: super::error(&msg), }) @@ -477,16 +477,16 @@ pub mod ECDH { fn ecdsa_key_gen(alg: &ECDHCurveSpec) -> Result<(Vec, Vec), String> { let private_key = aws_lc_rs::agreement::PrivateKey::generate(super::ECCUtils::get_alg(alg)) - .map_err(|e| format!("{:?}", e))?; + .map_err(|e| format!("{e:?}"))?; let public_key = private_key .compute_public_key() - .map_err(|e| format!("{:?}", e))?; + .map_err(|e| format!("{e:?}"))?; let public_key: Vec = super::ECCUtils::X962_to_X509(public_key.as_ref(), alg)?; let private_key_der = AsDer::::as_der(&private_key) - .map_err(|e| format!("{:?}", e))?; + .map_err(|e| format!("{e:?}"))?; let private_key = pem::Pem::new("PRIVATE KEY", private_key_der.as_ref()); let private_key = pem::encode(&private_key); let private_key: Vec = private_key.into_bytes(); @@ -505,7 +505,7 @@ pub mod ECDH { }), }), Err(e) => { - let msg = format!("ECDH Generate Key Pair : {}", e); + let msg = format!("ECDH Generate Key Pair : {e}"); Rc::new(_Wrappers_Compile::Result::Failure { error: super::error(&msg), }) @@ -526,12 +526,12 @@ pub mod ECDH { let pair: crate::ECDH::EccKeyPair = match &*KeyGeneration::GenerateKeyPair(&alg) { _Wrappers_Compile::Result::Success { value } => (**value).clone(), - _Wrappers_Compile::Result::Failure { error } => panic!("{:?}", error), + _Wrappers_Compile::Result::Failure { error } => panic!("{error:?}"), }; match &*ECCUtils::ValidatePublicKey(&alg, pair.publicKey()) { _Wrappers_Compile::Result::Success { .. } => {} - _Wrappers_Compile::Result::Failure { error } => panic!("{:?}", error), + _Wrappers_Compile::Result::Failure { error } => panic!("{error:?}"), }; } } diff --git a/releases/rust/esdk/src/ecdsa.rs b/releases/rust/esdk/src/ecdsa.rs index f7b992333..b03470608 100644 --- a/releases/rust/esdk/src/ecdsa.rs +++ b/releases/rust/esdk/src/ecdsa.rs @@ -55,8 +55,8 @@ pub mod Signature { fn get_nid(x: &ECDSASignatureAlgorithm) -> i32 { match x { - ECDSASignatureAlgorithm::ECDSA_P256 {} => aws_lc_sys::NID_X9_62_prime256v1, - ECDSASignatureAlgorithm::ECDSA_P384 {} => aws_lc_sys::NID_secp384r1, + ECDSASignatureAlgorithm::ECDSA_P256 {} => aws_lc_sys_impl::NID_X9_62_prime256v1, + ECDSASignatureAlgorithm::ECDSA_P384 {} => aws_lc_sys_impl::NID_secp384r1, } } @@ -71,20 +71,20 @@ pub mod Signature { sec1_convert( data, get_nid(alg), - aws_lc_sys::point_conversion_form_t::POINT_CONVERSION_COMPRESSED, + aws_lc_sys_impl::point_conversion_form_t::POINT_CONVERSION_COMPRESSED, ) } pub(crate) fn sec1_convert( data: &[u8], nid: i32, - form: aws_lc_sys::point_conversion_form_t, + form: aws_lc_sys_impl::point_conversion_form_t, ) -> Result, String> { - use aws_lc_sys::EC_GROUP_new_by_curve_name; - use aws_lc_sys::EC_POINT_free; - use aws_lc_sys::EC_POINT_new; - use aws_lc_sys::EC_POINT_oct2point; - use aws_lc_sys::EC_POINT_point2oct; + use aws_lc_sys_impl::EC_GROUP_new_by_curve_name; + use aws_lc_sys_impl::EC_POINT_free; + use aws_lc_sys_impl::EC_POINT_new; + use aws_lc_sys_impl::EC_POINT_oct2point; + use aws_lc_sys_impl::EC_POINT_point2oct; use std::ptr::null_mut; // no need to free ec_group @@ -120,7 +120,7 @@ pub mod Signature { } fn ecdsa_key_gen(alg: &ECDSASignatureAlgorithm) -> Result<(Vec, Vec), String> { - let pair = EcdsaKeyPair::generate(get_alg(alg)).map_err(|e| format!("{:?}", e))?; + let pair = EcdsaKeyPair::generate(get_alg(alg)).map_err(|e| format!("{e:?}"))?; let public_key: Vec = sec1_compress(pair.public_key().as_ref(), alg)?; let private_key: Vec = pair.private_key().as_der().unwrap().as_ref().to_vec(); @@ -139,7 +139,7 @@ pub mod Signature { }), }), Err(e) => { - let msg = format!("ECDSA Key Gen : {}", e); + let msg = format!("ECDSA Key Gen : {e}"); Rc::new(_Wrappers_Compile::Result::Failure { error: error(&msg) }) } } @@ -151,11 +151,9 @@ pub mod Signature { msg: &[u8], ) -> Result, String> { let private_key = EcdsaKeyPair::from_private_key_der(get_alg(alg), key) - .map_err(|e| format!("{:?}", e))?; + .map_err(|e| format!("{e:?}"))?; let rng = SystemRandom::new(); - let sig = private_key - .sign(&rng, msg) - .map_err(|e| format!("{:?}", e))?; + let sig = private_key.sign(&rng, msg).map_err(|e| format!("{e:?}"))?; Ok(sig.as_ref().to_vec()) } fn ecdsa_sign( @@ -189,7 +187,7 @@ pub mod Signature { value: dafny_runtime::Sequence::from_array_owned(x), }), Err(e) => { - let msg = format!("ECDSA Sign : {}", e); + let msg = format!("ECDSA Sign : {e}"); Rc::new(_Wrappers_Compile::Result::Failure { error: error(&msg) }) } } @@ -220,7 +218,7 @@ pub mod Signature { match ecdsa_verify(alg, key, msg, sig) { Ok(x) => Rc::new(_Wrappers_Compile::Result::Success { value: x }), Err(e) => { - let msg = format!("ECDSA Verify : {}", e); + let msg = format!("ECDSA Verify : {e}"); Rc::new(_Wrappers_Compile::Result::Failure { error: error(&msg) }) } } @@ -236,7 +234,7 @@ pub mod Signature { let key_pair = match &*ExternKeyGen(&alg) { _Wrappers_Compile::Result::Success { value } => value.clone(), _Wrappers_Compile::Result::Failure { error } => { - panic!("ExternKeyGen Failed : {:?}", error); + panic!("ExternKeyGen Failed : {error:?}"); } }; @@ -250,17 +248,17 @@ pub mod Signature { let message: ::dafny_runtime::Sequence = dafny_runtime::Sequence::from_array_owned(vec![1u8, 2, 3, 4, 5]); - let sig = match &*Sign(&alg, &s_key, &message) { + let sig = match &*Sign(&alg, s_key, &message) { _Wrappers_Compile::Result::Success { value } => value.clone(), _Wrappers_Compile::Result::Failure { error } => { - panic!("Sign Failed : {:?}", error); + panic!("Sign Failed : {error:?}"); } }; - let ver: bool = match &*Verify(&alg, &v_key, &message, &sig) { - _Wrappers_Compile::Result::Success { value } => value.clone(), + let ver: bool = match &*Verify(&alg, v_key, &message, &sig) { + _Wrappers_Compile::Result::Success { value } => *value, _Wrappers_Compile::Result::Failure { error } => { - panic!("Verify Failed : {:?}", error); + panic!("Verify Failed : {error:?}"); } }; assert!(ver); @@ -269,10 +267,10 @@ pub mod Signature { sig_vec[0] = 42; let sig2: ::dafny_runtime::Sequence = sig_vec.iter().cloned().collect(); assert!(sig != sig2); - let ver2: bool = match &*Verify(&alg, &v_key, &message, &sig2) { - _Wrappers_Compile::Result::Success { value } => value.clone(), + let ver2: bool = match &*Verify(&alg, v_key, &message, &sig2) { + _Wrappers_Compile::Result::Success { value } => *value, _Wrappers_Compile::Result::Failure { error } => { - panic!("Verify Failed : {:?}", error); + panic!("Verify Failed : {error:?}"); } }; assert!(!ver2); diff --git a/releases/rust/esdk/src/implementation_from_dafny.rs b/releases/rust/esdk/src/implementation_from_dafny.rs index 4016c05ba..217d27f48 100644 --- a/releases/rust/esdk/src/implementation_from_dafny.rs +++ b/releases/rust/esdk/src/implementation_from_dafny.rs @@ -43767,7 +43767,7 @@ pub mod software { } /// ../mpl/ComAmazonawsKms/src/Index.dfy(31,3) pub fn DafnyUserAgentSuffix(runtime: &Sequence) -> Sequence { - let mut version: Sequence = string_utf16_of("1.0.1"); + let mut version: Sequence = string_utf16_of("1.11.0"); string_utf16_of("AwsCryptographicMPL/").concat(runtime).concat(&string_utf16_of("/")).concat(&version) } /// ../mpl/ComAmazonawsKms/Model/ComAmazonawsKmsTypes.dfy(2006,3) @@ -88695,7 +88695,7 @@ pub mod _LocalCMC_Compile { pub struct _default {} impl _default { - /// ../mpl/AwsCryptographicMaterialProviders/dafny/AwsCryptographicMaterialProviders/src/CMCs/LocalCMC.dfy(301,3) + /// ../mpl/AwsCryptographicMaterialProviders/dafny/AwsCryptographicMaterialProviders/src/CMCs/LocalCMC.dfy(313,3) pub fn RemoveValue<_K: DafnyTypeEq, _V: DafnyTypeEq>(k0: &_K, m: &Map<_K, _V>) -> () { let mut _m_k: Map<_K, _V> = m.subtract(&set!{k0.clone()}); return (); @@ -88862,7 +88862,7 @@ pub mod _LocalCMC_Compile { pub fn _allocate_object() -> Object { allocate_object::() } - /// ../mpl/AwsCryptographicMaterialProviders/dafny/AwsCryptographicMaterialProviders/src/CMCs/LocalCMC.dfy(161,5) + /// ../mpl/AwsCryptographicMaterialProviders/dafny/AwsCryptographicMaterialProviders/src/CMCs/LocalCMC.dfy(166,5) pub fn _ctor(this: &Object) -> () { let mut _set_head: bool = false; let mut _set_tail: bool = false; @@ -88870,7 +88870,7 @@ pub mod _LocalCMC_Compile { update_field_mut_uninit_object!(this.clone(), tail, _set_tail, Arc::new(Ref::>::Null {})); return (); } - /// ../mpl/AwsCryptographicMaterialProviders/dafny/AwsCryptographicMaterialProviders/src/CMCs/LocalCMC.dfy(173,5) + /// ../mpl/AwsCryptographicMaterialProviders/dafny/AwsCryptographicMaterialProviders/src/CMCs/LocalCMC.dfy(178,5) pub fn pushCell(&self, toPush: &Object) -> () { let mut cRef: Arc>> = Arc::new(Ref::>::Ptr { deref: toPush.clone() @@ -88886,7 +88886,7 @@ pub mod _LocalCMC_Compile { }; return (); } - /// ../mpl/AwsCryptographicMaterialProviders/dafny/AwsCryptographicMaterialProviders/src/CMCs/LocalCMC.dfy(193,5) + /// ../mpl/AwsCryptographicMaterialProviders/dafny/AwsCryptographicMaterialProviders/src/CMCs/LocalCMC.dfy(198,5) pub fn moveToFront(&self, c: &Object) -> () { if read_field!(self.head).deref().clone() != c.clone() { let mut toPush: Arc>> = Arc::new(Ref::>::Ptr { @@ -88906,7 +88906,7 @@ pub mod _LocalCMC_Compile { }; return (); } - /// ../mpl/AwsCryptographicMaterialProviders/dafny/AwsCryptographicMaterialProviders/src/CMCs/LocalCMC.dfy(222,5) + /// ../mpl/AwsCryptographicMaterialProviders/dafny/AwsCryptographicMaterialProviders/src/CMCs/LocalCMC.dfy(230,5) pub fn remove(&self, toRemove: &Object) -> () { if matches!((&read_field!(rd!(toRemove.clone()).prev)).as_ref(), Null{ .. }) { modify_field!(self.head, read_field!(rd!(toRemove.clone()).next)) @@ -88934,7 +88934,7 @@ pub mod _LocalCMC_Compile { UpcastObjectFn!(DynAny); } - /// ../mpl/AwsCryptographicMaterialProviders/dafny/AwsCryptographicMaterialProviders/src/CMCs/LocalCMC.dfy(316,3) + /// ../mpl/AwsCryptographicMaterialProviders/dafny/AwsCryptographicMaterialProviders/src/CMCs/LocalCMC.dfy(328,3) pub struct LocalCMC { pub queue: ::dafny_runtime::Field>, pub cache: ::dafny_runtime::Field, Object>>>, @@ -88947,7 +88947,7 @@ pub mod _LocalCMC_Compile { pub fn _allocate_object() -> Object { allocate_object::() } - /// ../mpl/AwsCryptographicMaterialProviders/dafny/AwsCryptographicMaterialProviders/src/CMCs/LocalCMC.dfy(382,5) + /// ../mpl/AwsCryptographicMaterialProviders/dafny/AwsCryptographicMaterialProviders/src/CMCs/LocalCMC.dfy(394,5) pub fn _ctor(this: &Object, _entryCapacity_k: u64, _entryPruningTailSize_k: u64) -> () { let mut _set_queue: bool = false; let mut _set_cache: bool = false; @@ -88955,14 +88955,14 @@ pub mod _LocalCMC_Compile { let mut _set___i_entryPruningTailSize: bool = false; update_field_uninit_object!(this.clone(), __i_entryCapacity, _set___i_entryCapacity, _entryCapacity_k); update_field_uninit_object!(this.clone(), __i_entryPruningTailSize, _set___i_entryPruningTailSize, _entryPruningTailSize_k); - let mut _nw0: Object, Object>> = MutableMap::, Object>::_allocate_object(); + let mut _nw0: Object, Object>> = MutableMap::, Object>::_allocate_object(true); update_field_mut_uninit_object!(this.clone(), cache, _set_cache, _nw0.clone()); let mut _nw1: Object = DoublyLinkedCacheEntryList::_allocate_object(); DoublyLinkedCacheEntryList::_ctor(&_nw1); update_field_mut_uninit_object!(this.clone(), queue, _set_queue, _nw1.clone()); return (); } - /// ../mpl/AwsCryptographicMaterialProviders/dafny/AwsCryptographicMaterialProviders/src/CMCs/LocalCMC.dfy(424,5) + /// ../mpl/AwsCryptographicMaterialProviders/dafny/AwsCryptographicMaterialProviders/src/CMCs/LocalCMC.dfy(435,5) pub fn GetCacheEntryWithTime(&self, input: &Arc, now: PositiveLong) -> Arc, Arc>> { let mut output = MaybePlacebo::, Arc>>>::new(); if MutableMapTrait::, Object>::HasKey(rd!(read_field!(self.cache)), input.identifier()) { @@ -89012,7 +89012,7 @@ pub mod _LocalCMC_Compile { }; return output.read(); } - /// ../mpl/AwsCryptographicMaterialProviders/dafny/AwsCryptographicMaterialProviders/src/CMCs/LocalCMC.dfy(654,5) + /// ../mpl/AwsCryptographicMaterialProviders/dafny/AwsCryptographicMaterialProviders/src/CMCs/LocalCMC.dfy(684,5) pub fn pruning(&self, now: PositiveLong) -> Arc>> { let mut output = MaybePlacebo::>>>::new(); let mut _hi0: u64 = self.entryPruningTailSize().clone(); @@ -89047,11 +89047,11 @@ pub mod _LocalCMC_Compile { })); return output.read(); } - /// ../mpl/AwsCryptographicMaterialProviders/dafny/AwsCryptographicMaterialProviders/src/CMCs/LocalCMC.dfy(364,5) + /// ../mpl/AwsCryptographicMaterialProviders/dafny/AwsCryptographicMaterialProviders/src/CMCs/LocalCMC.dfy(376,5) pub fn entryCapacity(&self) -> u64 { self.__i_entryCapacity.clone() } - /// ../mpl/AwsCryptographicMaterialProviders/dafny/AwsCryptographicMaterialProviders/src/CMCs/LocalCMC.dfy(371,5) + /// ../mpl/AwsCryptographicMaterialProviders/dafny/AwsCryptographicMaterialProviders/src/CMCs/LocalCMC.dfy(383,5) pub fn entryPruningTailSize(&self) -> u64 { self.__i_entryPruningTailSize.clone() } @@ -89064,7 +89064,7 @@ pub mod _LocalCMC_Compile { impl ICryptographicMaterialsCache for LocalCMC { - /// ../mpl/AwsCryptographicMaterialProviders/dafny/AwsCryptographicMaterialProviders/src/CMCs/LocalCMC.dfy(410,5) + /// ../mpl/AwsCryptographicMaterialProviders/dafny/AwsCryptographicMaterialProviders/src/CMCs/LocalCMC.dfy(421,5) fn _GetCacheEntry_k(&self, input: &Arc) -> Arc, Arc>> { let mut output: Arc, Arc>>; let mut now: i64; @@ -89074,7 +89074,7 @@ pub mod _LocalCMC_Compile { output = _out1.clone(); return output.clone(); } - /// ../mpl/AwsCryptographicMaterialProviders/dafny/AwsCryptographicMaterialProviders/src/CMCs/LocalCMC.dfy(477,5) + /// ../mpl/AwsCryptographicMaterialProviders/dafny/AwsCryptographicMaterialProviders/src/CMCs/LocalCMC.dfy(488,5) fn _PutCacheEntry_k(&self, input: &Arc) -> Arc>> { let mut output = MaybePlacebo::>>>::new(); if self.entryCapacity().clone() == 0 { @@ -89118,7 +89118,7 @@ pub mod _LocalCMC_Compile { })); return output.read(); } - /// ../mpl/AwsCryptographicMaterialProviders/dafny/AwsCryptographicMaterialProviders/src/CMCs/LocalCMC.dfy(568,5) + /// ../mpl/AwsCryptographicMaterialProviders/dafny/AwsCryptographicMaterialProviders/src/CMCs/LocalCMC.dfy(598,5) fn _DeleteCacheEntry_k(&self, input: &Arc) -> Arc>> { let mut output: Arc>>; if MutableMapTrait::, Object>::HasKey(rd!(read_field!(self.cache)), input.identifier()) { @@ -89134,7 +89134,7 @@ pub mod _LocalCMC_Compile { }); return output.clone(); } - /// ../mpl/AwsCryptographicMaterialProviders/dafny/AwsCryptographicMaterialProviders/src/CMCs/LocalCMC.dfy(618,5) + /// ../mpl/AwsCryptographicMaterialProviders/dafny/AwsCryptographicMaterialProviders/src/CMCs/LocalCMC.dfy(648,5) fn _UpdateUsageMetadata_k(&self, input: &Arc) -> Arc>> { let mut output = MaybePlacebo::>>>::new(); if MutableMapTrait::, Object>::HasKey(rd!(read_field!(self.cache)), input.identifier()) { @@ -96473,18 +96473,21 @@ pub mod _StandardLibrary_Compile { pub use ::dafny_runtime::euclidian_division; pub use ::dafny_runtime::DafnyCharUTF16; pub use ::dafny_runtime::string_utf16_of; + pub use ::dafny_runtime::DafnyTypeEq; pub use ::std::sync::Arc; pub use crate::implementation_from_dafny::_Wrappers_Compile::Option; - pub use ::dafny_runtime::_System::nat; - pub use ::dafny_runtime::MaybePlacebo; pub use ::dafny_runtime::truncate; + pub use ::std::default::Default; + pub use crate::implementation_from_dafny::_Wrappers_Compile::Option::None; + pub use ::dafny_runtime::MaybePlacebo; + pub use ::dafny_runtime::_System::nat; pub use ::dafny_runtime::integer_range; pub use ::std::convert::Into; pub struct _default {} impl _default { - /// ../mpl/StandardLibrary/src/String.dfy(14,3) + /// ../mpl/StandardLibrary/src/String.dfy(17,3) pub fn Int2Digits(n: &DafnyInt, base: &DafnyInt) -> Sequence { let mut _accumulator: Sequence = seq![] as Sequence; let mut _r0 = n.clone(); @@ -96504,7 +96507,7 @@ pub mod _StandardLibrary_Compile { } } } - /// ../mpl/StandardLibrary/src/String.dfy(30,3) + /// ../mpl/StandardLibrary/src/String.dfy(33,3) pub fn Digits2String(digits: &Sequence, chars: &Sequence) -> Sequence { let mut _accumulator: Sequence = seq![] as Sequence; let mut _r0 = digits.clone(); @@ -96524,7 +96527,7 @@ pub mod _StandardLibrary_Compile { } } } - /// ../mpl/StandardLibrary/src/String.dfy(40,3) + /// ../mpl/StandardLibrary/src/String.dfy(43,3) pub fn Int2String(n: &DafnyInt, chars: &Sequence) -> Sequence { let mut base: DafnyInt = chars.cardinality(); if n.clone() == int!(0) { @@ -96537,25 +96540,177 @@ pub mod _StandardLibrary_Compile { } } } - /// ../mpl/StandardLibrary/src/String.dfy(52,3) + /// ../mpl/StandardLibrary/src/String.dfy(55,3) pub fn Base10Int2String(n: &DafnyInt) -> Sequence { crate::implementation_from_dafny::_StandardLibrary_Compile::_String_Compile::_default::Int2String(n, &crate::implementation_from_dafny::_StandardLibrary_Compile::_String_Compile::_default::Base10()) } - /// ../mpl/StandardLibrary/src/String.dfy(58,3) - pub fn HasSubString(haystack: &Sequence, needle: &Sequence) -> Arc> { + /// ../mpl/StandardLibrary/src/String.dfy(62,3) + pub fn SearchAndReplace<_T: DafnyTypeEq>(source: &Sequence<_T>, old_str: &Sequence<_T>, new_str: &Sequence<_T>) -> Sequence<_T> { + let mut o: Sequence<_T>; + let mut x: (Sequence<_T>, Arc>); + let mut _out0: (Sequence<_T>, Arc>); + _out0 = crate::implementation_from_dafny::_StandardLibrary_Compile::_String_Compile::_default::SearchAndReplacePos::<_T>(source, old_str, new_str, truncate!(int!(0), u64)); + x = _out0.clone(); + o = x.0.clone(); + return o.clone(); + } + /// ../mpl/StandardLibrary/src/String.dfy(73,3) + pub fn SearchAndReplacePos<_T: DafnyTypeEq>(source: &Sequence<_T>, old_str: &Sequence<_T>, new_str: &Sequence<_T>, pos: u64) -> (Sequence<_T>, Arc>) { + let mut o: (Sequence<_T>, Arc>) = ( + as Default>::default(), + > as Default>::default() + ); + let mut old_pos: Arc>; + let mut _out0: Arc>; + _out0 = crate::implementation_from_dafny::_StandardLibrary_Compile::_String_Compile::_default::HasSubStringPos::<_T>(source, old_str, pos); + old_pos = _out0.clone(); + if matches!((&old_pos).as_ref(), None{ .. }) { + o = ( + source.clone(), + Arc::new(Option::::None {}) + ); + return o.clone(); + } else { + let mut source_len: u64 = truncate!(source.cardinality(), u64); + let mut old_str_len: u64 = truncate!(old_str.cardinality(), u64); + let mut new_str_len: u64 = truncate!(new_str.cardinality(), u64); + o = ( + source.take(&int!(old_pos.value().clone())).concat(new_str).concat(&source.drop(&int!((&(old_pos.value().clone() + old_str_len)).clone()))), + Arc::new(Option::::Some { + value: crate::implementation_from_dafny::_StandardLibrary_Compile::_MemoryMath_Compile::_default::Add(old_pos.value().clone(), new_str_len) + }) + ); + o = o.clone(); + return o.clone(); + }; + return o.clone(); + } + /// ../mpl/StandardLibrary/src/String.dfy(96,3) + pub fn BadStart<_T: DafnyTypeEq>(source: &Sequence<_T>, pos: u64, chars: &Sequence<_T>) -> bool { + if pos == truncate!(int!(0), u64) { + false + } else { + chars.contains(&source.get(&int!((&(pos - truncate!(int!(1), u64))).clone()))) + } + } + /// ../mpl/StandardLibrary/src/String.dfy(105,3) + pub fn BadEnd<_T: DafnyTypeEq>(source: &Sequence<_T>, pos: u64, match_len: u64, chars: &Sequence<_T>) -> bool { + let mut source_len: u64 = truncate!(source.cardinality(), u64); + if !(crate::implementation_from_dafny::_StandardLibrary_Compile::_MemoryMath_Compile::_default::Add(pos, match_len) < source_len) { + false + } else { + chars.contains(&source.get(&int!((&(pos + match_len)).clone()))) + } + } + /// ../mpl/StandardLibrary/src/String.dfy(114,3) + pub fn BadMatch<_T: DafnyTypeEq>(source: &Sequence<_T>, pos: u64, match_len: u64, chars: &Sequence<_T>) -> bool { + crate::implementation_from_dafny::_StandardLibrary_Compile::_String_Compile::_default::BadStart::<_T>(source, pos, chars) || crate::implementation_from_dafny::_StandardLibrary_Compile::_String_Compile::_default::BadEnd::<_T>(source, pos, match_len, chars) + } + /// ../mpl/StandardLibrary/src/String.dfy(127,3) + pub fn SearchAndReplacePosWhole<_T: DafnyTypeEq>(source: &Sequence<_T>, old_str: &Sequence<_T>, new_str: &Sequence<_T>, xpos: u64, chars: &Sequence<_T>) -> (Sequence<_T>, Arc>) { + let mut o: (Sequence<_T>, Arc>) = ( + as Default>::default(), + > as Default>::default() + ); + let mut old_str_len: u64 = truncate!(old_str.cardinality(), u64); + let mut pos: u64 = xpos; + while pos < truncate!(source.cardinality(), u64) { + let mut old_pos: Arc>; + let mut _out0: Arc>; + _out0 = crate::implementation_from_dafny::_StandardLibrary_Compile::_String_Compile::_default::HasSubStringPos::<_T>(source, old_str, pos); + old_pos = _out0.clone(); + if matches!((&old_pos).as_ref(), None{ .. }) { + o = ( + source.clone(), + Arc::new(Option::::None {}) + ); + return o.clone(); + } else { + if crate::implementation_from_dafny::_StandardLibrary_Compile::_String_Compile::_default::BadMatch::<_T>(source, old_pos.value().clone(), old_str_len, chars) { + pos = old_pos.value().clone() + truncate!(int!(1), u64); + } else { + let mut source_len: u64 = truncate!(source.cardinality(), u64); + let mut new_str_len: u64 = truncate!(new_str.cardinality(), u64); + o = ( + source.take(&int!(old_pos.value().clone())).concat(new_str).concat(&source.drop(&int!((&(old_pos.value().clone() + old_str_len)).clone()))), + Arc::new(Option::::Some { + value: crate::implementation_from_dafny::_StandardLibrary_Compile::_MemoryMath_Compile::_default::Add(old_pos.value().clone(), new_str_len) + }) + ); + o = o.clone(); + return o.clone(); + } + } + }; + o = ( + source.clone(), + Arc::new(Option::::None {}) + ); + return o.clone(); + } + /// ../mpl/StandardLibrary/src/String.dfy(162,3) + pub fn SearchAndReplaceWhole<_T: DafnyTypeEq>(source: &Sequence<_T>, old_str: &Sequence<_T>, new_str: &Sequence<_T>, chars: &Sequence<_T>) -> (Sequence<_T>, Arc>) { + let mut o: (Sequence<_T>, Arc>) = ( + as Default>::default(), + > as Default>::default() + ); + let mut _out0: (Sequence<_T>, Arc>); + _out0 = crate::implementation_from_dafny::_StandardLibrary_Compile::_String_Compile::_default::SearchAndReplacePosWhole::<_T>(source, old_str, new_str, truncate!(int!(0), u64), chars); + o = _out0.clone(); + return o.clone(); + } + /// ../mpl/StandardLibrary/src/String.dfy(174,3) + pub fn SearchAndReplaceAll<_T: DafnyTypeEq>(source_in: &Sequence<_T>, old_str: &Sequence<_T>, new_str: &Sequence<_T>) -> Sequence<_T> { + let mut o = MaybePlacebo::>::new(); + let mut pos: u64 = truncate!(int!(0), u64); + let mut source: Sequence<_T> = source_in.clone(); + while true { + let mut res: (Sequence<_T>, Arc>); + let mut _out0: (Sequence<_T>, Arc>); + _out0 = crate::implementation_from_dafny::_StandardLibrary_Compile::_String_Compile::_default::SearchAndReplacePos::<_T>(&source, old_str, new_str, pos); + res = _out0.clone(); + if matches!((&res.1.clone()).as_ref(), None{ .. }) { + pos = truncate!(source.cardinality(), u64); + o = MaybePlacebo::from(res.0.clone()); + return o.read(); + }; + source = res.0.clone(); + pos = res.1.clone().value().clone(); + }; + return o.read(); + } + /// ../mpl/StandardLibrary/src/String.dfy(199,3) + pub fn SearchAndReplaceAllWhole<_T: DafnyTypeEq>(source_in: &Sequence<_T>, old_str: &Sequence<_T>, new_str: &Sequence<_T>, chars: &Sequence<_T>) -> Sequence<_T> { + let mut o = MaybePlacebo::>::new(); + let mut pos: u64 = truncate!(int!(0), u64); + let mut source: Sequence<_T> = source_in.clone(); + while true { + let mut res: (Sequence<_T>, Arc>); + let mut _out0: (Sequence<_T>, Arc>); + _out0 = crate::implementation_from_dafny::_StandardLibrary_Compile::_String_Compile::_default::SearchAndReplacePosWhole::<_T>(&source, old_str, new_str, pos, chars); + res = _out0.clone(); + if matches!((&res.1.clone()).as_ref(), None{ .. }) { + pos = truncate!(source.cardinality(), u64); + o = MaybePlacebo::from(res.0.clone()); + return o.read(); + }; + source = res.0.clone(); + pos = res.1.clone().value().clone(); + }; + return o.read(); + } + /// ../mpl/StandardLibrary/src/String.dfy(222,3) + pub fn HasSubString<_T: DafnyTypeEq>(haystack: &Sequence<_T>, needle: &Sequence<_T>) -> Arc> { let mut o = MaybePlacebo::>>::new(); - if haystack.cardinality() < needle.cardinality() { + if truncate!(haystack.cardinality(), u64) < truncate!(needle.cardinality(), u64) { o = MaybePlacebo::from(Arc::new(Option::::None {})); return o.read(); }; - if !(!(crate::implementation_from_dafny::_StandardLibrary_Compile::_UInt_Compile::_default::UINT64_MAX_LIMIT() - int!(1) < haystack.cardinality())) { - panic!("Halt") - }; let mut size: u64 = truncate!(needle.cardinality(), u64); - let mut limit: u64 = truncate!(haystack.cardinality(), u64) - size + truncate!(int!(1), u64); + let mut limit: u64 = crate::implementation_from_dafny::_StandardLibrary_Compile::_MemoryMath_Compile::_default::Add(truncate!(haystack.cardinality(), u64) - size, truncate!(int!(1), u64)); let mut _hi0: u64 = limit; for index in integer_range(truncate!(int!(0), u64), _hi0).map(Into::::into) { - if crate::implementation_from_dafny::_StandardLibrary_Compile::_Sequence_Compile::_default::SequenceEqual::(haystack, needle, index, truncate!(int!(0), u64), size) { + if crate::implementation_from_dafny::_StandardLibrary_Compile::_Sequence_Compile::_default::SequenceEqual::<_T>(haystack, needle, index, truncate!(int!(0), u64), size) { o = MaybePlacebo::from(Arc::new(Option::::Some { value: int!(index) })); @@ -96565,10 +96720,39 @@ pub mod _StandardLibrary_Compile { o = MaybePlacebo::from(Arc::new(Option::::None {})); return o.read(); } - /// ../mpl/StandardLibrary/src/String.dfy(12,3) + /// ../mpl/StandardLibrary/src/String.dfy(254,3) + pub fn HasSubStringPos<_T: DafnyTypeEq>(haystack: &Sequence<_T>, needle: &Sequence<_T>, pos: u64) -> Arc> { + let mut o = MaybePlacebo::>>::new(); + if truncate!(haystack.cardinality(), u64) - pos < truncate!(needle.cardinality(), u64) { + o = MaybePlacebo::from(Arc::new(Option::::None {})); + return o.read(); + }; + let mut size: u64 = truncate!(needle.cardinality(), u64); + let mut limit: u64 = crate::implementation_from_dafny::_StandardLibrary_Compile::_MemoryMath_Compile::_default::Add(truncate!(haystack.cardinality(), u64) - size, truncate!(int!(1), u64)); + let mut _hi0: u64 = limit; + for index in integer_range(pos, _hi0).map(Into::::into) { + if crate::implementation_from_dafny::_StandardLibrary_Compile::_Sequence_Compile::_default::SequenceEqual::<_T>(haystack, needle, index, truncate!(int!(0), u64), size) { + o = MaybePlacebo::from(Arc::new(Option::::Some { + value: index + })); + return o.read(); + } + } + o = MaybePlacebo::from(Arc::new(Option::::None {})); + return o.read(); + } + /// ../mpl/StandardLibrary/src/String.dfy(15,3) pub fn Base10() -> Sequence { seq![DafnyCharUTF16(48 as u16), DafnyCharUTF16(49 as u16), DafnyCharUTF16(50 as u16), DafnyCharUTF16(51 as u16), DafnyCharUTF16(52 as u16), DafnyCharUTF16(53 as u16), DafnyCharUTF16(54 as u16), DafnyCharUTF16(55 as u16), DafnyCharUTF16(56 as u16), DafnyCharUTF16(57 as u16)] } + /// ../mpl/StandardLibrary/src/String.dfy(120,3) + pub fn AlphaNumeric() -> Sequence { + string_utf16_of("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789") + } + /// ../mpl/StandardLibrary/src/String.dfy(121,3) + pub fn AlphaNumericUnder() -> Sequence { + string_utf16_of("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_") + } } } @@ -97015,7 +97199,7 @@ pub mod _StormTracker_Compile { let mut _nw0: Object = LocalCMC::_allocate_object(); LocalCMC::_ctor(&_nw0, cache.entryCapacity().clone() as u64, cache.entryPruningTailSize().UnwrapOr(&truncate!((&int!(1)).clone(), i32)) as u64); update_field_mut_uninit_object!(this.clone(), wrapped, _set_wrapped, _nw0.clone()); - let mut _nw1: Object, PositiveLong>> = MutableMap::, PositiveLong>::_allocate_object(); + let mut _nw1: Object, PositiveLong>> = MutableMap::, PositiveLong>::_allocate_object(true); update_field_mut_uninit_object!(this.clone(), inFlight, _set_inFlight, _nw1.clone()); update_field_mut_uninit_object!(this.clone(), gracePeriod, _set_gracePeriod, gracePeriod); update_field_mut_uninit_object!(this.clone(), graceInterval, _set_graceInterval, graceInterval); diff --git a/releases/rust/esdk/src/lib.rs b/releases/rust/esdk/src/lib.rs index dcb1d7b07..43ed4bdbf 100644 --- a/releases/rust/esdk/src/lib.rs +++ b/releases/rust/esdk/src/lib.rs @@ -75,6 +75,12 @@ pub mod operation; /// Types for the transform client. pub mod types; +#[cfg(feature = "fips")] +use aws_lc_fips_sys as aws_lc_sys_impl; + +#[cfg(not(feature = "fips"))] +use aws_lc_sys as aws_lc_sys_impl; + pub use client::Client; pub use types::aws_encryption_sdk_config::AwsEncryptionSdkConfig; diff --git a/releases/rust/esdk/src/rsa.rs b/releases/rust/esdk/src/rsa.rs index 72bd24ca9..bc89c5a97 100644 --- a/releases/rust/esdk/src/rsa.rs +++ b/releases/rust/esdk/src/rsa.rs @@ -46,18 +46,18 @@ pub mod RSAEncryption { fn generate_key_pair(length_bits: i32) -> Result<(Vec, Vec), String> { // Generate an RSA key. let private_key = PrivateDecryptingKey::generate(key_size_from_length(length_bits)) - .map_err(|e| format!("{:?}", e))?; + .map_err(|e| format!("{e:?}"))?; // Serialize the RSA private key to DER encoded PKCS#8 format for later usage. let private_key_der = - AsDer::::as_der(&private_key).map_err(|e| format!("{:?}", e))?; + AsDer::::as_der(&private_key).map_err(|e| format!("{e:?}"))?; // Retrieve the RSA public key let public_key = private_key.public_key(); // Serialize the RSA public key to DER encoded X.509 SubjectPublicKeyInfo for later usage. let public_key_der = - AsDer::::as_der(&public_key).map_err(|e| format!("{:?}", e))?; + AsDer::::as_der(&public_key).map_err(|e| format!("{e:?}"))?; let public_key = pem::Pem::new("RSA PUBLIC KEY", public_key_der.as_ref()); let public_key = pem::encode(&public_key); @@ -76,7 +76,7 @@ pub mod RSAEncryption { dafny_runtime::Sequence::from_array_owned(x.1), ), Err(e) => { - panic!("Unexpected error generating RSA Key Pair{}", e); + panic!("Unexpected error generating RSA Key Pair{e}"); } } } @@ -94,10 +94,10 @@ pub mod RSAEncryption { } fn get_modulus(public_key: &[u8]) -> Result { - let public_key = std::str::from_utf8(public_key).map_err(|e| format!("{:?}", e))?; - let public_key = pem::parse(public_key).map_err(|e| format!("{:?}", e))?; + let public_key = std::str::from_utf8(public_key).map_err(|e| format!("{e:?}"))?; + let public_key = pem::parse(public_key).map_err(|e| format!("{e:?}"))?; let public_key = PublicEncryptingKey::from_der(public_key.contents()) - .map_err(|e| format!("{:?}", e))?; + .map_err(|e| format!("{e:?}"))?; Ok(public_key.key_size_bits() as u32) } @@ -118,22 +118,21 @@ pub mod RSAEncryption { cipher_text: &[u8], ) -> Result, String> { let private_key = - std::str::from_utf8(private_key).map_err(|e| format!("from_utf8 : {:?}", e))?; - let private_key = - pem::parse(private_key).map_err(|e| format!("pem::parse : {:?}", e))?; + std::str::from_utf8(private_key).map_err(|e| format!("from_utf8 : {e:?}"))?; + let private_key = pem::parse(private_key).map_err(|e| format!("pem::parse : {e:?}"))?; if mode == &(RSAPaddingMode::PKCS1 {}) { return decrypt_pkcs1(private_key.contents(), cipher_text); } let mode = get_alg_for_padding(mode)?; let private_key = PrivateDecryptingKey::from_pkcs8(private_key.contents()) - .map_err(|e| format!("from_pkcs8 : {:?}", e))?; + .map_err(|e| format!("from_pkcs8 : {e:?}"))?; let private_key = - OaepPrivateDecryptingKey::new(private_key).map_err(|e| format!("new : {:?}", e))?; + OaepPrivateDecryptingKey::new(private_key).map_err(|e| format!("new : {e:?}"))?; let mut message: Vec = vec![0; cipher_text.len()]; let message = private_key .decrypt(mode, cipher_text, &mut message, None) - .map_err(|e| format!("decrypt {:?}", e))?; + .map_err(|e| format!("decrypt {e:?}"))?; Ok(message.to_vec()) } @@ -150,7 +149,7 @@ pub mod RSAEncryption { value: dafny_runtime::Sequence::from_array_owned(x), }), Err(e) => { - let msg = format!("RSA Decrypt : {}", e); + let msg = format!("RSA Decrypt : {e}"); Rc::new(Wrappers::Result::Failure { error: error(&msg) }) } } @@ -161,21 +160,21 @@ pub mod RSAEncryption { public_key: &[u8], message: &[u8], ) -> Result, String> { - let public_key = std::str::from_utf8(public_key).map_err(|e| format!("{:?}", e))?; - let public_key = pem::parse(public_key).map_err(|e| format!("{:?}", e))?; + let public_key = std::str::from_utf8(public_key).map_err(|e| format!("{e:?}"))?; + let public_key = pem::parse(public_key).map_err(|e| format!("{e:?}"))?; if mode == &(RSAPaddingMode::PKCS1 {}) { return encrypt_pkcs1(public_key.contents(), message); } let mode = get_alg_for_padding(mode)?; let public_key = PublicEncryptingKey::from_der(public_key.contents()) - .map_err(|e| format!("{:?}", e))?; + .map_err(|e| format!("{e:?}"))?; let public_key = - OaepPublicEncryptingKey::new(public_key).map_err(|e| format!("{:?}", e))?; + OaepPublicEncryptingKey::new(public_key).map_err(|e| format!("{e:?}"))?; let mut ciphertext: Vec = vec![0; message.len() + public_key.key_size_bytes()]; let cipher_text = public_key .encrypt(mode, message, &mut ciphertext, None) - .map_err(|e| format!("{:?}", e))?; + .map_err(|e| format!("{e:?}"))?; Ok(cipher_text.to_vec()) } @@ -192,7 +191,7 @@ pub mod RSAEncryption { value: dafny_runtime::Sequence::from_array_owned(x), }), Err(e) => { - let msg = format!("RSA Encrypt : {}", e); + let msg = format!("RSA Encrypt : {e}"); Rc::new(Wrappers::Result::Failure { error: error(&msg) }) } } @@ -200,25 +199,25 @@ pub mod RSAEncryption { pub fn encrypt_pkcs1(public_key: &[u8], plain_text: &[u8]) -> Result, String> { let public_key = - PublicEncryptingKey::from_der(public_key).map_err(|e| format!("{:?}", e))?; + PublicEncryptingKey::from_der(public_key).map_err(|e| format!("{e:?}"))?; let public_key = - Pkcs1PublicEncryptingKey::new(public_key).map_err(|e| format!("{:?}", e))?; + Pkcs1PublicEncryptingKey::new(public_key).map_err(|e| format!("{e:?}"))?; let mut ciphertext: Vec = vec![0; plain_text.len() + public_key.key_size_bytes()]; let cipher_text = public_key .encrypt(plain_text, &mut ciphertext) - .map_err(|e| format!("{:?}", e))?; + .map_err(|e| format!("{e:?}"))?; Ok(cipher_text.to_vec()) } pub fn decrypt_pkcs1(private_key: &[u8], cipher_text: &[u8]) -> Result, String> { let private_key = PrivateDecryptingKey::from_pkcs8(private_key) - .map_err(|e| format!("from_pkcs8 : {:?}", e))?; - let private_key = Pkcs1PrivateDecryptingKey::new(private_key) - .map_err(|e| format!("new : {:?}", e))?; + .map_err(|e| format!("from_pkcs8 : {e:?}"))?; + let private_key = + Pkcs1PrivateDecryptingKey::new(private_key).map_err(|e| format!("new : {e:?}"))?; let mut message: Vec = vec![0; cipher_text.len()]; let message = private_key .decrypt(cipher_text, &mut message) - .map_err(|e| format!("decrypt {:?}", e))?; + .map_err(|e| format!("decrypt {e:?}"))?; Ok(message.to_vec()) } @@ -231,7 +230,7 @@ pub mod RSAEncryption { let modulus: u32 = match &*GetRSAKeyModulusLengthExtern(&public_key) { Wrappers::Result::Success { value } => *value, - Wrappers::Result::Failure { error } => panic!("{:?}", error), + Wrappers::Result::Failure { error } => panic!("{error:?}"), }; assert_eq!(modulus, 2048); @@ -243,13 +242,13 @@ pub mod RSAEncryption { let cipher: ::dafny_runtime::Sequence = match &*EncryptExtern(&mode, &public_key, &plain_text) { Wrappers::Result::Success { value } => value.clone(), - Wrappers::Result::Failure { error } => panic!("{:?}", error), + Wrappers::Result::Failure { error } => panic!("{error:?}"), }; let message: ::dafny_runtime::Sequence = match &*DecryptExtern(&mode, &private_key, &cipher) { Wrappers::Result::Success { value } => value.clone(), - Wrappers::Result::Failure { error } => panic!("{:?}", error), + Wrappers::Result::Failure { error } => panic!("{error:?}"), }; assert_eq!(plain_text, message);