feat(hash):基本完成图像感知散列功能。

This commit is contained in:
徐涛 2023-07-01 22:16:36 +08:00
parent 039596a4f5
commit dfeafd5f62
3 changed files with 25 additions and 0 deletions

View File

@ -11,10 +11,12 @@ crate-type = ["dylib", "rlib"]
[dependencies] [dependencies]
aes = "0.8.3" aes = "0.8.3"
base64 = "0.21.2" base64 = "0.21.2"
blockhash = "0.5.0"
cbc = "0.1.2" cbc = "0.1.2"
des = "0.8.1" des = "0.8.1"
hex = "0.4.3" hex = "0.4.3"
hmac-sha512 = "1.1.5" hmac-sha512 = "1.1.5"
image = "0.24.6"
md-5 = "0.10.5" md-5 = "0.10.5"
rand = "0.8.5" rand = "0.8.5"
sha1 = "0.10.5" sha1 = "0.10.5"

View File

@ -26,3 +26,24 @@ pub mod sha512 {
crate::serialize::to_hex(result.as_slice()) crate::serialize::to_hex(result.as_slice())
} }
} }
pub mod image_hash {
pub enum Precision {
Low = 2,
Medium = 8,
High = 18,
Detailed = 32,
}
pub fn hash_image<T: image::GenericImage<Pixel = image::Rgb<u8>>>(
input: &T,
precision: Precision,
) -> String {
match precision {
Precision::Low => blockhash::blockhash16(input).to_string(),
Precision::Medium => blockhash::blockhash64(input).to_string(),
Precision::High => blockhash::blockhash144(input).to_string(),
Precision::Detailed => blockhash::blockhash256(input).to_string(),
}
}
}

View File

@ -1,3 +1,5 @@
pub extern crate image;
pub mod encryption; pub mod encryption;
pub mod hash; pub mod hash;
pub mod serial_code; pub mod serial_code;