feat: initialize K-Shrink workspace with multiple crates for image shrinking utility
- Add Cargo.toml for workspace configuration with dependencies. - Create README.md with project description, usage, and architecture details. - Implement `bin` crate for the main executable, including clipboard processing logic. - Add `config` crate for handling configuration in TOML format. - Develop `lib` crate containing core image processing logic and error handling. - Introduce `platform` crate for platform-specific clipboard interactions, starting with Wayland. - Implement tests for image shrinking functionality and clipboard interactions.
This commit is contained in:
29
crates/lib/src/hash.rs
Normal file
29
crates/lib/src/hash.rs
Normal file
@@ -0,0 +1,29 @@
|
||||
use sha2::{Digest, Sha256};
|
||||
|
||||
pub fn image_hash(data: &[u8]) -> [u8; 32] {
|
||||
let mut hasher = Sha256::new();
|
||||
hasher.update(data);
|
||||
hasher.finalize().into()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn same_input_same_hash() {
|
||||
let data = b"some image bytes";
|
||||
assert_eq!(image_hash(data), image_hash(data));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn different_input_different_hash() {
|
||||
assert_ne!(image_hash(b"abc"), image_hash(b"xyz"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn empty_input_no_panic() {
|
||||
let h = image_hash(b"");
|
||||
assert_eq!(h.len(), 32);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user