chore: Replace ring for sha256 with sha2

This commit is contained in:
Jade Ellis
2026-04-24 12:56:05 +01:00
parent 0344bf71d8
commit 7ca0d137c4
4 changed files with 13 additions and 19 deletions
Generated
+1 -1
View File
@@ -1069,13 +1069,13 @@ dependencies = [
"rand_core 0.6.4",
"regex",
"reqwest 0.13.2",
"ring",
"ruma",
"sanitize-filename",
"serde",
"serde-saphyr",
"serde_json",
"serde_regex",
"sha2 0.11.0",
"smallstr",
"smallvec",
"thiserror 2.0.18",
+1 -1
View File
@@ -562,7 +562,7 @@ version = "0.15.0"
[workspace.dependencies.lettre]
version = "0.11.19"
default-features = false
features = ["smtp-transport", "pool", "hostname", "builder", "rustls", "rustls-native-certs", "tokio1", "ring", "tokio1-rustls", "tracing", "serde"]
features = ["smtp-transport", "pool", "hostname", "builder", "rustls", "rustls-native-certs", "tokio1", "rustls-no-provider", "tokio1-rustls", "tracing", "serde"]
[workspace.dependencies.governor]
version = "0.10.4"
+1 -1
View File
@@ -92,7 +92,7 @@ rand.workspace = true
rand_core = { version = "0.6.4", features = ["getrandom"] }
regex.workspace = true
reqwest.workspace = true
ring.workspace = true
sha2.workspace = true
ruma.workspace = true
sanitize-filename.workspace = true
serde_json.workspace = true
+10 -16
View File
@@ -1,19 +1,16 @@
use ring::{
digest,
digest::{Context, SHA256, SHA256_OUTPUT_LEN},
};
use sha2::{Digest, Sha256};
pub type Digest = [u8; SHA256_OUTPUT_LEN];
pub type DigestOut = [u8; 256 / 8];
/// Sha256 hash (input gather joined by 0xFF bytes)
#[must_use]
#[tracing::instrument(skip(inputs), level = "trace")]
pub fn delimited<'a, T, I>(mut inputs: I) -> Digest
pub fn delimited<'a, T, I>(mut inputs: I) -> DigestOut
where
I: Iterator<Item = T> + 'a,
T: AsRef<[u8]> + 'a,
{
let mut ctx = Context::new(&SHA256);
let mut ctx = Sha256::new();
if let Some(input) = inputs.next() {
ctx.update(input.as_ref());
for input in inputs {
@@ -22,8 +19,7 @@ where
}
}
ctx.finish()
.as_ref()
ctx.finalize()
.try_into()
.expect("failed to return Digest buffer")
}
@@ -31,18 +27,17 @@ where
/// Sha256 hash (input gather)
#[must_use]
#[tracing::instrument(skip(inputs), level = "trace")]
pub fn concat<'a, T, I>(inputs: I) -> Digest
pub fn concat<'a, T, I>(inputs: I) -> DigestOut
where
I: Iterator<Item = T> + 'a,
T: AsRef<[u8]> + 'a,
{
inputs
.fold(Context::new(&SHA256), |mut ctx, input| {
.fold(Sha256::new(), |mut ctx, input| {
ctx.update(input.as_ref());
ctx
})
.finish()
.as_ref()
.finalize()
.try_into()
.expect("failed to return Digest buffer")
}
@@ -51,12 +46,11 @@ where
#[inline]
#[must_use]
#[tracing::instrument(skip(input), level = "trace")]
pub fn hash<T>(input: T) -> Digest
pub fn hash<T>(input: T) -> DigestOut
where
T: AsRef<[u8]>,
{
digest::digest(&SHA256, input.as_ref())
.as_ref()
Sha256::digest(input)
.try_into()
.expect("failed to return Digest buffer")
}