Implement crash-safe streaming worker runtime

This commit is contained in:
ms2k 2026-07-17 18:51:44 +09:00
commit cdeef3cc1a

View file

@ -5,6 +5,17 @@ use sha2::{Digest, Sha256};
pub struct IntegrityDigest(String);
impl IntegrityDigest {
pub fn parse(value: impl Into<String>) -> Result<Self, crate::StreamError> {
let value = value.into();
let Some(hex) = value.strip_prefix("sha256:") else {
return Err(crate::StreamError::integrity("invalid integrity digest"));
};
if hex.len() != 64 || !hex.bytes().all(|byte| byte.is_ascii_hexdigit()) {
return Err(crate::StreamError::integrity("invalid integrity digest"));
}
Ok(Self(format!("sha256:{}", hex.to_ascii_lowercase())))
}
#[must_use]
pub fn as_str(&self) -> &str {
&self.0