diff options
| author | tv <tv@krebsco.de> | 2026-10-31 05:22:02 +0100 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-10-31 05:22:02 +0100 |
| commit | 27df21d3eadd6c28b7775e5b1a0a57e89b6b1d8b (patch) | |
| tree | 13a79aeaeebeea21afd0b2bb3dd85866915ac3ab /src/api | |
| parent | 76e91dfc62bc76228df8c07abf6e012e777c4eca (diff) | |
unify hex builders
Diffstat (limited to 'src/api')
| -rw-r--r-- | src/api/dashboard/mod.rs | 8 | ||||
| -rw-r--r-- | src/api/store.rs | 9 |
2 files changed, 4 insertions, 13 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> { |
