Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SHA test cases #18

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions tests/hashers.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
use std::path::Path;

use cas_lib::hashers::{cas_hasher::CASHasher, sha::CASSHA};

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_sha_256_compare_fail() {
let path = Path::new("tests/test.docx");
let file_bytes: Vec<u8> = std::fs::read(path).unwrap();
let hash = <CASSHA as CASHasher>::hash_256(file_bytes);

let path_2 = Path::new("tests/test2.docx");
let file_bytes_2: Vec<u8> = std::fs::read(path_2).unwrap();
let hash_2 = <CASSHA as CASHasher>::hash_256(file_bytes_2);

assert_ne!(hash, hash_2);
}

#[test]
fn test_sha_256_success() {
let path = Path::new("tests/test.docx");
let file_bytes: Vec<u8> = std::fs::read(path).unwrap();
let hash = <CASSHA as CASHasher>::hash_256(file_bytes);

let path_2 = Path::new("tests/test.docx");
let file_bytes_2: Vec<u8> = std::fs::read(path).unwrap();
let hash_2 = <CASSHA as CASHasher>::hash_256(file_bytes_2);

assert_eq!(hash, hash_2);
}

#[test]
fn test_sha_512_compare_fail() {
let path = Path::new("tests/test.docx");
let file_bytes: Vec<u8> = std::fs::read(path).unwrap();
let hash = <CASSHA as CASHasher>::hash_512(file_bytes);

let path_2 = Path::new("tests/test2.docx");
let file_bytes_2: Vec<u8> = std::fs::read(path_2).unwrap();
let hash_2 = <CASSHA as CASHasher>::hash_512(file_bytes_2);

assert_ne!(hash, hash_2);
}

#[test]
fn test_sha_512_success() {
let path = Path::new("tests/test.docx");
let file_bytes: Vec<u8> = std::fs::read(path).unwrap();
let hash = <CASSHA as CASHasher>::hash_512(file_bytes);

let path_2 = Path::new("tests/test.docx");
let file_bytes_2: Vec<u8> = std::fs::read(path).unwrap();
let hash_2 = <CASSHA as CASHasher>::hash_512(file_bytes_2);

assert_eq!(hash, hash_2);
}
}
1 change: 1 addition & 0 deletions tests/test2.docx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is a test document for various cryptographic hashing.
Loading