diff --git a/rust/Cargo.lock b/rust/Cargo.lock index 77c703ee9..b2a92dcc3 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -321,7 +321,7 @@ dependencies = [ "reqwest 0.12.28", "serde", "serde_json", - "sha2 0.10.9", + "sha2 0.11.0", "tokio", "tracing", ] @@ -368,7 +368,7 @@ dependencies = [ "regex", "serde", "serde_json", - "sha2 0.10.9", + "sha2 0.11.0", "tempfile", "tracing", "windows", @@ -426,7 +426,7 @@ dependencies = [ "regex", "reqwest 0.12.28", "serde_json", - "sha2 0.10.9", + "sha2 0.11.0", "tempfile", "thiserror 2.0.21", "tracing", @@ -4162,7 +4162,7 @@ dependencies = [ "regex", "reqwest 0.12.28", "serde_json", - "sha2 0.10.9", + "sha2 0.11.0", "tar", "tempfile", "zip", diff --git a/rust/crates/aw-ai/Cargo.toml b/rust/crates/aw-ai/Cargo.toml index cf9871f45..0c6d2770e 100644 --- a/rust/crates/aw-ai/Cargo.toml +++ b/rust/crates/aw-ai/Cargo.toml @@ -14,5 +14,5 @@ chrono-tz.workspace = true tracing.workspace = true reqwest.workspace = true regex = "1" -sha2 = "0.10" +sha2 = "0.11" tokio = { version = "1", features = ["rt-multi-thread", "time"] } diff --git a/rust/crates/aw-ai/src/explainer.rs b/rust/crates/aw-ai/src/explainer.rs index e2b459e40..58da7ded6 100644 --- a/rust/crates/aw-ai/src/explainer.rs +++ b/rust/crates/aw-ai/src/explainer.rs @@ -27,6 +27,13 @@ use crate::provider::{ use crate::pyfmt::{self, truthy}; use crate::transport::{self, CancelToken, StreamLimits}; +fn sha256_hex(bytes: &[u8]) -> String { + Sha256::digest(bytes) + .iter() + .map(|b| format!("{b:02x}")) + .collect() +} + /// How long an explanation stays cached. Python's `Cache` is created with /// `ai_cache_ttl`, but the explainer always stores with `ttl=300`. pub const EXPLANATION_CACHE_TTL: Duration = Duration::from_secs(300); @@ -529,7 +536,7 @@ impl AiExplainer { string(&self.effective_system_prompt(style)), string(&self.build_prompt(weather, location_name)), ); - format!("ai_explanation:v2:{:x}", Sha256::digest(dumped.as_bytes())) + format!("ai_explanation:v2:{}", sha256_hex(dumped.as_bytes())) } /// `_text_product_cache_key`. @@ -541,10 +548,10 @@ impl AiExplainer { style: ExplanationStyle, ) -> String { format!( - "ai_text_product:{}:{}:{product_type}:{location_name}:{:x}:{}", + "ai_text_product:{}:{}:{product_type}:{location_name}:{}:{}", self.provider.as_str(), self.effective_model(), - Sha256::digest(product_text.as_bytes()), + sha256_hex(product_text.as_bytes()), style.as_str() ) } diff --git a/rust/crates/aw-notify/Cargo.toml b/rust/crates/aw-notify/Cargo.toml index b33cfd264..748bf5ac6 100644 --- a/rust/crates/aw-notify/Cargo.toml +++ b/rust/crates/aw-notify/Cargo.toml @@ -14,7 +14,7 @@ chrono.workspace = true tracing.workspace = true tempfile.workspace = true regex = "1" -sha2 = "0.10" +sha2 = "0.11" [target.'cfg(windows)'.dependencies] windows = { version = "0.62", features = [ diff --git a/rust/crates/aw-services/Cargo.toml b/rust/crates/aw-services/Cargo.toml index 67bf62a08..d65a24925 100644 --- a/rust/crates/aw-services/Cargo.toml +++ b/rust/crates/aw-services/Cargo.toml @@ -18,7 +18,7 @@ reqwest.workspace = true tempfile.workspace = true url.workspace = true regex = "1" -sha2 = "0.10" +sha2 = "0.11" md5 = "0.8" [target.'cfg(windows)'.dependencies] diff --git a/rust/xtask/Cargo.toml b/rust/xtask/Cargo.toml index f70cc29c6..8f8deccc6 100644 --- a/rust/xtask/Cargo.toml +++ b/rust/xtask/Cargo.toml @@ -16,7 +16,7 @@ flate2 = "1" icns = "0.5" image = { version = "0.25", default-features = false, features = ["png", "ico"] } regex = "1" -sha2 = "0.10" +sha2 = "0.11" tar = "0.4" zip = { version = "9.0.5", default-features = false, features = ["deflate"] } diff --git a/rust/xtask/src/package.rs b/rust/xtask/src/package.rs index 9114321c5..a0a36394c 100644 --- a/rust/xtask/src/package.rs +++ b/rust/xtask/src/package.rs @@ -8,7 +8,7 @@ //! Each artifact gets a `.sha256` beside it. use std::fs; -use std::io::Write; +use std::io::{Read, Write}; use std::path::{Path, PathBuf}; use std::process::Command; @@ -682,12 +682,25 @@ fn remove_file_if_exists(path: &Path) -> Result<()> { /// `.sha256` in `sha256sum` format. fn write_sha256(path: &Path) -> Result<()> { let mut hasher = Sha256::new(); - std::io::copy(&mut fs::File::open(path)?, &mut hasher)?; + let mut file = fs::File::open(path)?; + let mut buf = [0u8; 8192]; + loop { + let n = file.read(&mut buf)?; + if n == 0 { + break; + } + hasher.update(&buf[..n]); + } let name = path .file_name() .expect("artifact has a name") .to_string_lossy(); + let digest = hasher + .finalize() + .iter() + .map(|b| format!("{b:02x}")) + .collect::(); let mut sum = fs::File::create(format!("{}.sha256", path.display()))?; - writeln!(sum, "{:x} {name}", hasher.finalize())?; + writeln!(sum, "{digest} {name}")?; Ok(()) }