From dfeafd5f62bb48422530be41db736c2dbbcbadc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E6=B6=9B?= Date: Sat, 1 Jul 2023 22:16:36 +0800 Subject: [PATCH] =?UTF-8?q?feat(hash):=E5=9F=BA=E6=9C=AC=E5=AE=8C=E6=88=90?= =?UTF-8?q?=E5=9B=BE=E5=83=8F=E6=84=9F=E7=9F=A5=E6=95=A3=E5=88=97=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.toml | 2 ++ src/hash/mod.rs | 21 +++++++++++++++++++++ src/lib.rs | 2 ++ 3 files changed, 25 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 10f8fc7..59dc1d6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,10 +11,12 @@ crate-type = ["dylib", "rlib"] [dependencies] aes = "0.8.3" base64 = "0.21.2" +blockhash = "0.5.0" cbc = "0.1.2" des = "0.8.1" hex = "0.4.3" hmac-sha512 = "1.1.5" +image = "0.24.6" md-5 = "0.10.5" rand = "0.8.5" sha1 = "0.10.5" diff --git a/src/hash/mod.rs b/src/hash/mod.rs index 69fb356..3c090c1 100644 --- a/src/hash/mod.rs +++ b/src/hash/mod.rs @@ -26,3 +26,24 @@ pub mod sha512 { 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>>( + 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(), + } + } +} diff --git a/src/lib.rs b/src/lib.rs index d85ad96..b637022 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,5 @@ +pub extern crate image; + pub mod encryption; pub mod hash; pub mod serial_code;