From a31a5f8a5dcd8cccf263c9e396b55b25aab05c9e Mon Sep 17 00:00:00 2001 From: Ritvik Kapila <61410899+RitvikKapila@users.noreply.github.com> Date: Tue, 29 Oct 2024 11:29:30 -0700 Subject: [PATCH] Delete AwsEncryptionSDK/runtimes/rust/src directory --- AwsEncryptionSDK/runtimes/rust/src/aes_gcm.rs | 255 --------- .../runtimes/rust/src/aes_kdf_ctr.rs | 76 --- AwsEncryptionSDK/runtimes/rust/src/client.rs | 36 -- .../runtimes/rust/src/concurrent_call.rs | 61 --- .../runtimes/rust/src/conversions.rs | 22 - .../runtimes/rust/src/dafny_libraries.rs | 150 ----- AwsEncryptionSDK/runtimes/rust/src/ddb.rs | 75 --- AwsEncryptionSDK/runtimes/rust/src/deps.rs | 12 - AwsEncryptionSDK/runtimes/rust/src/digest.rs | 34 -- AwsEncryptionSDK/runtimes/rust/src/ecdh.rs | 513 ------------------ AwsEncryptionSDK/runtimes/rust/src/ecdsa.rs | 276 ---------- AwsEncryptionSDK/runtimes/rust/src/error.rs | 16 - AwsEncryptionSDK/runtimes/rust/src/hmac.rs | 121 ----- AwsEncryptionSDK/runtimes/rust/src/kms.rs | 88 --- .../runtimes/rust/src/local_cmc.rs | 53 -- .../runtimes/rust/src/operation.rs | 8 - AwsEncryptionSDK/runtimes/rust/src/random.rs | 38 -- AwsEncryptionSDK/runtimes/rust/src/rsa.rs | 256 --------- AwsEncryptionSDK/runtimes/rust/src/sets.rs | 63 --- .../runtimes/rust/src/software_externs.rs | 22 - .../rust/src/standard_library_conversions.rs | 266 --------- .../rust/src/standard_library_externs.rs | 80 --- .../runtimes/rust/src/storm_tracker.rs | 80 --- AwsEncryptionSDK/runtimes/rust/src/time.rs | 43 -- AwsEncryptionSDK/runtimes/rust/src/types.rs | 24 - AwsEncryptionSDK/runtimes/rust/src/uuid.rs | 76 --- 26 files changed, 2744 deletions(-) delete mode 100644 AwsEncryptionSDK/runtimes/rust/src/aes_gcm.rs delete mode 100644 AwsEncryptionSDK/runtimes/rust/src/aes_kdf_ctr.rs delete mode 100644 AwsEncryptionSDK/runtimes/rust/src/client.rs delete mode 100644 AwsEncryptionSDK/runtimes/rust/src/concurrent_call.rs delete mode 100644 AwsEncryptionSDK/runtimes/rust/src/conversions.rs delete mode 100644 AwsEncryptionSDK/runtimes/rust/src/dafny_libraries.rs delete mode 100644 AwsEncryptionSDK/runtimes/rust/src/ddb.rs delete mode 100644 AwsEncryptionSDK/runtimes/rust/src/deps.rs delete mode 100644 AwsEncryptionSDK/runtimes/rust/src/digest.rs delete mode 100644 AwsEncryptionSDK/runtimes/rust/src/ecdh.rs delete mode 100644 AwsEncryptionSDK/runtimes/rust/src/ecdsa.rs delete mode 100644 AwsEncryptionSDK/runtimes/rust/src/error.rs delete mode 100644 AwsEncryptionSDK/runtimes/rust/src/hmac.rs delete mode 100644 AwsEncryptionSDK/runtimes/rust/src/kms.rs delete mode 100644 AwsEncryptionSDK/runtimes/rust/src/local_cmc.rs delete mode 100644 AwsEncryptionSDK/runtimes/rust/src/operation.rs delete mode 100644 AwsEncryptionSDK/runtimes/rust/src/random.rs delete mode 100644 AwsEncryptionSDK/runtimes/rust/src/rsa.rs delete mode 100644 AwsEncryptionSDK/runtimes/rust/src/sets.rs delete mode 100644 AwsEncryptionSDK/runtimes/rust/src/software_externs.rs delete mode 100644 AwsEncryptionSDK/runtimes/rust/src/standard_library_conversions.rs delete mode 100644 AwsEncryptionSDK/runtimes/rust/src/standard_library_externs.rs delete mode 100644 AwsEncryptionSDK/runtimes/rust/src/storm_tracker.rs delete mode 100644 AwsEncryptionSDK/runtimes/rust/src/time.rs delete mode 100644 AwsEncryptionSDK/runtimes/rust/src/types.rs delete mode 100644 AwsEncryptionSDK/runtimes/rust/src/uuid.rs diff --git a/AwsEncryptionSDK/runtimes/rust/src/aes_gcm.rs b/AwsEncryptionSDK/runtimes/rust/src/aes_gcm.rs deleted file mode 100644 index cbf0a8f78..000000000 --- a/AwsEncryptionSDK/runtimes/rust/src/aes_gcm.rs +++ /dev/null @@ -1,255 +0,0 @@ -// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. -// SPDX-License-Identifier: Apache-2.0 - -#![deny(warnings, unconditional_panic)] -#![deny(nonstandard_style)] -#![deny(clippy::all)] - -use crate::software::amazon::cryptography::primitives::internaldafny::types::AESEncryptOutput; -use crate::software::amazon::cryptography::primitives::internaldafny::types::Error as DafnyError; -use crate::software::amazon::cryptography::primitives::internaldafny::types::AES_GCM; -use crate::*; -use aws_lc_rs::aead::{Aad, LessSafeKey, Nonce, UnboundKey}; -use std::rc::Rc; - -struct DoAESEncryptOutput { - cipher_text: Vec, - auth_tag: Vec, -} - -fn error(s: &str) -> Rc { - Rc::new(DafnyError::AwsCryptographicPrimitivesError { - message: - dafny_runtime::dafny_runtime_conversions::unicode_chars_false::string_to_dafny_string(s), - }) -} - -fn enc_result(s: &str) -> Rc<_Wrappers_Compile::Result, Rc>> { - Rc::new(_Wrappers_Compile::Result::Failure { error: error(s) }) -} - -fn dec_result( - s: &str, -) -> Rc<_Wrappers_Compile::Result<::dafny_runtime::Sequence, Rc>> { - Rc::new(_Wrappers_Compile::Result::Failure { error: error(s) }) -} - -#[allow(non_snake_case)] -pub mod AESEncryption { - pub use crate::software::amazon::cryptography::primitives::internaldafny::types::*; -} -impl AES_GCM { - fn get_alg(&self) -> Result<&'static aws_lc_rs::aead::Algorithm, String> { - if *self.tagLength() != 16i32 { - Err(format!( - "Tag length of {} not supported in Rust. Tag length must be 16.", - self.tagLength() - )) - } else if *self.ivLength() != 12i32 { - Err(format!( - "IV length of {} not supported in Rust. IV length must be 12.", - self.ivLength() - )) - } else if *self.keyLength() == 32i32 { - Ok(&aws_lc_rs::aead::AES_256_GCM) - } else if *self.keyLength() == 16i32 { - Ok(&aws_lc_rs::aead::AES_128_GCM) - } else { - Err(format!( - "Key length of {} not supported in Rust. Tag length must be 16 or 32.", - self.keyLength() - )) - } - } - - fn do_aes_encrypt( - &self, - iv: &[u8], - key: &[u8], - msg: &[u8], - aad: &[u8], - ) -> 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 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))?; - Ok(DoAESEncryptOutput { - cipher_text: in_out_buffer, - auth_tag: Vec::from(tag.as_ref()), - }) - } - - fn do_aes_decrypt( - &self, - key: &[u8], - cipher_text: &[u8], - auth_tag: &[u8], - iv: &[u8], - aad: &[u8], - ) -> 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 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))?; - Ok(out_buffer) - } - - #[allow(non_snake_case)] - pub fn AESEncryptExtern( - &self, - iv: &::dafny_runtime::Sequence, - key: &::dafny_runtime::Sequence, - msg: &::dafny_runtime::Sequence, - aad: &::dafny_runtime::Sequence, - ) -> Rc<_Wrappers_Compile::Result, Rc>> { - let iv: Vec = iv.iter().collect(); - let key: Vec = key.iter().collect(); - let msg: Vec = msg.iter().collect(); - let aad: Vec = aad.iter().collect(); - - if *self.keyLength() as usize != key.len() { - let msg = format!( - "AESEncrypt : algorithm key length was {} but actual key length was {}.", - self.keyLength(), - key.len() - ); - return enc_result(&msg); - } - if *self.ivLength() as usize != iv.len() { - let msg = format!( - "AESEncrypt : algorithm nonce length was {} but actual nonce length was {}.", - self.ivLength(), - iv.len() - ); - return enc_result(&msg); - } - - match self.do_aes_encrypt(&iv, &key, &msg, &aad) { - Ok(x) => Rc::new(_Wrappers_Compile::Result::Success { - value: Rc::new(AESEncryptOutput::AESEncryptOutput { - cipherText: x.cipher_text.iter().cloned().collect(), - authTag: x.auth_tag.iter().cloned().collect(), - }), - }), - Err(e) => { - let msg = format!("AES Encrypt : {}", e); - enc_result(&msg) - } - } - } - - #[allow(non_snake_case)] - pub fn AESDecryptExtern( - &self, - key: &::dafny_runtime::Sequence, - cipher_text: &::dafny_runtime::Sequence, - auth_tag: &::dafny_runtime::Sequence, - iv: &::dafny_runtime::Sequence, - aad: &::dafny_runtime::Sequence, - ) -> Rc<_Wrappers_Compile::Result<::dafny_runtime::Sequence, Rc>> { - let key: Vec = key.iter().collect(); - let cipher_text: Vec = cipher_text.iter().collect(); - let auth_tag: Vec = auth_tag.iter().collect(); - let iv: Vec = iv.iter().collect(); - let aad: Vec = aad.iter().collect(); - - if *self.keyLength() as usize != key.len() { - let msg = format!( - "AESEncrypt : algorithm key length was {} but actual key length was {}.", - self.keyLength(), - key.len() - ); - return dec_result(&msg); - } - - if *self.ivLength() as usize != iv.len() { - let msg = format!( - "AESEncrypt : algorithm nonce length was {} but actual nonce length was {}.", - self.ivLength(), - iv.len() - ); - return dec_result(&msg); - } - - if *self.tagLength() as usize != auth_tag.len() { - let msg = format!( - "AESEncrypt : algorithm auth tag length was {} but actual auth tag length was {}.", - self.tagLength(), - auth_tag.len() - ); - return dec_result(&msg); - } - - match self.do_aes_decrypt(&key, &cipher_text, &auth_tag, &iv, &aad) { - Ok(x) => Rc::new(_Wrappers_Compile::Result::Success { - value: x.iter().cloned().collect(), - }), - Err(e) => { - let msg = format!("AES Decrypt : {}", e); - dec_result(&msg) - } - } - } -} - -#[cfg(test)] -mod tests { - use super::*; - #[test] - fn test_generate() { - let iv: ::dafny_runtime::Sequence = [1u8, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] - .iter() - .cloned() - .collect(); - let key: ::dafny_runtime::Sequence = [ - 2u8, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, - 25, 26, 27, 28, 29, 30, 31, 32, 33, - ] - .iter() - .cloned() - .collect(); - let msg: ::dafny_runtime::Sequence = [2u8, 4, 6, 8, 10, 12].iter().cloned().collect(); - let aad: ::dafny_runtime::Sequence = - [3u8, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17] - .iter() - .cloned() - .collect(); - - let alg = AES_GCM::AES_GCM { - keyLength: 32, - tagLength: 16, - ivLength: 12, - }; - 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); - } - }; - - let (cipher_text, auth_tag) = match &*cipher { - AESEncryptOutput::AESEncryptOutput { - cipherText, - authTag, - } => (cipherText, authTag), - }; - - 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); - } - }; - - assert_eq!(output, msg); - } -} diff --git a/AwsEncryptionSDK/runtimes/rust/src/aes_kdf_ctr.rs b/AwsEncryptionSDK/runtimes/rust/src/aes_kdf_ctr.rs deleted file mode 100644 index e7798d322..000000000 --- a/AwsEncryptionSDK/runtimes/rust/src/aes_kdf_ctr.rs +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. -// SPDX-License-Identifier: Apache-2.0 - -#![deny(warnings, unconditional_panic)] -#![deny(nonstandard_style)] -#![deny(clippy::all)] - -#[allow(non_snake_case)] -pub mod AesKdfCtr { - use crate::software::amazon::cryptography::primitives::internaldafny::types::Error as DafnyError; - use crate::*; - use aws_lc_rs::cipher::{EncryptingKey, EncryptionContext, UnboundCipherKey, AES_256}; - use dafny_runtime::Sequence; - use std::rc::Rc; - - #[allow(non_camel_case_types)] - // pub struct _default {} - - fn error(s: &str) -> Rc { - Rc::new(DafnyError::AwsCryptographicPrimitivesError { - message: - dafny_runtime::dafny_runtime_conversions::unicode_chars_false::string_to_dafny_string(s), - }) - } - - fn as_array(nonce: &[u8]) -> &[u8; aws_lc_rs::iv::IV_LEN_128_BIT] { - nonce.try_into().unwrap() - } - - fn ctr_stream(nonce: &[u8], key: &[u8], length: u32) -> Result, String> { - if nonce.len() != aws_lc_rs::iv::IV_LEN_128_BIT { - return Err(format!( - "Nonce length of {} not supported in AesKdfCtrStream. Nonce length must be {}.", - nonce.len(), - aws_lc_rs::iv::IV_LEN_128_BIT - )); - } - - 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 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))?; - Ok(in_out_buffer) - } - - impl crate::AesKdfCtr::_default { - #[allow(non_snake_case)] - pub fn AesKdfCtrStream( - nonce: &Sequence, - key: &Sequence, - length: u32, - ) -> Rc< - _Wrappers_Compile::Result< - Sequence, - Rc, - >, - > { - let nonce: Vec = nonce.iter().collect(); - let key: Vec = key.iter().collect(); - match ctr_stream(&nonce, &key, length) { - Ok(x) => Rc::new(_Wrappers_Compile::Result::Success { - value: x.iter().cloned().collect(), - }), - Err(e) => { - let msg = format!("Aes Kdf Ctr : {}", e); - Rc::new(_Wrappers_Compile::Result::Failure { error: error(&msg) }) - } - } - } - } -} diff --git a/AwsEncryptionSDK/runtimes/rust/src/client.rs b/AwsEncryptionSDK/runtimes/rust/src/client.rs deleted file mode 100644 index c7b90345b..000000000 --- a/AwsEncryptionSDK/runtimes/rust/src/client.rs +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. -// SPDX-License-Identifier: Apache-2.0 -// Do not modify this file. This file is machine generated, and any changes to it will be overwritten. -use aws_smithy_types::error::operation::BuildError; - -#[derive(::std::clone::Clone, ::std::fmt::Debug, ::std::cmp::PartialEq)] -#[allow(missing_docs)] -pub struct Client { - pub(crate) dafny_client: ::dafny_runtime::Object -} - -impl Client { - /// Creates a new client from the service [`Config`](crate::Config). - #[track_caller] - pub fn from_conf( - conf: crate::types::aws_encryption_sdk_config::AwsEncryptionSdkConfig, - ) -> Result { - let inner = - crate::software::amazon::cryptography::encryptionsdk::internaldafny::_default::ESDK( - &crate::conversions::aws_encryption_sdk_config::_aws_encryption_sdk_config::to_dafny(conf), - ); - if matches!( - inner.as_ref(), - crate::_Wrappers_Compile::Result::Failure { .. } - ) { - return Err(crate::conversions::error::from_dafny(inner.as_ref().error().clone())); - } - Ok(Self { - dafny_client: ::dafny_runtime::upcast_object()(inner.Extract()) - }) - } -} - -mod encrypt; - -mod decrypt; diff --git a/AwsEncryptionSDK/runtimes/rust/src/concurrent_call.rs b/AwsEncryptionSDK/runtimes/rust/src/concurrent_call.rs deleted file mode 100644 index 6bafd0c6a..000000000 --- a/AwsEncryptionSDK/runtimes/rust/src/concurrent_call.rs +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. -// SPDX-License-Identifier: Apache-2.0 - -#![deny(warnings, unconditional_panic)] -#![deny(nonstandard_style)] -#![deny(clippy::all)] -#![allow(dead_code)] - -#[allow(non_snake_case)] -pub mod ConcurrentCall { - - fn de_const( - p: *const dafny_runtime::Object<(dyn Callee + 'static)>, - ) -> *mut dafny_runtime::Object<(dyn Callee + 'static)> { - p as _ - } - - pub struct FakeCallee { - callee: *const dafny_runtime::Object<(dyn Callee + 'static)>, - } - impl FakeCallee { - fn new(callee: &dafny_runtime::Object<(dyn Callee + 'static)>) -> Self { - Self { - callee: std::ptr::from_ref(callee), - } - } - fn call(&self, x: u32, y: u32) { - let mptr = de_const(self.callee); - let value: &mut dafny_runtime::Object<(dyn Callee + 'static)> = unsafe { &mut *mptr }; - value.as_mut().call(x, y); - } - } - unsafe impl Send for FakeCallee {} - - #[allow(nonstandard_style)] - pub struct _default {} - use crate::ConcurrentCall::Callee; - impl _default { - pub fn ConcurrentCall( - callee: &dafny_runtime::Object<(dyn Callee + 'static)>, - serial_iters: u32, - concurrent_iters: u32, - ) { - let mut children = vec![]; - - for i in 0..concurrent_iters { - // Spin up another thread - let fake = FakeCallee::new(callee); - children.push(std::thread::spawn(move || { - for j in 0..serial_iters { - fake.call(j, i); - } - })); - } - - for child in children { - let _ = child.join(); - } - } - } -} diff --git a/AwsEncryptionSDK/runtimes/rust/src/conversions.rs b/AwsEncryptionSDK/runtimes/rust/src/conversions.rs deleted file mode 100644 index 0ffc951b1..000000000 --- a/AwsEncryptionSDK/runtimes/rust/src/conversions.rs +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. -// SPDX-License-Identifier: Apache-2.0 -// Do not modify this file. This file is machine generated, and any changes to it will be overwritten. -pub mod client; - - pub mod decrypt; - - pub mod decrypt_input; - - pub mod decrypt_output; - - pub mod encrypt; - - pub mod encrypt_input; - - pub mod encrypt_output; - - pub mod error; - - pub mod net_v4_0_0_retry_policy; - -pub mod aws_encryption_sdk_config; diff --git a/AwsEncryptionSDK/runtimes/rust/src/dafny_libraries.rs b/AwsEncryptionSDK/runtimes/rust/src/dafny_libraries.rs deleted file mode 100644 index 52f8782ee..000000000 --- a/AwsEncryptionSDK/runtimes/rust/src/dafny_libraries.rs +++ /dev/null @@ -1,150 +0,0 @@ -// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. -// SPDX-License-Identifier: Apache-2.0 - -#![deny(warnings, unconditional_panic)] -#![deny(nonstandard_style)] -#![deny(clippy::all)] - -#[allow(non_snake_case)] -pub mod DafnyLibraries { - use dashmap::DashMap; - use std::collections::HashMap; - use std::collections::HashSet; - - pub struct MutableMap { - map: DashMap, - } - - impl MutableMap { - pub fn _allocate_object() -> ::dafny_runtime::Object { - ::dafny_runtime::Object::new(MutableMap { - map: DashMap::new(), - }) - } - } - - impl - crate::DafnyLibraries::MutableMapTrait for MutableMap - { - fn content(&self) -> ::dafny_runtime::Map { - let mut new_map = HashMap::new(); - for entry in self.map.iter() { - new_map.insert(entry.key().clone(), entry.value().clone()); - } - dafny_runtime::Map::from_hashmap_owned(new_map) - } - fn Put(&self, k: &K, v: &V) { - self.map.insert(k.clone(), v.clone()); - } - fn Keys(&self) -> ::dafny_runtime::Set { - let mut new_set = HashSet::new(); - for entry in self.map.iter() { - new_set.insert(entry.key().clone()); - } - dafny_runtime::Set::from_hashset_owned(new_set) - } - fn HasKey(&self, k: &K) -> bool { - self.map.contains_key(k) - } - fn Values(&self) -> ::dafny_runtime::Set { - let mut new_set = HashSet::new(); - for entry in self.map.iter() { - new_set.insert(entry.value().clone()); - } - dafny_runtime::Set::from_hashset_owned(new_set) - } - fn Items(&self) -> ::dafny_runtime::Set<(K, V)> { - let mut new_set = HashSet::new(); - for entry in self.map.iter() { - new_set.insert((entry.key().clone(), entry.value().clone())); - } - dafny_runtime::Set::from_hashset_owned(new_set) - } - fn Select(&self, k: &K) -> V { - self.map.get(k).unwrap().clone() - } - fn Remove(&self, k: &K) { - self.map.remove(k); - } - fn Size(&self) -> ::dafny_runtime::DafnyInt { - self.map.len().into() - } - } - - pub mod FileIO { - use std::fs::File; - use std::io::Read; - use std::io::Write; - use std::path::Path; - - pub fn INTERNAL_ReadBytesFromFile( - file: &::dafny_runtime::Sequence<::dafny_runtime::DafnyCharUTF16>, - ) -> ( - bool, - ::dafny_runtime::Sequence, - ::dafny_runtime::Sequence<::dafny_runtime::DafnyCharUTF16>, - ) { - let file_name = dafny_runtime::dafny_runtime_conversions::unicode_chars_false::dafny_string_to_string(file); - let path = Path::new(&file_name); - - let mut file = match File::open(path) { - Err(why) => { - let err_msg = format!("couldn't open {} for reading: {}", path.display(), why); - let err_msg = dafny_runtime::dafny_runtime_conversions::unicode_chars_false::string_to_dafny_string(&err_msg); - return (true, dafny_runtime::Sequence::default(), err_msg); - } - Ok(file) => file, - }; - - let mut result = Vec::new(); - match file.read_to_end(&mut result) { - Err(why) => { - let err_msg = format!("couldn't read from {}: {}", path.display(), why); - let err_msg = dafny_runtime::dafny_runtime_conversions::unicode_chars_false::string_to_dafny_string(&err_msg); - (true, dafny_runtime::Sequence::default(), err_msg) - } - Ok(_) => ( - false, - dafny_runtime::Sequence::from_array_owned(result), - dafny_runtime::Sequence::default(), - ), - } - } - - pub fn INTERNAL_WriteBytesToFile( - path: &::dafny_runtime::Sequence<::dafny_runtime::DafnyCharUTF16>, - bytes: &::dafny_runtime::Sequence, - ) -> ( - bool, - ::dafny_runtime::Sequence<::dafny_runtime::DafnyCharUTF16>, - ) { - let file_name = dafny_runtime::dafny_runtime_conversions::unicode_chars_false::dafny_string_to_string(path); - let path = Path::new(&file_name); - - let maybe_file = std::fs::OpenOptions::new() - .write(true) - .create(true) - .truncate(true) - .open(path); - let mut file = match maybe_file { - Err(why) => { - let err_msg = format!("couldn't open {} for writing: {}", path.display(), why); - let err_msg = dafny_runtime::dafny_runtime_conversions::unicode_chars_false::string_to_dafny_string(&err_msg); - return (true, err_msg); - } - Ok(file) => file, - }; - - let bytes = bytes.to_array(); - match file.write_all(&bytes) { - Err(why) => { - let err_msg = - format!("couldn't write all bytes to {}: {}", path.display(), why); - let err_msg = dafny_runtime::dafny_runtime_conversions::unicode_chars_false::string_to_dafny_string(&err_msg); - (true, err_msg) - } - Ok(_) => (false, dafny_runtime::Sequence::default()), - } - } - } -} diff --git a/AwsEncryptionSDK/runtimes/rust/src/ddb.rs b/AwsEncryptionSDK/runtimes/rust/src/ddb.rs deleted file mode 100644 index 2032916b5..000000000 --- a/AwsEncryptionSDK/runtimes/rust/src/ddb.rs +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. -// SPDX-License-Identifier: Apache-2.0 - -#![deny(warnings, unconditional_panic)] -#![deny(nonstandard_style)] -#![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 { - pub fn DDBClientForRegion(region: &::dafny_runtime::Sequence<::dafny_runtime::DafnyCharUTF16>) -> ::std::rc::Rc< - crate::r#_Wrappers_Compile::Result< - ::dafny_runtime::Object, - ::std::rc::Rc - > - >{ - let region = - dafny_runtime::dafny_runtime_conversions::unicode_chars_false::dafny_string_to_string( - region, - ); - 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)) - .build(); - 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)); - std::rc::Rc::new(crate::r#_Wrappers_Compile::Result::Success { - value: dafny_client, - }) - } - - pub fn DynamoDBClient() -> ::std::rc::Rc< - crate::r#_Wrappers_Compile::Result< - ::dafny_runtime::Object, - ::std::rc::Rc - > - >{ - 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)); - std::rc::Rc::new(crate::r#_Wrappers_Compile::Result::Success { - value: dafny_client, - }) - } -} diff --git a/AwsEncryptionSDK/runtimes/rust/src/deps.rs b/AwsEncryptionSDK/runtimes/rust/src/deps.rs deleted file mode 100644 index 12e9c9a6b..000000000 --- a/AwsEncryptionSDK/runtimes/rust/src/deps.rs +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. -// SPDX-License-Identifier: Apache-2.0 -// Do not modify this file. This file is machine generated, and any changes to it will be overwritten. -pub mod aws_cryptography_keyStore; - - pub mod aws_cryptography_materialProviders; - - pub mod aws_cryptography_primitives; - - pub mod com_amazonaws_dynamodb; - - pub mod com_amazonaws_kms; diff --git a/AwsEncryptionSDK/runtimes/rust/src/digest.rs b/AwsEncryptionSDK/runtimes/rust/src/digest.rs deleted file mode 100644 index f3a01ce67..000000000 --- a/AwsEncryptionSDK/runtimes/rust/src/digest.rs +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. -// SPDX-License-Identifier: Apache-2.0 - -#![deny(warnings, unconditional_panic)] -#![deny(nonstandard_style)] -#![deny(clippy::all)] - -use crate::*; -use aws_lc_rs::digest; -use software::amazon::cryptography::primitives::internaldafny::types::DigestAlgorithm; - -impl crate::ExternDigest::_default { - #[allow(non_snake_case)] - pub fn Digest( - digest_algorithm: &::std::rc::Rc, - message: &::dafny_runtime::Sequence, - ) -> ::std::rc::Rc< - _Wrappers_Compile::Result< - ::dafny_runtime::Sequence, - ::std::rc::Rc, - >, - > { - let algorithm = match **digest_algorithm { - DigestAlgorithm::SHA_512 {} => &digest::SHA512, - DigestAlgorithm::SHA_384 {} => &digest::SHA384, - DigestAlgorithm::SHA_256 {} => &digest::SHA256, - }; - let message_vec: Vec = message.iter().collect(); - let result = digest::digest(algorithm, &message_vec); - ::std::rc::Rc::new(_Wrappers_Compile::Result::Success { - value: result.as_ref().iter().cloned().collect(), - }) - } -} diff --git a/AwsEncryptionSDK/runtimes/rust/src/ecdh.rs b/AwsEncryptionSDK/runtimes/rust/src/ecdh.rs deleted file mode 100644 index 15e179505..000000000 --- a/AwsEncryptionSDK/runtimes/rust/src/ecdh.rs +++ /dev/null @@ -1,513 +0,0 @@ -// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. -// SPDX-License-Identifier: Apache-2.0 - -#![deny(warnings, unconditional_panic)] -#![deny(nonstandard_style)] -#![deny(clippy::all)] -#![allow(dead_code)] - -#[allow(non_snake_case)] -pub mod ECDH { - use crate::software::amazon::cryptography::primitives::internaldafny::types::Error as DafnyError; - use std::rc::Rc; - - fn error(s: &str) -> Rc { - Rc::new(DafnyError::AwsCryptographicPrimitivesError { - message: - dafny_runtime::dafny_runtime_conversions::unicode_chars_false::string_to_dafny_string(s), - }) - } - - pub mod ECCUtils { - 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 std::rc::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::SM2 {} => panic!("No SM2 in Rust"), - } - } - // NID_secp224r1 (NIST P-224), - // NID_secp256k1 (SEC/ANSI P-256 K1) - - pub(crate) fn get_alg(x: &ECDHCurveSpec) -> &'static aws_lc_rs::agreement::Algorithm { - match x { - ECDHCurveSpec::ECC_NIST_P256 {} => &aws_lc_rs::agreement::ECDH_P256, - ECDHCurveSpec::ECC_NIST_P384 {} => &aws_lc_rs::agreement::ECDH_P384, - ECDHCurveSpec::ECC_NIST_P521 {} => &aws_lc_rs::agreement::ECDH_P521, - ECDHCurveSpec::SM2 {} => panic!("No SM2 in Rust"), - } - } - - 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 std::ptr::null_mut; - - const ELEM_MAX_BITS: usize = 521; - const ELEM_MAX_BYTES: usize = (ELEM_MAX_BITS + 7) / 8; - const PUBLIC_KEY_MAX_LEN: usize = 1 + (2 * ELEM_MAX_BYTES); - - pub(crate) fn X509_to_X962( - public_key: &[u8], - compress: bool, - nid: Option, - ) -> Result, String> { - let mut cbs = CBS { - data: public_key.as_ptr(), - len: public_key.len(), - }; - - let evp_pkey = unsafe { EVP_parse_public_key(&mut cbs) }; - if evp_pkey.is_null() { - return Err("Invalid X509 Public Key.".to_string()); - } - let ec_key = unsafe { EVP_PKEY_get0_EC_KEY(evp_pkey) }; - - let ec_group = unsafe { EC_KEY_get0_group(ec_key) }; - if ec_group.is_null() { - return Err("Error in EC_KEY_get0_group in X509_to_X962.".to_string()); - } - if nid.is_some() && nid.unwrap() != unsafe { EC_GROUP_get_curve_name(ec_group) } { - return Err("Curve type mismatch in X509_to_X962.".to_string()); - } - let ec_point = unsafe { EC_KEY_get0_public_key(ec_key) }; - if ec_point.is_null() { - return Err("Error in EC_KEY_get0_public_key in X509_to_X962.".to_string()); - } - - let comp = if compress { - aws_lc_sys::point_conversion_form_t::POINT_CONVERSION_COMPRESSED - } else { - aws_lc_sys::point_conversion_form_t::POINT_CONVERSION_UNCOMPRESSED - }; - - let mut out_buf = [0u8; PUBLIC_KEY_MAX_LEN]; - let new_size = unsafe { - EC_POINT_point2oct( - ec_group, - ec_point, - comp, - out_buf.as_mut_ptr(), - PUBLIC_KEY_MAX_LEN, - null_mut(), - ) - }; - unsafe { EVP_PKEY_free(evp_pkey) }; - Ok(out_buf[..new_size].to_vec()) - } - - pub(crate) fn X962_to_X509( - public_key: &[u8], - alg: &ECDHCurveSpec, - ) -> Result, String> { - let ec_group = unsafe { EC_GROUP_new_by_curve_name(get_nid(alg)) }; - let ec_point = unsafe { EC_POINT_new(ec_group) }; - - if 1 != unsafe { - EC_POINT_oct2point( - ec_group, - ec_point, - public_key.as_ptr(), - public_key.len(), - null_mut(), - ) - } { - return Err("Error in EC_POINT_oct2point.".to_string()); - } - - let ec_key = unsafe { EC_KEY_new_by_curve_name(get_nid(alg)) }; - if 1 != unsafe { EC_KEY_set_public_key(ec_key, ec_point) } { - return Err("Error in EC_KEY_set_public_key.".to_string()); - } - - let evp_pkey = unsafe { EVP_PKEY_new() }; - if 1 != unsafe { EVP_PKEY_assign_EC_KEY(evp_pkey, ec_key) } { - return Err("Error in EVP_PKEY_assign_EC_KEY.".to_string()); - } - - let key_size_bytes: usize = unsafe { EVP_PKEY_size(evp_pkey) }.try_into().unwrap(); - let mut cbb: CBB = Default::default(); - unsafe { CBB_init(&mut cbb as *mut CBB, key_size_bytes * 5) }; - - if 1 != unsafe { EVP_marshal_public_key(&mut cbb, evp_pkey) } { - return Err("Error in EVP_marshal_public_key in GetPublicKey.".to_string()); - }; - - let mut out_data = null_mut::(); - let mut out_len: usize = 0; - - if 1 != unsafe { CBB_finish(&mut cbb, &mut out_data, &mut out_len) } { - return Err("Error in CBB_finish in GetPublicKey.".to_string()); - }; - let slice = unsafe { std::slice::from_raw_parts(out_data, out_len) }; - let slice = slice.to_vec(); - - unsafe { OPENSSL_free(out_data as *mut ::std::os::raw::c_void) }; - unsafe { EVP_PKEY_free(evp_pkey) }; - unsafe { EC_POINT_free(ec_point) }; - Ok(slice) - } - - fn inner_get_public_key( - key_bytes: &[u8], - expected_curve_nid: i32, - ) -> Result, String> { - let mut out = null_mut(); - let evp_pkey = unsafe { - aws_lc_sys::d2i_PrivateKey( - EVP_PKEY_EC, - &mut out, - &mut key_bytes.as_ptr(), - key_bytes - .len() - .try_into() - .map_err(|_| "Key too long".to_string())?, - ) - }; - if evp_pkey.is_null() { - return Err("Error in d2i_PrivateKey in GetPublicKey.".to_string()); - } - - let ec_key = unsafe { EVP_PKEY_get0_EC_KEY(evp_pkey) }; - if ec_key.is_null() { - return Err("Error in EVP_PKEY_get0_EC_KEY in GetPublicKey.".to_string()); - } - let ec_group = unsafe { EC_KEY_get0_group(ec_key) }; - if ec_group.is_null() { - return Err("Error in EC_KEY_get0_group in GetPublicKey.".to_string()); - } - let key_nid = unsafe { EC_GROUP_get_curve_name(ec_group) }; - - if key_nid != expected_curve_nid { - return Err("Wrong Algorithm".to_string()); - } - - let key_size_bytes: usize = unsafe { EVP_PKEY_size(evp_pkey) }.try_into().unwrap(); - let mut cbb: CBB = Default::default(); - unsafe { CBB_init(&mut cbb as *mut CBB, key_size_bytes * 5) }; - - if 1 != unsafe { EVP_marshal_public_key(&mut cbb, evp_pkey) } { - return Err("Error in EVP_marshal_public_key in GetPublicKey.".to_string()); - }; - - let mut out_data = null_mut::(); - let mut out_len: usize = 0; - - if 1 != unsafe { CBB_finish(&mut cbb, &mut out_data, &mut out_len) } { - return Err("Error in CBB_finish in GetPublicKey.".to_string()); - }; - let slice = unsafe { std::slice::from_raw_parts(out_data, out_len) }; - let slice = slice.to_vec(); - - unsafe { OPENSSL_free(out_data as *mut ::std::os::raw::c_void) }; - unsafe { EVP_PKEY_free(evp_pkey) }; - 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))?; - inner_get_public_key(private_key.contents(), get_nid(alg)) - } - - fn get_out_of_bounds(curve: &ECDHCurveSpec) -> Vec { - match curve { - ECDHCurveSpec::ECC_NIST_P256 {} => vec![ - 48, 89, 48, 19, 6, 7, 42, 134, 72, 206, 61, 2, 1, 6, 8, 42, 134, 72, 206, 61, - 3, 1, 7, 3, 66, 0, 4, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, - ], - ECDHCurveSpec::ECC_NIST_P384 {} => vec![ - 48, 118, 48, 16, 6, 7, 42, 134, 72, 206, 61, 2, 1, 6, 5, 43, 129, 4, 0, 34, 3, - 98, 0, 4, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, - ], - ECDHCurveSpec::ECC_NIST_P521 {} => vec![ - 48, 129, 155, 48, 16, 6, 7, 42, 134, 72, 206, 61, 2, 1, 6, 5, 43, 129, 4, 0, - 35, 3, 129, 134, 0, 4, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, - ], - ECDHCurveSpec::SM2 {} => vec![], - } - } - pub fn GetOutOfBoundsPublicKey( - curve_algorithm: &Rc, - ) -> Rc<_Wrappers_Compile::Result<::dafny_runtime::Sequence, Rc>> { - let result = get_out_of_bounds(curve_algorithm); - Rc::new(_Wrappers_Compile::Result::Success { - value: result.iter().cloned().collect(), - }) - } - - fn get_infinity(curve: &ECDHCurveSpec) -> Vec { - match curve { - ECDHCurveSpec::ECC_NIST_P256 {} => vec![ - 48, 25, 48, 19, 6, 7, 42, 134, 72, 206, 61, 2, 1, 6, 8, 42, 134, 72, 206, 61, - 3, 1, 7, 3, 2, 0, 0, - ], - ECDHCurveSpec::ECC_NIST_P384 {} => vec![ - 48, 22, 48, 16, 6, 7, 42, 134, 72, 206, 61, 2, 1, 6, 5, 43, 129, 4, 0, 34, 3, - 2, 0, 0, - ], - ECDHCurveSpec::ECC_NIST_P521 {} => vec![ - 48, 22, 48, 16, 6, 7, 42, 134, 72, 206, 61, 2, 1, 6, 5, 43, 129, 4, 0, 35, 3, - 2, 0, 0, - ], - ECDHCurveSpec::SM2 {} => vec![], - } - } - - pub fn GetInfinityPublicKey( - curve_algorithm: &Rc, - ) -> Rc<_Wrappers_Compile::Result<::dafny_runtime::Sequence, Rc>> { - let result = get_infinity(curve_algorithm); - Rc::new(_Wrappers_Compile::Result::Success { - value: result.iter().cloned().collect(), - }) - } - pub fn GetPublicKey( - curve_algorithm: &Rc, - private_key: &Rc, - ) -> Rc<_Wrappers_Compile::Result<::dafny_runtime::Sequence, Rc>> { - let private_key: Vec = private_key.pem().iter().collect(); - match get_public_key(curve_algorithm, &private_key) { - Ok(x) => Rc::new(_Wrappers_Compile::Result::Success { - value: x.iter().cloned().collect(), - }), - Err(e) => { - let msg = format!("ECDH Get Public Key : {}", e); - Rc::new(_Wrappers_Compile::Result::Failure { - error: super::error(&msg), - }) - } - } - } - - // for the moment, it's valid if we can use it to generate a shared secret - fn valid_public_key(alg: &ECDHCurveSpec, public_key: &[u8]) -> Result<(), String> { - X509_to_X962(public_key, false, Some(get_nid(alg)))?; - Ok(()) - } - - pub fn ValidatePublicKey( - curve_algorithm: &Rc, - public_key: &::dafny_runtime::Sequence, - ) -> Rc<_Wrappers_Compile::Result>> { - let public_key: Vec = public_key.iter().collect(); - match valid_public_key(curve_algorithm, &public_key) { - Ok(_) => Rc::new(_Wrappers_Compile::Result::Success { value: true }), - Err(e) => Rc::new(_Wrappers_Compile::Result::Failure { - error: super::error(&e), - }), - } - } - - pub fn CompressPublicKey( - public_key: &::dafny_runtime::Sequence, - _curve_algorithm: &Rc, - ) -> Rc<_Wrappers_Compile::Result<::dafny_runtime::Sequence, Rc>> { - let public_key: Vec = public_key.iter().collect(); - match X509_to_X962(&public_key, true, None) { - Ok(v) => Rc::new(_Wrappers_Compile::Result::Success { - value: v.iter().cloned().collect(), - }), - Err(e) => { - let msg = format!("ECDH Compress Public Key {}", e); - Rc::new(_Wrappers_Compile::Result::Failure { - error: super::error(&msg), - }) - } - } - } - - pub fn DecompressPublicKey( - public_key: &::dafny_runtime::Sequence, - curve_algorithm: &Rc, - ) -> Rc<_Wrappers_Compile::Result<::dafny_runtime::Sequence, Rc>> { - let public_key: Vec = public_key.iter().collect(); - match X962_to_X509(&public_key, curve_algorithm) { - Ok(v) => Rc::new(_Wrappers_Compile::Result::Success { - value: v.iter().cloned().collect(), - }), - Err(e) => { - let msg = format!("ECDH Decompress Public Key {}", e); - Rc::new(_Wrappers_Compile::Result::Failure { - error: super::error(&msg), - }) - } - } - } - - pub fn ParsePublicKey( - publicKey: &::dafny_runtime::Sequence, - ) -> Rc<_Wrappers_Compile::Result<::dafny_runtime::Sequence, Rc>> { - let public_key: Vec = publicKey.iter().collect(); - match X509_to_X962(&public_key, false, None) { - Ok(_) => Rc::new(_Wrappers_Compile::Result::Success { - value: publicKey.clone(), - }), - Err(e) => Rc::new(_Wrappers_Compile::Result::Failure { - error: super::error(&e), - }), - } - } - } - pub mod DeriveSharedSecret { - use crate::software::amazon::cryptography::primitives::internaldafny::types::ECDHCurveSpec; - use crate::software::amazon::cryptography::primitives::internaldafny::types::Error as DafnyError; - use crate::*; - use std::rc::Rc; - - pub fn agree( - curve_algorithm: &ECDHCurveSpec, - 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 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))?; - 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), - &public_key, - ); - let shared: Vec = - aws_lc_rs::agreement::agree(&private_key, &public_key, "foo", |x| Ok(x.to_vec())) - .map_err(|_e| "Failure in aws_lc_rs::agreement::agree.".to_string())?; - Ok(shared) - } - pub fn CalculateSharedSecret( - curve_algorithm: &Rc, - private_key: &Rc, - public_key: &Rc, - ) -> Rc<_Wrappers_Compile::Result<::dafny_runtime::Sequence, Rc>> { - let private_key: Vec = private_key.pem().iter().collect(); - let public_key: Vec = public_key.der().iter().collect(); - match agree(curve_algorithm, &private_key, &public_key) { - Ok(v) => Rc::new(_Wrappers_Compile::Result::Success { - value: v.iter().cloned().collect(), - }), - Err(e) => { - let msg = format!("ECDH Calculate Shared Secret : {}", e); - Rc::new(_Wrappers_Compile::Result::Failure { - error: super::error(&msg), - }) - } - } - } - } - pub mod KeyGeneration { - 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_rs::encoding::AsDer; - use aws_lc_rs::encoding::EcPrivateKeyRfc5915Der; - use std::rc::Rc; - - 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))?; - - let public_key = private_key - .compute_public_key() - .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))?; - 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(); - - Ok((public_key, private_key)) - } - - pub fn GenerateKeyPair( - s: &Rc, - ) -> Rc<_Wrappers_Compile::Result, Rc>> { - match ecdsa_key_gen(s) { - Ok(x) => Rc::new(_Wrappers_Compile::Result::Success { - value: Rc::new(crate::ECDH::EccKeyPair::EccKeyPair { - publicKey: x.0.iter().cloned().collect(), - privateKey: x.1.iter().cloned().collect(), - }), - }), - Err(e) => { - let msg = format!("ECDH Generate Key Pair : {}", e); - Rc::new(_Wrappers_Compile::Result::Failure { - error: super::error(&msg), - }) - } - } - } - } - #[cfg(test)] - mod tests { - use super::*; - use crate::software::amazon::cryptography::primitives::internaldafny::types::ECDHCurveSpec; - use crate::*; - use std::rc::Rc; - - #[test] - fn test_generate() { - let alg = Rc::new(ECDHCurveSpec::ECC_NIST_P256 {}); - - let pair: crate::ECDH::EccKeyPair = match &*KeyGeneration::GenerateKeyPair(&alg) { - _Wrappers_Compile::Result::Success { value } => (**value).clone(), - _Wrappers_Compile::Result::Failure { error } => panic!("{:?}", error), - }; - - match &*ECCUtils::ValidatePublicKey(&alg, pair.publicKey()) { - _Wrappers_Compile::Result::Success { .. } => {} - _Wrappers_Compile::Result::Failure { error } => panic!("{:?}", error), - }; - } - } -} diff --git a/AwsEncryptionSDK/runtimes/rust/src/ecdsa.rs b/AwsEncryptionSDK/runtimes/rust/src/ecdsa.rs deleted file mode 100644 index 5daf10d8f..000000000 --- a/AwsEncryptionSDK/runtimes/rust/src/ecdsa.rs +++ /dev/null @@ -1,276 +0,0 @@ -// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. -// SPDX-License-Identifier: Apache-2.0 - -#![deny(warnings, unconditional_panic)] -#![deny(nonstandard_style)] -#![deny(clippy::all)] - -#[allow(non_snake_case)] -pub mod Signature { - pub mod ECDSA { - use crate::software::amazon::cryptography::primitives::internaldafny::types::ECDSASignatureAlgorithm; - use crate::software::amazon::cryptography::primitives::internaldafny::types::Error as DafnyError; - use crate::*; - use aws_lc_rs::encoding::AsDer; - use aws_lc_rs::rand::SystemRandom; - use aws_lc_rs::signature::EcdsaKeyPair; - use aws_lc_rs::signature::EcdsaSigningAlgorithm; - use aws_lc_rs::signature::EcdsaVerificationAlgorithm; - use aws_lc_rs::signature::KeyPair; - use aws_lc_rs::signature::UnparsedPublicKey; - use std::rc::Rc; - - fn error(s: &str) -> Rc { - Rc::new(DafnyError::AwsCryptographicPrimitivesError { - message: - dafny_runtime::dafny_runtime_conversions::unicode_chars_false::string_to_dafny_string(s), - }) - } - - fn get_alg(x: &ECDSASignatureAlgorithm) -> &'static EcdsaSigningAlgorithm { - match x { - ECDSASignatureAlgorithm::ECDSA_P256 {} => { - // &aws_lc_rs::signature::ECDSA_P256_SHA256_FIXED_SIGNING - &aws_lc_rs::signature::ECDSA_P256_SHA256_ASN1_SIGNING - } - ECDSASignatureAlgorithm::ECDSA_P384 {} => { - // &aws_lc_rs::signature::ECDSA_P384_SHA384_FIXED_SIGNING - &aws_lc_rs::signature::ECDSA_P384_SHA384_ASN1_SIGNING - } - } - } - - fn get_ver_alg(x: &ECDSASignatureAlgorithm) -> &'static EcdsaVerificationAlgorithm { - match x { - ECDSASignatureAlgorithm::ECDSA_P256 {} => { - // &aws_lc_rs::signature::ECDSA_P256_SHA256_FIXED - &aws_lc_rs::signature::ECDSA_P256_SHA256_ASN1 - } - ECDSASignatureAlgorithm::ECDSA_P384 {} => { - // &aws_lc_rs::signature::ECDSA_P384_SHA384_FIXED - &aws_lc_rs::signature::ECDSA_P384_SHA384_ASN1 - } - } - } - - 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, - } - } - - const ELEM_MAX_BITS: usize = 521; - const ELEM_MAX_BYTES: usize = (ELEM_MAX_BITS + 7) / 8; - const PUBLIC_KEY_MAX_LEN: usize = 1 + (2 * ELEM_MAX_BYTES); - - pub(crate) fn sec1_compress( - data: &[u8], - alg: &ECDSASignatureAlgorithm, - ) -> Result, String> { - sec1_convert( - data, - get_nid(alg), - aws_lc_sys::point_conversion_form_t::POINT_CONVERSION_COMPRESSED, - ) - } - - pub(crate) fn sec1_convert( - data: &[u8], - nid: i32, - form: aws_lc_sys::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 std::ptr::null_mut; - - // no need to free ec_group - let ec_group = unsafe { EC_GROUP_new_by_curve_name(nid) }; - if ec_group.is_null() { - return Err("EC_GROUP_new_by_curve_name returned failure.".to_string()); - } - - let ec_point = unsafe { EC_POINT_new(ec_group) }; - if ec_point.is_null() { - return Err("EC_POINT_new returned failure.".to_string()); - } - let mut out_buf = [0u8; PUBLIC_KEY_MAX_LEN]; - - let ret = unsafe { - EC_POINT_oct2point(ec_group, ec_point, data.as_ptr(), data.len(), null_mut()) - }; - if ret == 0 { - return Err("EC_POINT_oct2point returned failure.".to_string()); - } - let new_size: usize = unsafe { - EC_POINT_point2oct( - ec_group, - ec_point, - form, - out_buf.as_mut_ptr(), - PUBLIC_KEY_MAX_LEN, - null_mut(), - ) - }; - unsafe { EC_POINT_free(ec_point) }; - Ok(out_buf[..new_size].to_vec()) - } - - fn ecdsa_key_gen(alg: &ECDSASignatureAlgorithm) -> Result<(Vec, Vec), String> { - 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(); - Ok((public_key, private_key)) - } - - pub fn ExternKeyGen( - alg: &Rc, - ) -> Rc<_Wrappers_Compile::Result, Rc>> - { - match ecdsa_key_gen(alg) { - Ok(x) => Rc::new(_Wrappers_Compile::Result::Success { - value: Rc::new(Signature::SignatureKeyPair::SignatureKeyPair { - verificationKey: x.0.iter().cloned().collect(), - signingKey: x.1.iter().cloned().collect(), - }), - }), - Err(e) => { - let msg = format!("ECDSA Key Gen : {}", e); - Rc::new(_Wrappers_Compile::Result::Failure { error: error(&msg) }) - } - } - } - - fn ecdsa_sign_inner( - alg: &ECDSASignatureAlgorithm, - key: &[u8], - msg: &[u8], - ) -> Result, String> { - let private_key = EcdsaKeyPair::from_private_key_der(get_alg(alg), key) - .map_err(|e| format!("{:?}", e))?; - let rng = SystemRandom::new(); - let sig = private_key - .sign(&rng, msg) - .map_err(|e| format!("{:?}", e))?; - Ok(sig.as_ref().to_vec()) - } - fn ecdsa_sign( - alg: &ECDSASignatureAlgorithm, - key: &[u8], - msg: &[u8], - ) -> Result, String> { - loop { - let result = ecdsa_sign_inner(alg, key, msg)?; - if result.len() == 103 { - return Ok(result); - } - } - } - - pub fn Sign( - alg: &Rc, - key: &::dafny_runtime::Sequence, - msg: &::dafny_runtime::Sequence, - ) -> Rc<_Wrappers_Compile::Result<::dafny_runtime::Sequence, Rc>> { - let key: Vec = key.iter().collect(); - let msg: Vec = msg.iter().collect(); - match ecdsa_sign(alg, &key, &msg) { - Ok(x) => Rc::new(_Wrappers_Compile::Result::Success { - value: x.iter().cloned().collect(), - }), - Err(e) => { - let msg = format!("ECDSA Sign : {}", e); - Rc::new(_Wrappers_Compile::Result::Failure { error: error(&msg) }) - } - } - } - - fn ecdsa_verify( - alg: &ECDSASignatureAlgorithm, - key: &[u8], - msg: &[u8], - sig: &[u8], - ) -> Result { - let public_key = UnparsedPublicKey::new(get_ver_alg(alg), key); - match public_key.verify(msg, sig) { - Ok(_) => Ok(true), - Err(_) => Ok(false), - } - } - - pub fn Verify( - alg: &Rc, - key: &::dafny_runtime::Sequence, - msg: &::dafny_runtime::Sequence, - sig: &::dafny_runtime::Sequence, - ) -> Rc<_Wrappers_Compile::Result>> { - let key: Vec = key.iter().collect(); - let msg: Vec = msg.iter().collect(); - let sig: Vec = sig.iter().collect(); - 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); - Rc::new(_Wrappers_Compile::Result::Failure { error: error(&msg) }) - } - } - } - #[cfg(test)] - mod tests { - use super::*; - use std::rc::Rc; - - #[test] - fn test_generate() { - let alg = Rc::new(ECDSASignatureAlgorithm::ECDSA_P384 {}); - let key_pair = match &*ExternKeyGen(&alg) { - _Wrappers_Compile::Result::Success { value } => value.clone(), - _Wrappers_Compile::Result::Failure { error } => { - panic!("ExternKeyGen Failed : {:?}", error); - } - }; - - let (s_key, v_key) = match &*key_pair { - Signature::SignatureKeyPair::SignatureKeyPair { - signingKey, - verificationKey, - } => (signingKey, verificationKey), - }; - - let message: ::dafny_runtime::Sequence = - [1u8, 2, 3, 4, 5].iter().cloned().collect(); - - let sig = match &*Sign(&alg, &s_key, &message) { - _Wrappers_Compile::Result::Success { value } => value.clone(), - _Wrappers_Compile::Result::Failure { error } => { - panic!("Sign Failed : {:?}", error); - } - }; - - let ver: bool = match &*Verify(&alg, &v_key, &message, &sig) { - _Wrappers_Compile::Result::Success { value } => value.clone(), - _Wrappers_Compile::Result::Failure { error } => { - panic!("Verify Failed : {:?}", error); - } - }; - assert!(ver); - - let mut sig_vec: Vec = sig.iter().collect(); - 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(), - _Wrappers_Compile::Result::Failure { error } => { - panic!("Verify Failed : {:?}", error); - } - }; - assert!(!ver2); - } - } - } -} diff --git a/AwsEncryptionSDK/runtimes/rust/src/error.rs b/AwsEncryptionSDK/runtimes/rust/src/error.rs deleted file mode 100644 index 4cddaa7c3..000000000 --- a/AwsEncryptionSDK/runtimes/rust/src/error.rs +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. -// SPDX-License-Identifier: Apache-2.0 -// Do not modify this file. This file is machine generated, and any changes to it will be overwritten. -pub use ::aws_smithy_runtime_api::box_error::BoxError; - -/// Error type returned by the client. -pub type SdkError = - ::aws_smithy_runtime_api::client::result::SdkError; -pub use ::aws_smithy_runtime_api::client::result::ConnectorError; -pub use ::aws_smithy_types::error::operation::BuildError; - -pub use ::aws_smithy_types::error::display::DisplayErrorContext; -pub use ::aws_smithy_types::error::metadata::ErrorMetadata; -pub use ::aws_smithy_types::error::metadata::ProvideErrorMetadata; - -pub(crate) mod sealed_unhandled; diff --git a/AwsEncryptionSDK/runtimes/rust/src/hmac.rs b/AwsEncryptionSDK/runtimes/rust/src/hmac.rs deleted file mode 100644 index 4f8abc4e2..000000000 --- a/AwsEncryptionSDK/runtimes/rust/src/hmac.rs +++ /dev/null @@ -1,121 +0,0 @@ -// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. -// SPDX-License-Identifier: Apache-2.0 - -#![deny(warnings, unconditional_panic)] -#![deny(nonstandard_style)] -#![deny(clippy::all)] - -use crate::software::amazon::cryptography::primitives::internaldafny::types::DigestAlgorithm; -use crate::*; -use aws_lc_rs::hmac; - -fn convert_algorithm(input: &DigestAlgorithm) -> hmac::Algorithm { - match input { - DigestAlgorithm::SHA_512 {} => hmac::HMAC_SHA512, - DigestAlgorithm::SHA_384 {} => hmac::HMAC_SHA384, - DigestAlgorithm::SHA_256 {} => hmac::HMAC_SHA256, - } -} - -// Let's implement HMAC::_default::Digest -impl crate::HMAC::_default { - #[allow(non_snake_case)] - pub fn Digest( - input: &::std::rc::Rc< - crate::software::amazon::cryptography::primitives::internaldafny::types::HMacInput, - >, - ) -> ::std::rc::Rc< - _Wrappers_Compile::Result< - ::dafny_runtime::Sequence, - ::std::rc::Rc, - >, - > { - let key_vec: Vec = input.key().iter().collect(); - let the_key = hmac::Key::new(convert_algorithm(input.digestAlgorithm()), &key_vec); - let message_vec: Vec = input.message().iter().collect(); - let result = hmac::sign(&the_key, &message_vec); - ::std::rc::Rc::new(_Wrappers_Compile::Result::Success { - value: result.as_ref().iter().cloned().collect(), - }) - } -} - -#[allow(non_snake_case)] -pub mod HMAC { - use crate::*; - use aws_lc_rs::hmac; - use std::cell::RefCell; - #[allow(non_camel_case_types)] - pub struct _default {} - - #[derive(Debug)] - pub struct HMacInner { - context: Option, - key: Option, - } - pub struct HMac { - algorithm: hmac::Algorithm, - inner: RefCell, - } - - impl dafny_runtime::UpcastObject for HMac { - dafny_runtime::UpcastObjectFn!(dyn std::any::Any); - } - - impl HMac { - pub fn Init(&self, salt: &::dafny_runtime::Sequence) { - let salt: Vec = salt.iter().collect(); - self.inner.borrow_mut().key = Some(hmac::Key::new(self.algorithm, &salt)); - let context = Some(hmac::Context::with_key(self.inner.borrow().key.as_ref().unwrap())); - self.inner.borrow_mut().context = context; - } - pub fn re_init(&self) { - let context = Some(hmac::Context::with_key( - self.inner.borrow().key.as_ref().unwrap(), - )); - self.inner.borrow_mut().context = context; - } - pub fn Build( - input: &::std::rc::Rc< - software::amazon::cryptography::primitives::internaldafny::types::DigestAlgorithm, - >, - ) -> ::std::rc::Rc< - _Wrappers_Compile::Result< - ::dafny_runtime::Object, - ::std::rc::Rc< - software::amazon::cryptography::primitives::internaldafny::types::Error, - >, - >, - > { - let inner = dafny_runtime::Object::new(Self { - algorithm: super::convert_algorithm(input), - inner: RefCell::new(HMacInner { - context: None, - key: None, - }), - }); - - ::std::rc::Rc::new(_Wrappers_Compile::Result::Success { value: inner }) - } - pub fn BlockUpdate(&self, block: &::dafny_runtime::Sequence) { - let part: Vec = block.iter().collect(); - self.inner - .borrow_mut() - .context - .as_mut() - .unwrap() - .update(&part); - } - pub fn GetResult(&self) -> ::dafny_runtime::Sequence { - let is_empty = self.inner.borrow().context.is_none(); - if is_empty { - return [].iter().cloned().collect(); - } - let tag = self.inner.borrow_mut().context.take().unwrap().sign(); - // other languages allow you to call BlockUpdate after GetResult - // so we re-initialize to mimic that behavior - self.re_init(); - tag.as_ref().iter().cloned().collect() - } - } -} diff --git a/AwsEncryptionSDK/runtimes/rust/src/kms.rs b/AwsEncryptionSDK/runtimes/rust/src/kms.rs deleted file mode 100644 index 571a3b3fa..000000000 --- a/AwsEncryptionSDK/runtimes/rust/src/kms.rs +++ /dev/null @@ -1,88 +0,0 @@ -// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. -// SPDX-License-Identifier: Apache-2.0 - -#![deny(warnings, unconditional_panic)] -#![deny(nonstandard_style)] -#![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)] - pub fn KMSClientForRegion(region: &::dafny_runtime::Sequence<::dafny_runtime::DafnyCharUTF16>) -> ::std::rc::Rc, ::std::rc::Rc>>{ - let region = - dafny_runtime::dafny_runtime_conversions::unicode_chars_false::dafny_string_to_string( - region, - ); - - 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)) - .build(); - 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)); - std::rc::Rc::new(crate::r#_Wrappers_Compile::Result::Success { - value: dafny_client, - }) - } - - #[allow(non_snake_case)] - pub fn KMSClient() -> ::std::rc::Rc, ::std::rc::Rc>>{ - 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)); - std::rc::Rc::new(crate::r#_Wrappers_Compile::Result::Success { - value: dafny_client, - }) - } - - #[allow(non_snake_case)] - pub fn RegionMatch( - kmsClient: &::dafny_runtime::Object, - region: &::dafny_runtime::Sequence<::dafny_runtime::DafnyCharUTF16>, - ) -> ::std::rc::Rc> { - let region = - dafny_runtime::dafny_runtime_conversions::unicode_chars_false::dafny_string_to_string( - region, - ); - let any = dafny_runtime::cast_any_object!(kmsClient); - let client = - dafny_runtime::cast_object!(any, crate::deps::com_amazonaws_kms::client::Client); - let flag = match client.as_ref().inner.config().region() { - Some(r) => r.as_ref() == region, - None => false, - }; - ::std::rc::Rc::new(crate::r#_Wrappers_Compile::Option::Some { value: flag }) - } -} diff --git a/AwsEncryptionSDK/runtimes/rust/src/local_cmc.rs b/AwsEncryptionSDK/runtimes/rust/src/local_cmc.rs deleted file mode 100644 index c12c67f4f..000000000 --- a/AwsEncryptionSDK/runtimes/rust/src/local_cmc.rs +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. -// SPDX-License-Identifier: Apache-2.0 - -#![deny(warnings, unconditional_panic)] -#![deny(nonstandard_style)] -#![deny(clippy::all)] - -#[allow(non_snake_case)] -pub mod internal_SynchronizedLocalCMC { - use crate::*; - use std::sync::Mutex; - - pub struct SynchronizedLocalCMC { - wrapped: Mutex<::dafny_runtime::Object<_LocalCMC_Compile::LocalCMC>>, - } - - impl SynchronizedLocalCMC { - pub fn _allocate_object( - cmc: ::dafny_runtime::Object<_LocalCMC_Compile::LocalCMC>, - ) -> ::dafny_runtime::Object { - ::dafny_runtime::Object::new(SynchronizedLocalCMC { - wrapped: Mutex::new(cmc), - }) - } - } - - impl ::dafny_runtime::UpcastObject for SynchronizedLocalCMC { - ::dafny_runtime::UpcastObjectFn!(dyn ::std::any::Any); - } - - impl ::dafny_runtime::UpcastObject - for SynchronizedLocalCMC { - ::dafny_runtime::UpcastObjectFn!(dyn software::amazon::cryptography::materialproviders::internaldafny::types::ICryptographicMaterialsCache); - } - - impl software::amazon::cryptography::materialproviders::internaldafny::types::ICryptographicMaterialsCache for SynchronizedLocalCMC { - fn r#_PutCacheEntry_k(&self, input: &std::rc::Rc) -> std::rc::Rc>> { - self.wrapped.lock().unwrap().as_mut()._PutCacheEntry_k(input) - } - - fn r#_UpdateUsageMetadata_k(&self, input: &std::rc::Rc) -> std::rc::Rc>> { - self.wrapped.lock().unwrap().as_mut()._UpdateUsageMetadata_k(input) - } - - fn r#_GetCacheEntry_k(&self, input: &std::rc::Rc) -> std::rc::Rc, std::rc::Rc>> { - self.wrapped.lock().unwrap().as_mut()._GetCacheEntry_k(input) - } - - fn r#_DeleteCacheEntry_k(&self, input: &std::rc::Rc) -> std::rc::Rc>> { - self.wrapped.lock().unwrap().as_mut()._DeleteCacheEntry_k(input) - } - } -} diff --git a/AwsEncryptionSDK/runtimes/rust/src/operation.rs b/AwsEncryptionSDK/runtimes/rust/src/operation.rs deleted file mode 100644 index 666ecbab2..000000000 --- a/AwsEncryptionSDK/runtimes/rust/src/operation.rs +++ /dev/null @@ -1,8 +0,0 @@ -// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. -// SPDX-License-Identifier: Apache-2.0 -// Do not modify this file. This file is machine generated, and any changes to it will be overwritten. -/// Types for the `Decrypt` operation. -pub mod decrypt; - -/// Types for the `Encrypt` operation. -pub mod encrypt; diff --git a/AwsEncryptionSDK/runtimes/rust/src/random.rs b/AwsEncryptionSDK/runtimes/rust/src/random.rs deleted file mode 100644 index 437a22c69..000000000 --- a/AwsEncryptionSDK/runtimes/rust/src/random.rs +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. -// SPDX-License-Identifier: Apache-2.0 - -#![deny(warnings, unconditional_panic)] -#![deny(nonstandard_style)] -#![deny(clippy::all)] - -use crate::*; -use aws_lc_rs::rand; - -impl crate::ExternRandom::_default { - #[allow(non_snake_case)] - pub fn GenerateBytes( - num_bytes: i32, - ) -> ::std::rc::Rc< - _Wrappers_Compile::Result< - ::dafny_runtime::Sequence, - ::std::rc::Rc, - >, - > { - let mut rand_bytes: Vec = vec![0; num_bytes as usize]; - match rand::fill(&mut rand_bytes) { - Ok(_) => { - ::std::rc::Rc::new( - _Wrappers_Compile::Result::Success{value : - dafny_runtime::dafny_runtime_conversions::vec_to_dafny_sequence(&rand_bytes, |x| *x) - } - ) - } - Err(_) => { - std::rc::Rc::new(_Wrappers_Compile::Result::Failure{ error : std::rc::Rc::new( - software::amazon::cryptography::primitives::internaldafny::types::Error::AwsCryptographicPrimitivesError{ - message : dafny_runtime::dafny_runtime_conversions::unicode_chars_false::string_to_dafny_string("Error generating random bytes.") - })}) - } - } - } -} diff --git a/AwsEncryptionSDK/runtimes/rust/src/rsa.rs b/AwsEncryptionSDK/runtimes/rust/src/rsa.rs deleted file mode 100644 index 9bb76d9cc..000000000 --- a/AwsEncryptionSDK/runtimes/rust/src/rsa.rs +++ /dev/null @@ -1,256 +0,0 @@ -// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. -// SPDX-License-Identifier: Apache-2.0 - -#![deny(warnings, unconditional_panic)] -#![deny(nonstandard_style)] -#![deny(clippy::all)] - -// Extern methods with a foreign module name -#[allow(non_snake_case)] -pub mod RSAEncryption { - pub mod RSA { - use crate::_Wrappers_Compile as Wrappers; - use crate::software::amazon::cryptography::primitives::internaldafny::types::RSAPaddingMode; - use crate::*; - use ::std::rc::Rc; - use aws_lc_rs::encoding::{AsDer, Pkcs8V1Der, PublicKeyX509Der}; - - use aws_lc_rs::rsa::KeySize; - use aws_lc_rs::rsa::OaepAlgorithm; - use aws_lc_rs::rsa::OaepPrivateDecryptingKey; - use aws_lc_rs::rsa::OaepPublicEncryptingKey; - use aws_lc_rs::rsa::Pkcs1PrivateDecryptingKey; - use aws_lc_rs::rsa::Pkcs1PublicEncryptingKey; - use aws_lc_rs::rsa::PrivateDecryptingKey; - use aws_lc_rs::rsa::PublicEncryptingKey; - use pem; - use software::amazon::cryptography::primitives::internaldafny::types::Error as DafnyError; - - pub fn key_size_from_length(length: i32) -> KeySize { - match length { - 2048 => KeySize::Rsa2048, - 3072 => KeySize::Rsa3072, - 4096 => KeySize::Rsa4096, - 8192 => KeySize::Rsa8192, - _ => panic!("Bad length for GenerateKeyPair"), - } - } - - fn error(s: &str) -> Rc { - Rc::new(DafnyError::AwsCryptographicPrimitivesError { - message: - dafny_runtime::dafny_runtime_conversions::unicode_chars_false::string_to_dafny_string(s), - }) - } - - 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))?; - - // 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))?; - - // 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))?; - - let public_key = pem::Pem::new("RSA PUBLIC KEY", public_key_der.as_ref()); - let public_key = pem::encode(&public_key); - let private_key = pem::Pem::new("RSA PRIVATE KEY", private_key_der.as_ref()); - let private_key = pem::encode(&private_key); - - Ok((public_key.into(), private_key.into())) - } - #[allow(non_snake_case)] - pub fn GenerateKeyPairExtern( - length_bits: i32, - ) -> (::dafny_runtime::Sequence, ::dafny_runtime::Sequence) { - match generate_key_pair(length_bits) { - Ok(x) => (x.0.iter().cloned().collect(), x.1.iter().cloned().collect()), - Err(e) => { - panic!("Unexpected error generating RSA Key Pair{}", e); - } - } - } - - fn get_alg_for_padding(mode: &RSAPaddingMode) -> Result<&'static OaepAlgorithm, String> { - match mode { - RSAPaddingMode::PKCS1 {} => { - Err("No support for RSA with PKCS1 in Rust.".to_string()) - } - RSAPaddingMode::OAEP_SHA1 {} => Ok(&aws_lc_rs::rsa::OAEP_SHA1_MGF1SHA1), - RSAPaddingMode::OAEP_SHA256 {} => Ok(&aws_lc_rs::rsa::OAEP_SHA256_MGF1SHA256), - RSAPaddingMode::OAEP_SHA384 {} => Ok(&aws_lc_rs::rsa::OAEP_SHA384_MGF1SHA384), - RSAPaddingMode::OAEP_SHA512 {} => Ok(&aws_lc_rs::rsa::OAEP_SHA512_MGF1SHA512), - } - } - - 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 = PublicEncryptingKey::from_der(public_key.contents()) - .map_err(|e| format!("{:?}", e))?; - Ok(public_key.key_size_bits() as u32) - } - - #[allow(non_snake_case)] - pub fn GetRSAKeyModulusLengthExtern( - public_key: &::dafny_runtime::Sequence, - ) -> Rc>> { - let public_key: Vec = public_key.iter().collect(); - match get_modulus(&public_key) { - Ok(v) => Rc::new(Wrappers::Result::Success { value: v }), - Err(e) => Rc::new(Wrappers::Result::Failure { error: error(&e) }), - } - } - - fn decrypt_extern( - mode: &RSAPaddingMode, - private_key: &[u8], - 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))?; - 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))?; - let private_key = - 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))?; - Ok(message.to_vec()) - } - - #[allow(non_snake_case)] - pub fn DecryptExtern( - mode: &RSAPaddingMode, - private_key: &::dafny_runtime::Sequence, - cipher_text: &::dafny_runtime::Sequence, - ) -> Rc, Rc>> { - let private_key: Vec = private_key.iter().collect(); - let cipher_text: Vec = cipher_text.iter().collect(); - match decrypt_extern(mode, &private_key, &cipher_text) { - Ok(x) => Rc::new(Wrappers::Result::Success { - value: x.iter().cloned().collect(), - }), - Err(e) => { - let msg = format!("RSA Decrypt : {}", e); - Rc::new(Wrappers::Result::Failure { error: error(&msg) }) - } - } - } - - fn encrypt_extern( - mode: &RSAPaddingMode, - 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))?; - 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))?; - let public_key = - 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))?; - Ok(cipher_text.to_vec()) - } - - #[allow(non_snake_case)] - pub fn EncryptExtern( - mode: &RSAPaddingMode, - public_key: &::dafny_runtime::Sequence, - message: &::dafny_runtime::Sequence, - ) -> Rc, Rc>> { - let public_key: Vec = public_key.iter().collect(); - let message: Vec = message.iter().collect(); - match encrypt_extern(mode, &public_key, &message) { - Ok(x) => Rc::new(Wrappers::Result::Success { - value: x.iter().cloned().collect(), - }), - Err(e) => { - let msg = format!("RSA Encrypt : {}", e); - Rc::new(Wrappers::Result::Failure { error: error(&msg) }) - } - } - } - - 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))?; - let public_key = - 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))?; - 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))?; - let mut message: Vec = vec![0; cipher_text.len()]; - let message = private_key - .decrypt(cipher_text, &mut message) - .map_err(|e| format!("decrypt {:?}", e))?; - Ok(message.to_vec()) - } - - #[cfg(test)] - mod tests { - use super::*; - #[test] - fn test_generate() { - let (public_key, private_key) = GenerateKeyPairExtern(2048); - - let modulus: u32 = match &*GetRSAKeyModulusLengthExtern(&public_key) { - Wrappers::Result::Success { value } => *value, - Wrappers::Result::Failure { error } => panic!("{:?}", error), - }; - assert_eq!(modulus, 2048); - - let mode = RSAPaddingMode::OAEP_SHA256 {}; - - let plain_text: ::dafny_runtime::Sequence = - [1u8, 2, 3, 4, 5].iter().cloned().collect(); - - let cipher: ::dafny_runtime::Sequence = - match &*EncryptExtern(&mode, &public_key, &plain_text) { - Wrappers::Result::Success { value } => value.clone(), - 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), - }; - - assert_eq!(plain_text, message); - } - } - } -} diff --git a/AwsEncryptionSDK/runtimes/rust/src/sets.rs b/AwsEncryptionSDK/runtimes/rust/src/sets.rs deleted file mode 100644 index 755615ddb..000000000 --- a/AwsEncryptionSDK/runtimes/rust/src/sets.rs +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. -// SPDX-License-Identifier: Apache-2.0 - -#![deny(warnings, unconditional_panic)] -#![deny(nonstandard_style)] -#![deny(clippy::all)] - -#[allow(non_snake_case)] -#[allow(clippy::type_complexity)] -pub mod SortedSets { - use std::cmp::Ordering; - - #[allow(non_camel_case_types)] - pub struct _default {} - impl _default { - pub fn SetToSequence( - elems: &::dafny_runtime::Set, - ) -> ::dafny_runtime::Sequence { - elems.iter().cloned().collect() - } - - pub fn SetToOrderedSequence( - elems: &::dafny_runtime::Set<::dafny_runtime::Sequence>, - less: &::std::rc::Rc bool>, - ) -> ::dafny_runtime::Sequence<::dafny_runtime::Sequence> { - let mut vec = elems.iter().cloned().collect::>(); - vec.sort_by(|a, b| Self::order(a, b, less)); - dafny_runtime::dafny_runtime_conversions::vec_to_dafny_sequence(&vec, |x| x.clone()) - } - - pub fn SetToOrderedSequence2( - elems: &::dafny_runtime::Set<::dafny_runtime::Sequence>, - less: &::std::rc::Rc bool>, - ) -> ::dafny_runtime::Sequence<::dafny_runtime::Sequence> { - Self::SetToOrderedSequence(elems, less) - } - - fn order( - x: &::dafny_runtime::Sequence, - y: &::dafny_runtime::Sequence, - less: &::std::rc::Rc bool>, - ) -> Ordering { - let mut iter1 = x.iter(); - let mut iter2 = y.iter(); - - loop { - match (iter1.next(), iter2.next()) { - (Some(lhs), Some(rhs)) => { - if less(&lhs, &rhs) { - return Ordering::Less; - } - if less(&rhs, &lhs) { - return Ordering::Greater; - } - } - (Some(_), None) => return Ordering::Greater, - (None, Some(_)) => return Ordering::Less, - (None, None) => return Ordering::Equal, - } - } - } - } -} diff --git a/AwsEncryptionSDK/runtimes/rust/src/software_externs.rs b/AwsEncryptionSDK/runtimes/rust/src/software_externs.rs deleted file mode 100644 index 5ff57e57f..000000000 --- a/AwsEncryptionSDK/runtimes/rust/src/software_externs.rs +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. -// SPDX-License-Identifier: Apache-2.0 - -#![deny(warnings, unconditional_panic)] -#![deny(nonstandard_style)] -#![deny(clippy::all)] -#![allow(non_snake_case)] - -pub mod software { - pub mod amazon { - pub mod cryptography { - pub mod internaldafny { - pub mod StormTrackingCMC { - pub use crate::storm_tracker::internal_StormTrackingCMC::*; - } - pub mod SynchronizedLocalCMC { - pub use crate::local_cmc::internal_SynchronizedLocalCMC::*; - } - } - } - } -} diff --git a/AwsEncryptionSDK/runtimes/rust/src/standard_library_conversions.rs b/AwsEncryptionSDK/runtimes/rust/src/standard_library_conversions.rs deleted file mode 100644 index 6bf8297d8..000000000 --- a/AwsEncryptionSDK/runtimes/rust/src/standard_library_conversions.rs +++ /dev/null @@ -1,266 +0,0 @@ -pub fn ostring_to_dafny( - input: &Option, -) -> ::std::rc::Rc< - crate::_Wrappers_Compile::Option<::dafny_runtime::Sequence<::dafny_runtime::DafnyCharUTF16>>, -> { - let dafny_value = match input { - Some(b) => crate::_Wrappers_Compile::Option::Some { value: - dafny_runtime::dafny_runtime_conversions::unicode_chars_false::string_to_dafny_string(&b) - }, - None => crate::_Wrappers_Compile::Option::None {}, -}; - ::std::rc::Rc::new(dafny_value) -} - -pub fn ostring_from_dafny( - input: ::std::rc::Rc< - crate::_Wrappers_Compile::Option< - ::dafny_runtime::Sequence<::dafny_runtime::DafnyCharUTF16>, - >, - >, -) -> Option { - if matches!( - input.as_ref(), - crate::_Wrappers_Compile::Option::Some { .. } - ) { - Some( - dafny_runtime::dafny_runtime_conversions::unicode_chars_false::dafny_string_to_string( - &input.Extract(), - ), - ) - } else { - None - } -} - -pub fn obool_to_dafny( - input: &Option, -) -> ::std::rc::Rc> { - let dafny_value = match input { - Some(b) => crate::_Wrappers_Compile::Option::Some { value: *b }, - None => crate::_Wrappers_Compile::Option::None {}, - }; - ::std::rc::Rc::new(dafny_value) -} - -pub fn obool_from_dafny( - input: ::std::rc::Rc>, -) -> Option { - if matches!( - input.as_ref(), - crate::_Wrappers_Compile::Option::Some { .. } - ) { - Some(input.Extract()) - } else { - None - } -} - -pub fn oint_to_dafny(input: Option) -> ::std::rc::Rc> { - let dafny_value = match input { - Some(b) => crate::_Wrappers_Compile::Option::Some { value: b }, - None => crate::_Wrappers_Compile::Option::None {}, - }; - ::std::rc::Rc::new(dafny_value) -} - -pub fn oint_from_dafny(input: ::std::rc::Rc>) -> Option { - if matches!( - input.as_ref(), - crate::_Wrappers_Compile::Option::Some { .. } - ) { - Some(input.Extract()) - } else { - None - } -} - -pub fn olong_to_dafny(input: &Option) -> ::std::rc::Rc> { - let dafny_value = match input { - Some(b) => crate::_Wrappers_Compile::Option::Some { value: *b }, - None => crate::_Wrappers_Compile::Option::None {}, - }; - ::std::rc::Rc::new(dafny_value) -} - -pub fn olong_from_dafny( - input: ::std::rc::Rc>, -) -> Option { - if matches!( - input.as_ref(), - crate::_Wrappers_Compile::Option::Some { .. } - ) { - Some(input.Extract()) - } else { - None - } -} - -pub fn blob_to_dafny(input: &::aws_smithy_types::Blob) -> ::dafny_runtime::Sequence { - ::dafny_runtime::dafny_runtime_conversions::vec_to_dafny_sequence(&input.clone().into_inner(), |x| *x) -} - -pub fn oblob_to_dafny( - input: &Option<::aws_smithy_types::Blob>, -) -> ::std::rc::Rc>> { - let dafny_value = match input { - Some(b) => crate::_Wrappers_Compile::Option::Some { - value: blob_to_dafny(&b), - }, - None => crate::_Wrappers_Compile::Option::None {}, - }; - ::std::rc::Rc::new(dafny_value) -} - -pub fn blob_from_dafny(input: ::dafny_runtime::Sequence) -> ::aws_smithy_types::Blob { - ::aws_smithy_types::Blob::new( - ::std::rc::Rc::try_unwrap(input.to_array()).unwrap_or_else(|rc| (*rc).clone()), - ) -} - -pub fn oblob_from_dafny( - input: ::std::rc::Rc>>, -) -> Option<::aws_smithy_types::Blob> { - if matches!( - input.as_ref(), - crate::_Wrappers_Compile::Option::Some { .. } - ) { - Some(blob_from_dafny(input.Extract())) - } else { - None - } -} - -pub fn double_to_dafny(input: f64) -> ::dafny_runtime::Sequence { - ::dafny_runtime::dafny_runtime_conversions::vec_to_dafny_sequence( - &f64::to_be_bytes(input).to_vec(), - |x| *x, - ) -} - -pub fn odouble_to_dafny( - input: &Option, -) -> ::std::rc::Rc>> { - let dafny_value = match input { - Some(f) => crate::_Wrappers_Compile::Option::Some { - value: double_to_dafny(*f), - }, - None => crate::_Wrappers_Compile::Option::None {}, - }; - ::std::rc::Rc::new(dafny_value) -} - -pub fn double_from_dafny(input: &::dafny_runtime::Sequence) -> f64 { - let v = ::dafny_runtime::dafny_runtime_conversions::dafny_sequence_to_vec(input, |x| *x); - f64::from_be_bytes(v.try_into().expect("Error converting Sequence to f64")) -} - -pub fn odouble_from_dafny( - input: ::std::rc::Rc>>, -) -> Option { - if matches!( - input.as_ref(), - crate::_Wrappers_Compile::Option::Some { .. } - ) { - Some(double_from_dafny(&input.Extract())) - } else { - None - } -} - -pub fn timestamp_to_dafny( - input: &::aws_smithy_types::DateTime, -) -> ::dafny_runtime::Sequence<::dafny_runtime::DafnyCharUTF16> { - ::dafny_runtime::dafny_runtime_conversions::unicode_chars_false::string_to_dafny_string( - &input.to_string(), - ) -} - -pub fn otimestamp_to_dafny( - input: &Option<::aws_smithy_types::DateTime>, -) -> ::std::rc::Rc< - crate::_Wrappers_Compile::Option<::dafny_runtime::Sequence<::dafny_runtime::DafnyCharUTF16>>, -> { - let dafny_value = match input { - Some(f) => crate::_Wrappers_Compile::Option::Some { - value: timestamp_to_dafny(f), - }, - None => crate::_Wrappers_Compile::Option::None {}, - }; - ::std::rc::Rc::new(dafny_value) -} - -pub fn timestamp_from_dafny( - input: ::dafny_runtime::Sequence<::dafny_runtime::DafnyCharUTF16>, -) -> ::aws_smithy_types::DateTime { - let s = dafny_runtime::dafny_runtime_conversions::unicode_chars_false::dafny_string_to_string( - &input, - ); - ::aws_smithy_types::DateTime::from_str(&s, aws_smithy_types::date_time::Format::DateTime) - .unwrap() -} - -pub fn otimestamp_from_dafny( - input: ::std::rc::Rc< - crate::_Wrappers_Compile::Option< - ::dafny_runtime::Sequence<::dafny_runtime::DafnyCharUTF16>, - >, - >, -) -> Option<::aws_smithy_types::DateTime> { - if matches!( - input.as_ref(), - crate::_Wrappers_Compile::Option::Some { .. } - ) { - Some(timestamp_from_dafny(input.Extract())) - } else { - None - } -} - -pub fn option_from_dafny( - input: ::std::rc::Rc>, - converter: fn(&T) -> TR, -) -> Option { - match &*input { - crate::_Wrappers_Compile::Option::Some { value } => Some(converter(value)), - crate::_Wrappers_Compile::Option::None {} => None, - } -} - -pub fn option_to_dafny( - input: &Option, - converter: fn(&TR) -> T, -) -> ::std::rc::Rc> { - match input { - Some(value) => ::std::rc::Rc::new(crate::_Wrappers_Compile::Option::Some { - value: converter(&value), - }), - None => ::std::rc::Rc::new(crate::_Wrappers_Compile::Option::None {}), - } -} - -pub fn result_from_dafny( - input: ::std::rc::Rc>, - converter_t: fn(&T) -> TR, - converter_e: fn(&E) -> ER, -) -> Result { - match &*input { - crate::_Wrappers_Compile::Result::Success { value } => Ok(converter_t(value)), - crate::_Wrappers_Compile::Result::Failure { error } => Err(converter_e(error)), - } -} - -pub fn result_to_dafny( - input: &Result, - converter_t: fn(&TR) -> T, - converter_e: fn(&ER) -> E, -) -> ::std::rc::Rc> { - match input { - Ok(value) => ::std::rc::Rc::new(crate::_Wrappers_Compile::Result::Success { - value: converter_t(&value), - }), - Err(error) => ::std::rc::Rc::new(crate::_Wrappers_Compile::Result::Failure { - error: converter_e(&error), - }), - } -} diff --git a/AwsEncryptionSDK/runtimes/rust/src/standard_library_externs.rs b/AwsEncryptionSDK/runtimes/rust/src/standard_library_externs.rs deleted file mode 100644 index eca6a2980..000000000 --- a/AwsEncryptionSDK/runtimes/rust/src/standard_library_externs.rs +++ /dev/null @@ -1,80 +0,0 @@ -// Annotation to ignore the case of this module -use crate::r#_Wrappers_Compile; -use crate::UTF8; - -impl crate::UTF8::_default { - pub fn Encode( - s: &::dafny_runtime::Sequence<::dafny_runtime::DafnyCharUTF16>, - ) -> ::std::rc::Rc< - r#_Wrappers_Compile::Result< - UTF8::ValidUTF8Bytes, - ::dafny_runtime::Sequence<::dafny_runtime::DafnyCharUTF16>, - >, - > { - let v = s.to_array(); - let mut _accumulator: Vec = vec![]; - // Use of .encode_utf8 method. - let mut surrogate: Option = None; - for c in v.iter() { - let s = if let Some(s) = surrogate { - String::from_utf16(&[s, c.0]) - } else { - String::from_utf16(&[c.0]) - }; - surrogate = None; - match s { - Ok(value) => { - _accumulator.extend(value.as_bytes()); - continue; - } - Err(e) => { - if 0xD800 <= c.0 && c.0 <= 0xDFFF { - surrogate = Some(c.0); - continue; - } - return ::std::rc::Rc::new(r#_Wrappers_Compile::Result::>::Failure { - error: ::dafny_runtime::dafny_runtime_conversions::unicode_chars_false::string_to_dafny_string( - &e.to_string()) - }); - } - } - } - if let Some(s) = surrogate { - return ::std::rc::Rc::new(r#_Wrappers_Compile::Result::>::Failure { - error: ::dafny_runtime::dafny_runtime_conversions::unicode_chars_false::string_to_dafny_string( - &format!("Surrogate pair missing: 0x{:04x}", s)) - }); - } - ::std::rc::Rc::new(r#_Wrappers_Compile::Result::< - UTF8::ValidUTF8Bytes, - ::dafny_runtime::Sequence<::dafny_runtime::DafnyCharUTF16>, - >::Success { - value: ::dafny_runtime::Sequence::from_array_owned(_accumulator), - }) - } - pub fn Decode( - b: &::dafny_runtime::Sequence, - ) -> ::std::rc::Rc< - r#_Wrappers_Compile::Result< - ::dafny_runtime::Sequence<::dafny_runtime::DafnyCharUTF16>, - ::dafny_runtime::Sequence<::dafny_runtime::DafnyCharUTF16>, - >, - > { - let b = String::from_utf8(b.to_array().as_ref().clone()); - match b { - Ok(s) => { - ::std::rc::Rc::new(r#_Wrappers_Compile::Result::<::dafny_runtime::Sequence<::dafny_runtime::DafnyCharUTF16>, - ::dafny_runtime::Sequence<::dafny_runtime::DafnyCharUTF16>>::Success { - value: ::dafny_runtime::dafny_runtime_conversions::unicode_chars_false::string_to_dafny_string(&s) - }) - }, - Err(e) => { - return ::std::rc::Rc::new(r#_Wrappers_Compile::Result::<::dafny_runtime::Sequence<::dafny_runtime::DafnyCharUTF16>, - ::dafny_runtime::Sequence<::dafny_runtime::DafnyCharUTF16>>::Failure { - error: ::dafny_runtime::dafny_runtime_conversions::unicode_chars_false::string_to_dafny_string( - &e.to_string()) - }) - } - } - } -} diff --git a/AwsEncryptionSDK/runtimes/rust/src/storm_tracker.rs b/AwsEncryptionSDK/runtimes/rust/src/storm_tracker.rs deleted file mode 100644 index abb4024bb..000000000 --- a/AwsEncryptionSDK/runtimes/rust/src/storm_tracker.rs +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. -// SPDX-License-Identifier: Apache-2.0 - -#![deny(warnings, unconditional_panic)] -#![deny(nonstandard_style)] -#![deny(clippy::all)] - -#[allow(non_snake_case)] -pub mod internal_StormTrackingCMC { - use crate::_StormTracker_Compile::CacheState::*; - use crate::*; - use std::sync::Mutex; - use std::time::Duration; - - pub struct StormTrackingCMC { - wrapped: Mutex<::dafny_runtime::Object<_StormTracker_Compile::StormTracker>>, - } - impl StormTrackingCMC { - pub fn _allocate_object( - cmc: ::dafny_runtime::Object<_StormTracker_Compile::StormTracker>, - ) -> ::dafny_runtime::Object { - ::dafny_runtime::Object::new(StormTrackingCMC { - wrapped: Mutex::new(cmc), - }) - } - } - - impl ::dafny_runtime::UpcastObject for StormTrackingCMC { - ::dafny_runtime::UpcastObjectFn!(dyn ::std::any::Any); - } - - impl ::dafny_runtime::UpcastObject - for StormTrackingCMC { - ::dafny_runtime::UpcastObjectFn!(dyn software::amazon::cryptography::materialproviders::internaldafny::types::ICryptographicMaterialsCache); -} - - impl crate::software::amazon::cryptography::materialproviders::internaldafny::types::ICryptographicMaterialsCache for StormTrackingCMC { - fn r#_PutCacheEntry_k(&self, input: &std::rc::Rc) - -> std::rc::Rc>> - { - self.wrapped.lock().unwrap().as_mut().PutCacheEntry(input) - } - - fn r#_UpdateUsageMetadata_k(&self, input: &std::rc::Rc) - -> std::rc::Rc>> - { - self.wrapped.lock().unwrap().as_mut().UpdateUsageMetadata(input) - } - - fn r#_GetCacheEntry_k(&self, input: &std::rc::Rc) - -> std::rc::Rc, std::rc::Rc>> - { - loop { - let result = self.wrapped.lock().unwrap().as_mut().GetFromCache(input); - match &*result { - crate::_Wrappers_Compile::Result::Failure{error} => {return std::rc::Rc::new(crate::_Wrappers_Compile::Result::Failure{error : error.clone()});} - crate::_Wrappers_Compile::Result::Success{value} => { - match &**value { - Full { data } => { return std::rc::Rc::new(crate::_Wrappers_Compile::Result::Success{value : data.clone()}); } - EmptyFetch {} => { - return std::rc::Rc::new(crate::_Wrappers_Compile::Result::Failure{error : - std::rc::Rc::new(crate::software::amazon::cryptography::materialproviders::internaldafny::types::Error::EntryDoesNotExist { message: - dafny_runtime::dafny_runtime_conversions::unicode_chars_false::string_to_dafny_string( - "Entry does not exist" - ) - }, - )}); - } - EmptyWait {} => { std::thread::sleep(Duration::from_micros(50)); } - } - } - } - } - } - - fn r#_DeleteCacheEntry_k(&self, input: &std::rc::Rc) -> std::rc::Rc>> { - self.wrapped.lock().unwrap().as_mut().DeleteCacheEntry(input) - } - } -} diff --git a/AwsEncryptionSDK/runtimes/rust/src/time.rs b/AwsEncryptionSDK/runtimes/rust/src/time.rs deleted file mode 100644 index c82a871de..000000000 --- a/AwsEncryptionSDK/runtimes/rust/src/time.rs +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. -// SPDX-License-Identifier: Apache-2.0 - -#![deny(warnings, unconditional_panic)] -#![deny(nonstandard_style)] -#![deny(clippy::all)] - -use crate::*; -use std::time::SystemTime; - -impl crate::Time::_default { - #[allow(non_snake_case)] - pub fn CurrentRelativeTime() -> i64 { - match SystemTime::now().duration_since(SystemTime::UNIX_EPOCH) { - Ok(n) => n.as_secs() as i64, - Err(_) => 0, - } - } - - #[allow(non_snake_case)] - pub fn CurrentRelativeTimeMilli() -> i64 { - match SystemTime::now().duration_since(SystemTime::UNIX_EPOCH) { - Ok(n) => n.as_millis() as i64, - Err(_) => 0, - } - } - - #[allow(non_snake_case)] - pub fn GetCurrentTimeStamp() -> ::std::rc::Rc< - _Wrappers_Compile::Result< - ::dafny_runtime::Sequence<::dafny_runtime::DafnyCharUTF16>, - ::dafny_runtime::Sequence<::dafny_runtime::DafnyCharUTF16>, - >, - > { - let now_utc = chrono::Utc::now(); - let formatted = format!("{}", now_utc.format("%Y-%m-%dT%H:%M:%S%.fZ")); - ::std::rc::Rc::new( - _Wrappers_Compile::Result::Success{value : - dafny_runtime::dafny_runtime_conversions::unicode_chars_false::string_to_dafny_string(&formatted) - } - ) - } -} diff --git a/AwsEncryptionSDK/runtimes/rust/src/types.rs b/AwsEncryptionSDK/runtimes/rust/src/types.rs deleted file mode 100644 index c9ff218a5..000000000 --- a/AwsEncryptionSDK/runtimes/rust/src/types.rs +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. -// SPDX-License-Identifier: Apache-2.0 -// Do not modify this file. This file is machine generated, and any changes to it will be overwritten. -/// Types for the `AwsEncryptionSdkConfig` -pub mod aws_encryption_sdk_config; - -pub mod builders; - - - -mod _decrypt_input; -pub use crate::types::_decrypt_input::DecryptInput; -mod _decrypt_output; -pub use crate::types::_decrypt_output::DecryptOutput; -mod _encrypt_input; -pub use crate::types::_encrypt_input::EncryptInput; -mod _encrypt_output; -pub use crate::types::_encrypt_output::EncryptOutput; - -pub mod error; - -mod _net_v4_0_0_retry_policy; -pub use crate::types::_net_v4_0_0_retry_policy::NetV400RetryPolicy; - diff --git a/AwsEncryptionSDK/runtimes/rust/src/uuid.rs b/AwsEncryptionSDK/runtimes/rust/src/uuid.rs deleted file mode 100644 index 700b2b1d2..000000000 --- a/AwsEncryptionSDK/runtimes/rust/src/uuid.rs +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. -// SPDX-License-Identifier: Apache-2.0 - -#![deny(warnings, unconditional_panic)] -#![deny(nonstandard_style)] -#![deny(clippy::all)] - -use crate::*; -use ::uuid::Uuid; - -impl crate::UUID::_default { - #[allow(non_snake_case)] - pub fn ToByteArray( - bytes: &::dafny_runtime::Sequence<::dafny_runtime::DafnyCharUTF16>, - ) -> ::std::rc::Rc< - _Wrappers_Compile::Result< - ::dafny_runtime::Sequence, - ::dafny_runtime::Sequence<::dafny_runtime::DafnyCharUTF16>, - >, - > { - let my_str = - dafny_runtime::dafny_runtime_conversions::unicode_chars_false::dafny_string_to_string( - bytes, - ); - match Uuid::parse_str(&my_str) { - Ok(u) => { - let b = u.as_bytes(); - std::rc::Rc::new(_Wrappers_Compile::Result::Success { value : - b.iter().cloned().collect() - }) - } - Err(e) => { - std::rc::Rc::new(_Wrappers_Compile::Result::Failure{ error : - dafny_runtime::dafny_runtime_conversions::unicode_chars_false::string_to_dafny_string( - &format!("{my_str} is not a valid UUID ({e}).")) - }) - } - } - } - - #[allow(non_snake_case)] - pub fn FromByteArray( - bytes: &::dafny_runtime::Sequence, - ) -> ::std::rc::Rc< - _Wrappers_Compile::Result< - ::dafny_runtime::Sequence<::dafny_runtime::DafnyCharUTF16>, - ::dafny_runtime::Sequence<::dafny_runtime::DafnyCharUTF16>, - >, - > { - let vec: Vec = bytes.iter().collect(); - if vec.len() != 16 { - return std::rc::Rc::new(_Wrappers_Compile::Result::Failure{ error : - dafny_runtime::dafny_runtime_conversions::unicode_chars_false::string_to_dafny_string("Not 16 bytes of input to FromByteArray.") - }); - } - let bytes: ::uuid::Bytes = vec[..16].try_into().unwrap(); - let uuid = Uuid::from_bytes_ref(&bytes); - let my_str = uuid.to_string(); - std::rc::Rc::new(_Wrappers_Compile::Result::Success { value : - dafny_runtime::dafny_runtime_conversions::unicode_chars_false::string_to_dafny_string(&my_str) - }) - } - - #[allow(non_snake_case)] - pub fn GenerateUUID() -> ::std::rc::Rc< - _Wrappers_Compile::Result< - ::dafny_runtime::Sequence<::dafny_runtime::DafnyCharUTF16>, - ::dafny_runtime::Sequence<::dafny_runtime::DafnyCharUTF16>, - >, - > { - let my_str = Uuid::new_v4().to_string(); - std::rc::Rc::new(_Wrappers_Compile::Result::Success { value : - dafny_runtime::dafny_runtime_conversions::unicode_chars_false::string_to_dafny_string(&my_str) - }) - } -}