mirror of
https://github.com/lune-org/lune.git
synced 2025-04-15 01:13:55 +01:00
feat: impl sha3 (256-bit & 512-bit)
This commit is contained in:
parent
8d5854af3a
commit
f05e1ca765
4 changed files with 36 additions and 2 deletions
20
Cargo.lock
generated
20
Cargo.lock
generated
|
@ -1070,6 +1070,15 @@ dependencies = [
|
||||||
"wasm-bindgen",
|
"wasm-bindgen",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "keccak"
|
||||||
|
version = "0.1.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8f6d5ed8676d904364de097082f4e7d240b571b67989ced0240f08b7f966f940"
|
||||||
|
dependencies = [
|
||||||
|
"cpufeatures",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "lazy_static"
|
name = "lazy_static"
|
||||||
version = "1.4.0"
|
version = "1.4.0"
|
||||||
|
@ -1171,6 +1180,7 @@ dependencies = [
|
||||||
"serde_yaml",
|
"serde_yaml",
|
||||||
"sha1 0.10.6",
|
"sha1 0.10.6",
|
||||||
"sha2",
|
"sha2",
|
||||||
|
"sha3",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"tokio",
|
"tokio",
|
||||||
"tokio-tungstenite",
|
"tokio-tungstenite",
|
||||||
|
@ -2107,6 +2117,16 @@ dependencies = [
|
||||||
"digest",
|
"digest",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "sha3"
|
||||||
|
version = "0.10.8"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "75872d278a8f37ef87fa0ddbda7802605cb18344497949862c0d4dcb291eba60"
|
||||||
|
dependencies = [
|
||||||
|
"digest",
|
||||||
|
"keccak",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "sharded-slab"
|
name = "sharded-slab"
|
||||||
version = "0.1.7"
|
version = "0.1.7"
|
||||||
|
|
|
@ -107,6 +107,7 @@ digest = "0.10.7"
|
||||||
md-5 = "0.10.6"
|
md-5 = "0.10.6"
|
||||||
sha1 = "0.10.6"
|
sha1 = "0.10.6"
|
||||||
sha2 = "0.10.8"
|
sha2 = "0.10.8"
|
||||||
|
sha3 = "0.10.8"
|
||||||
blake2 = "0.10.6"
|
blake2 = "0.10.6"
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,7 @@ macro_rules! impl_hash_algo {
|
||||||
impl Crypto {
|
impl Crypto {
|
||||||
$(
|
$(
|
||||||
paste::item! {
|
paste::item! {
|
||||||
pub fn [<$algo:lower>]<T: ToString>(content: Option<T>) -> Self {
|
pub fn [<$algo:snake:lower>]<T: ToString>(content: Option<T>) -> Self {
|
||||||
let constructed = Self {
|
let constructed = Self {
|
||||||
algo: Arc::new(Mutex::new(CryptoAlgo::$algo(Box::new($Type::new())))),
|
algo: Arc::new(Mutex::new(CryptoAlgo::$algo(Box::new($Type::new())))),
|
||||||
};
|
};
|
||||||
|
@ -68,7 +68,9 @@ impl_hash_algo! {
|
||||||
Sha512: sha2::Sha512,
|
Sha512: sha2::Sha512,
|
||||||
Md5: md5::Md5,
|
Md5: md5::Md5,
|
||||||
Blake2s256: blake2::Blake2s256,
|
Blake2s256: blake2::Blake2s256,
|
||||||
Blake2b512: blake2::Blake2b512
|
Blake2b512: blake2::Blake2b512,
|
||||||
|
Sha3_256: sha3::Sha3_256,
|
||||||
|
Sha3_512: sha3::Sha3_512
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
|
|
@ -35,6 +35,17 @@ pub fn create(lua: &'static Lua) -> LuaResult<LuaTable> {
|
||||||
.with_function("blake2b512", |_, content: Option<String>| {
|
.with_function("blake2b512", |_, content: Option<String>| {
|
||||||
Ok(Crypto::blake2b512(content))
|
Ok(Crypto::blake2b512(content))
|
||||||
})?
|
})?
|
||||||
|
.with_function("sha3", |_, (variant, content): (String, Option<String>)| {
|
||||||
|
match variant.to_string().as_str() {
|
||||||
|
"256" => Ok(Crypto::sha3_256(content)),
|
||||||
|
"512" => Ok(Crypto::sha3_512(content)),
|
||||||
|
|
||||||
|
&_ => Err(LuaError::runtime(format!(
|
||||||
|
"Expected sha3 variant to be 256-bit or 512-bit, got {}",
|
||||||
|
variant
|
||||||
|
))),
|
||||||
|
}
|
||||||
|
})?
|
||||||
.build()?,
|
.build()?,
|
||||||
)?
|
)?
|
||||||
.build_readonly()
|
.build_readonly()
|
||||||
|
|
Loading…
Add table
Reference in a new issue