-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added functions, docs, and testing. * Update cmd/implants/eldritch/src/file/hash_impl.rs Co-authored-by: Nicholas O'Brien <[email protected]> Co-authored-by: KCarretto <[email protected]> Co-authored-by: Nicholas O'Brien <[email protected]>
- Loading branch information
1 parent
c6518a6
commit a87a3d0
Showing
3 changed files
with
32 additions
and
3 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 |
---|---|---|
|
@@ -7,3 +7,4 @@ edition = "2021" | |
starlark = "0.6.0" | ||
anyhow = "1.0.55" | ||
derive_more = "0.99.17" | ||
sha256 = "1.0.3" |
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 |
---|---|---|
@@ -1,5 +1,33 @@ | ||
use anyhow::Result; | ||
use sha256::digest_file; | ||
|
||
pub fn hash(_path: String) -> Result<String> { | ||
unimplemented!("Method unimplemented") | ||
pub fn hash(path: String) -> Result<String> { | ||
let val = digest_file(path)?; | ||
Ok(val) | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
use std::fs::File; | ||
use std::io::prelude::*; | ||
use std::fs::remove_file; | ||
|
||
#[test] | ||
fn test_hash() -> anyhow::Result<()>{ | ||
let winfile = "/tmp/win_test_exists_does"; | ||
let _ = remove_file(String::from(winfile)); | ||
// Create file | ||
let mut file = File::create(winfile)?; | ||
// Write to file | ||
file.write_all(b"aoeu")?; | ||
|
||
// Run our code | ||
let res = hash(String::from(winfile))?; | ||
|
||
assert_eq!(res, "bc4c24181ed3ce6666444deeb95e1f61940bffee70dd13972beb331f5d111e9b"); | ||
|
||
remove_file(String::from(winfile))?; | ||
Ok(()) | ||
} | ||
} |
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