-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from Cryptographic-API-Services/sha_hash_test_…
…cases SHA test cases
- Loading branch information
Showing
2 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
This is a test document for various cryptographic hashing. |