Skip to content

Commit

Permalink
Merge pull request #15 from rakurame96/example-tests
Browse files Browse the repository at this point in the history
#7 Add examples using cas-lib
  • Loading branch information
WingZer0o authored Dec 4, 2024
2 parents 3fbc651 + 22e9560 commit d2801b9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
24 changes: 24 additions & 0 deletions tests/symmetric.rs
Original file line number Diff line number Diff line change
@@ -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_aes_256() {
let path = Path::new("tests/test.docx");
let file_bytes: Vec<u8> = std::fs::read(path).unwrap();
let aes_nonce = <CASAES256 as CASAESEncryption>::generate_nonce();
let aes_key = <CASAES256 as CASAESEncryption>::generate_key();
let encrypted_bytes = <CASAES256 as CASAESEncryption>::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<u8> = std::fs::read(path).unwrap();
let decrypted_bytes = <CASAES256 as CASAESEncryption>::decrypt_ciphertext(aes_key, aes_nonce, file_bytes);
let mut file = File::create("decrypted.docx").unwrap();
file.write_all(&decrypted_bytes);
}
}
3 changes: 3 additions & 0 deletions tests/test.docx
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit d2801b9

Please sign in to comment.