Skip to content

Commit

Permalink
Merge pull request #18 from Cryptographic-API-Services/sha_hash_test_…
Browse files Browse the repository at this point in the history
…cases

SHA test cases
  • Loading branch information
WingZer0o authored Dec 18, 2024
2 parents c510c13 + 9bbf63e commit 5120bb8
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
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.

0 comments on commit 5120bb8

Please sign in to comment.