aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-10-31 05:22:02 +0100
committertv <tv@krebsco.de>2026-10-31 05:22:02 +0100
commit204a38965c2c2e360ebdfeb357c6cfce50a3654d (patch)
tree6aa23e2f85d36b2b2b50f817a10301783f154041 /src
parentba64c49fda6f2b4c9eb91eb3d311bdf9b9b98954 (diff)
unify hex builders
Diffstat (limited to 'src')
-rw-r--r--src/api/dashboard/mod.rs8
-rw-r--r--src/api/store.rs9
-rw-r--r--src/document/replica.rs2
-rw-r--r--src/swarm/auth.rs2
-rw-r--r--src/swarm/topology/tests.rs2
-rw-r--r--src/transport/wire.rs2
6 files changed, 8 insertions, 17 deletions
diff --git a/src/api/dashboard/mod.rs b/src/api/dashboard/mod.rs
index 87f5aeb..c284f6f 100644
--- a/src/api/dashboard/mod.rs
+++ b/src/api/dashboard/mod.rs
@@ -31,7 +31,7 @@ use tokio::time::Instant;
use crate::locks::MutexExt;
use crate::state::AppState;
use crate::swarm::{links, members, topology};
-use crate::transport::Link;
+use crate::transport::{Hex, Link};
/// How often the snapshot is built and compared, while anyone looks.
const TICK: Duration = Duration::from_secs(2);
@@ -411,11 +411,7 @@ fn page() -> &'static (String, String) {
let growing = serde_json::to_string(GROWING).unwrap_or_else(|_| "[]".to_owned());
let page = PAGE.replace(GROWING_MARK, &growing);
// Of the page with its list: a new list is a new version too.
- let version: String = Sha256::digest(page.as_bytes())
- .iter()
- .take(8)
- .map(|byte| format!("{byte:02x}"))
- .collect();
+ let version = Hex(&Sha256::digest(page.as_bytes())[..8]).to_string();
let served = page.replace(PAGE_VERSION_MARK, &version);
(version, served)
})
diff --git a/src/api/store.rs b/src/api/store.rs
index bd4ae8e..c67df85 100644
--- a/src/api/store.rs
+++ b/src/api/store.rs
@@ -24,6 +24,7 @@ use super::{ApiError, store_status};
use crate::document::meta;
use crate::document::store::{self, StoreError, paths_related};
use crate::state::{AppState, ReadSource};
+use crate::transport::Hex;
#[derive(Debug, Default, Deserialize)]
pub(crate) struct ReadQuery {
@@ -209,13 +210,7 @@ pub(crate) async fn put_store_entry(
}
fn etag_for(bytes: &[u8]) -> String {
- let digest = Sha256::digest(bytes);
- let hex = digest
- .iter()
- .map(|byte| format!("{byte:02x}"))
- .collect::<String>();
-
- format!("\"{hex}\"")
+ format!("\"{}\"", Hex(&Sha256::digest(bytes)))
}
fn parse_key_path(key: &str) -> Result<Vec<String>, StatusCode> {
diff --git a/src/document/replica.rs b/src/document/replica.rs
index c8f648b..8640c7e 100644
--- a/src/document/replica.rs
+++ b/src/document/replica.rs
@@ -55,7 +55,7 @@ impl Epoch {
}
pub(crate) fn id_hex(&self) -> String {
- self.id.iter().map(|byte| format!("{byte:02x}")).collect()
+ crate::transport::Hex(&self.id).to_string()
}
}
diff --git a/src/swarm/auth.rs b/src/swarm/auth.rs
index 088f615..50e2fae 100644
--- a/src/swarm/auth.rs
+++ b/src/swarm/auth.rs
@@ -172,7 +172,7 @@ mod tests {
use super::*;
fn hex(bytes: &[u8]) -> String {
- bytes.iter().map(|byte| format!("{byte:02x}")).collect()
+ crate::transport::Hex(bytes).to_string()
}
#[test]
diff --git a/src/swarm/topology/tests.rs b/src/swarm/topology/tests.rs
index d1b755f..d3a3e38 100644
--- a/src/swarm/topology/tests.rs
+++ b/src/swarm/topology/tests.rs
@@ -49,7 +49,7 @@ fn edges(graph: &BTreeMap<String, BTreeSet<String>>) -> BTreeSet<(String, String
}
fn hex(bytes: [u8; 32]) -> String {
- bytes.iter().map(|byte| format!("{byte:02x}")).collect()
+ crate::transport::Hex(&bytes).to_string()
}
/// Over random swarms (size, `k`, who is reachable, who is stable): links only
diff --git a/src/transport/wire.rs b/src/transport/wire.rs
index 28bd431..00bc739 100644
--- a/src/transport/wire.rs
+++ b/src/transport/wire.rs
@@ -590,7 +590,7 @@ mod tests {
}
fn hex(bytes: &[u8]) -> String {
- bytes.iter().map(|byte| format!("{byte:02x}")).collect()
+ crate::transport::Hex(bytes).to_string()
}
/// The exact bytes of a few messages. If this fails after a change to a message type