use crate::utils::{crypto, Apply};
#[derive(Debug)]
#[allow(clippy::exhaustive_enums)]
pub enum AmzContentSha256<'a> {
MultipleChunks,
SingleChunk {
payload_checksum: &'a str,
},
UnsignedPayload,
}
#[derive(Debug, Clone, Copy, thiserror::Error)]
#[error("ParseAmzContentSha256Error")]
pub struct ParseAmzContentSha256Error {
_priv: (),
}
impl<'a> AmzContentSha256<'a> {
pub fn from_header_str(header: &'a str) -> Result<Self, ParseAmzContentSha256Error> {
match header {
"UNSIGNED-PAYLOAD" => Self::UnsignedPayload,
"STREAMING-AWS4-HMAC-SHA256-PAYLOAD" => Self::MultipleChunks,
payload_checksum => {
if !crypto::is_sha256_checksum(payload_checksum) {
return Err(ParseAmzContentSha256Error { _priv: () });
}
Self::SingleChunk { payload_checksum }
}
}
.apply(Ok)
}
}