- 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.
30 lines
597 B
Rust
30 lines
597 B
Rust
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);
|
|
}
|
|
}
|