From 5e75b39419f67856550111d6e5130cdb0715c191 Mon Sep 17 00:00:00 2001 From: Rakuram Date: Tue, 26 Nov 2024 23:33:18 +0530 Subject: [PATCH 1/3] initial commit --- tests/symmetric_test/src/decrypted.docx | 1 + tests/symmetric_test/src/encrypted.docx | 1 + tests/symmetric_test/src/main.rs | 19 +++++++++++++++++++ tests/test.docx | 3 +++ 4 files changed, 24 insertions(+) create mode 100644 tests/symmetric_test/src/decrypted.docx create mode 100644 tests/symmetric_test/src/encrypted.docx create mode 100644 tests/symmetric_test/src/main.rs create mode 100644 tests/test.docx diff --git a/tests/symmetric_test/src/decrypted.docx b/tests/symmetric_test/src/decrypted.docx new file mode 100644 index 0000000..554210c --- /dev/null +++ b/tests/symmetric_test/src/decrypted.docx @@ -0,0 +1 @@ +this is test document for validating the CAS-LIB implemention and provide the examples usecases for the users \ No newline at end of file diff --git a/tests/symmetric_test/src/encrypted.docx b/tests/symmetric_test/src/encrypted.docx new file mode 100644 index 0000000..4e49e2b --- /dev/null +++ b/tests/symmetric_test/src/encrypted.docx @@ -0,0 +1 @@ +Ί97Ú懚1N5I[`?BíϜ^x&W.m|+ܮDͺzH3.قbrlp6d~DYJ^ ?a;&S~w^z \ No newline at end of file diff --git a/tests/symmetric_test/src/main.rs b/tests/symmetric_test/src/main.rs new file mode 100644 index 0000000..1e36ea2 --- /dev/null +++ b/tests/symmetric_test/src/main.rs @@ -0,0 +1,19 @@ +use std::{fs::{File}, io::Write, path::Path}; + +use cas_lib::symmetric::{aes::CASAES256, cas_symmetric_encryption::CASAESEncryption}; + +fn main() { + let path = Path::new("./../../test.docx"); + let file_bytes: Vec = std::fs::read(path).unwrap(); + let aes_nonce = ::generate_nonce(); + let aes_key = ::generate_key(); + let encrypted_bytes = ::encrypt_plaintext(aes_key.clone(), aes_nonce.clone(), file_bytes); + let mut file = File::create("encrypted.docx").unwrap(); + file.write_all(&encrypted_bytes); + + let path = Path::new("encrypted.docx"); + let file_bytes: Vec = std::fs::read(path).unwrap(); + let decrypted_bytes = ::decrypt_ciphertext(aes_key, aes_nonce, file_bytes); + let mut file = File::create("decrypted.docx").unwrap(); + file.write_all(&decrypted_bytes); +} \ No newline at end of file diff --git a/tests/test.docx b/tests/test.docx new file mode 100644 index 0000000..9fac6e3 --- /dev/null +++ b/tests/test.docx @@ -0,0 +1,3 @@ +This is a sample document. +It contains several lines of text. +We will use this document to demonstrate signing and verifying using RSA encryption. From a2112efcb4d54fd7d513969e75d098cea32a9a17 Mon Sep 17 00:00:00 2001 From: Rakuram Date: Fri, 29 Nov 2024 17:23:20 +0530 Subject: [PATCH 2/3] update the folder structure to run tests using cargo test command --- tests/symmetric.rs | 24 ++++++++++++++++++++++++ tests/symmetric_test/src/decrypted.docx | 1 - tests/symmetric_test/src/encrypted.docx | 1 - tests/symmetric_test/src/main.rs | 19 ------------------- 4 files changed, 24 insertions(+), 21 deletions(-) create mode 100644 tests/symmetric.rs delete mode 100644 tests/symmetric_test/src/decrypted.docx delete mode 100644 tests/symmetric_test/src/encrypted.docx delete mode 100644 tests/symmetric_test/src/main.rs diff --git a/tests/symmetric.rs b/tests/symmetric.rs new file mode 100644 index 0000000..517afc9 --- /dev/null +++ b/tests/symmetric.rs @@ -0,0 +1,24 @@ +use std::{fs::{File}, io::Write, path::Path}; + +use cas_lib::symmetric::{aes::CASAES256, cas_symmetric_encryption::CASAESEncryption}; + +#[cfg(test)] +mod tests { + use super::*; + #[test] + fn test_sym() { + let path = Path::new("tests/test.docx"); + let file_bytes: Vec = std::fs::read(path).unwrap(); + let aes_nonce = ::generate_nonce(); + let aes_key = ::generate_key(); + let encrypted_bytes = ::encrypt_plaintext(aes_key.clone(), aes_nonce.clone(), file_bytes); + let mut file = File::create("encrypted.docx").unwrap(); + file.write_all(&encrypted_bytes); + + let path = Path::new("encrypted.docx"); + let file_bytes: Vec = std::fs::read(path).unwrap(); + let decrypted_bytes = ::decrypt_ciphertext(aes_key, aes_nonce, file_bytes); + let mut file = File::create("decrypted.docx").unwrap(); + file.write_all(&decrypted_bytes); + } +} \ No newline at end of file diff --git a/tests/symmetric_test/src/decrypted.docx b/tests/symmetric_test/src/decrypted.docx deleted file mode 100644 index 554210c..0000000 --- a/tests/symmetric_test/src/decrypted.docx +++ /dev/null @@ -1 +0,0 @@ -this is test document for validating the CAS-LIB implemention and provide the examples usecases for the users \ No newline at end of file diff --git a/tests/symmetric_test/src/encrypted.docx b/tests/symmetric_test/src/encrypted.docx deleted file mode 100644 index 4e49e2b..0000000 --- a/tests/symmetric_test/src/encrypted.docx +++ /dev/null @@ -1 +0,0 @@ -Ί97Ú懚1N5I[`?BíϜ^x&W.m|+ܮDͺzH3.قbrlp6d~DYJ^ ?a;&S~w^z \ No newline at end of file diff --git a/tests/symmetric_test/src/main.rs b/tests/symmetric_test/src/main.rs deleted file mode 100644 index 1e36ea2..0000000 --- a/tests/symmetric_test/src/main.rs +++ /dev/null @@ -1,19 +0,0 @@ -use std::{fs::{File}, io::Write, path::Path}; - -use cas_lib::symmetric::{aes::CASAES256, cas_symmetric_encryption::CASAESEncryption}; - -fn main() { - let path = Path::new("./../../test.docx"); - let file_bytes: Vec = std::fs::read(path).unwrap(); - let aes_nonce = ::generate_nonce(); - let aes_key = ::generate_key(); - let encrypted_bytes = ::encrypt_plaintext(aes_key.clone(), aes_nonce.clone(), file_bytes); - let mut file = File::create("encrypted.docx").unwrap(); - file.write_all(&encrypted_bytes); - - let path = Path::new("encrypted.docx"); - let file_bytes: Vec = std::fs::read(path).unwrap(); - let decrypted_bytes = ::decrypt_ciphertext(aes_key, aes_nonce, file_bytes); - let mut file = File::create("decrypted.docx").unwrap(); - file.write_all(&decrypted_bytes); -} \ No newline at end of file From 22e9560cb675a7797b48d38e7673a88e8d05697e Mon Sep 17 00:00:00 2001 From: Rakuram Date: Tue, 3 Dec 2024 23:35:16 +0530 Subject: [PATCH 3/3] update test function name --- tests/symmetric.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/symmetric.rs b/tests/symmetric.rs index 517afc9..2b78ddc 100644 --- a/tests/symmetric.rs +++ b/tests/symmetric.rs @@ -6,7 +6,7 @@ use cas_lib::symmetric::{aes::CASAES256, cas_symmetric_encryption::CASAESEncrypt mod tests { use super::*; #[test] - fn test_sym() { + fn test_aes_256() { let path = Path::new("tests/test.docx"); let file_bytes: Vec = std::fs::read(path).unwrap(); let aes_nonce = ::generate_nonce();