Implement crash-safe streaming worker runtime
This commit is contained in:
parent
16cba3c317
commit
cdeef3cc1a
1 changed files with 7448 additions and 194 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue