pub enum Checksum {
Blake3(Hash),
Sha256([u8; 32]),
}Expand description
A checksum value computed with a recognised algorithm (BLAKE3 or SHA-256).
let data = Cursor::new(b"BepInExPack_Valheim-5.4.2202.zip contents");
let ck = Checksum::compute(data, ChecksumAlgorithm::Blake3).unwrap();
assert_eq!(ck.algorithm().to_string(), "blake3");
let as_str = ck.to_string();
let parsed: Checksum = as_str.parse().unwrap();
assert_eq!(ck, parsed);
let ck = Checksum::from_value_str(
"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
ChecksumAlgorithm::Sha256,
).unwrap();
assert_eq!(ck.algorithm().to_string(), "sha256");Variants§
Implementations§
Source§impl Checksum
impl Checksum
Sourcepub fn blake3(hash: Hash) -> Self
pub fn blake3(hash: Hash) -> Self
Create a Checksum::Blake3 from an already-computed blake3::Hash.
Sourcepub fn compute<R>(reader: R, algorithm: ChecksumAlgorithm) -> Result<Self>where
R: Read,
pub fn compute<R>(reader: R, algorithm: ChecksumAlgorithm) -> Result<Self>where
R: Read,
Compute a checksum by reading a byte stream with the chosen algorithm.
let data = Cursor::new(b"some mod archive data");
let ck = Checksum::compute(data, ChecksumAlgorithm::Sha256).unwrap();
assert_eq!(ck.algorithm().to_string(), "sha256");pub fn compute_from_path( path: impl AsRef<Path>, algorithm: ChecksumAlgorithm, ) -> Result<Self>
Sourcepub fn algorithm(&self) -> ChecksumAlgorithm
pub fn algorithm(&self) -> ChecksumAlgorithm
Return which algorithm this checksum was produced with.
Sourcepub fn without_algorithm(&self) -> WithoutAlgorithm<'_>
pub fn without_algorithm(&self) -> WithoutAlgorithm<'_>
Return a wrapper that displays only the hex portion (no algorithm prefix).
Sourcepub fn from_value_str(value: &str, algorithm: ChecksumAlgorithm) -> Result<Self>
pub fn from_value_str(value: &str, algorithm: ChecksumAlgorithm) -> Result<Self>
Parse a checksum from a raw hex string with an explicit algorithm.
Useful when the algorithm and value are stored separately, or when
you have already split "<algo>:<hex>" yourself.
let ck = Checksum::from_value_str(
"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
ChecksumAlgorithm::Sha256,
).unwrap();
assert_eq!(ck.algorithm().to_string(), "sha256");Trait Implementations§
Source§impl<'de> Deserialize<'de> for Checksum
impl<'de> Deserialize<'de> for Checksum
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl Eq for Checksum
impl StructuralPartialEq for Checksum
Auto Trait Implementations§
impl Freeze for Checksum
impl RefUnwindSafe for Checksum
impl Send for Checksum
impl Sync for Checksum
impl Unpin for Checksum
impl UnsafeUnpin for Checksum
impl UnwindSafe for Checksum
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more