pub struct Sha256Digest(/* private fields */);Expand description
Raw SHA-256 identity, without a product-specific prefix or wire format.
Implementations§
Source§impl Sha256Digest
impl Sha256Digest
Sourcepub const fn from_bytes(bytes: [u8; 32]) -> Self
pub const fn from_bytes(bytes: [u8; 32]) -> Self
Construct an identity from exact digest bytes.
Sourcepub fn compute(bytes: &[u8]) -> Self
pub fn compute(bytes: &[u8]) -> Self
Hash bytes already held by the caller.
Examples found in repository?
examples/inspect_regular_file.rs (line 28)
4fn main() -> Result<(), Box<dyn std::error::Error>> {
5 use ic_host_tools::artifact::{Sha256Digest, read_file_no_follow};
6 use std::{io, path::Path};
7
8 let mut args = std::env::args_os().skip(1);
9 let path = args.next().ok_or_else(|| {
10 io::Error::new(
11 io::ErrorKind::InvalidInput,
12 "usage: inspect_regular_file PATH MAX_BYTES",
13 )
14 })?;
15 let max_bytes = args
16 .next()
17 .ok_or_else(|| io::Error::new(io::ErrorKind::InvalidInput, "missing byte limit"))?
18 .into_string()
19 .map_err(|_| io::Error::new(io::ErrorKind::InvalidInput, "byte limit must be UTF-8"))?
20 .parse()?;
21 if args.next().is_some() {
22 return Err(io::Error::new(io::ErrorKind::InvalidInput, "unexpected argument").into());
23 }
24 let bytes = read_file_no_follow(Path::new(&path), max_bytes)?;
25 println!(
26 "raw_bytes={} sha256={}",
27 bytes.len(),
28 Sha256Digest::compute(&bytes)
29 );
30 Ok(())
31}Trait Implementations§
Source§impl Clone for Sha256Digest
impl Clone for Sha256Digest
impl Copy for Sha256Digest
Source§impl Debug for Sha256Digest
impl Debug for Sha256Digest
Source§impl Display for Sha256Digest
impl Display for Sha256Digest
impl Eq for Sha256Digest
Source§impl FromStr for Sha256Digest
impl FromStr for Sha256Digest
Source§impl Hash for Sha256Digest
impl Hash for Sha256Digest
Source§impl PartialEq for Sha256Digest
impl PartialEq for Sha256Digest
impl StructuralPartialEq for Sha256Digest
Auto Trait Implementations§
impl Freeze for Sha256Digest
impl RefUnwindSafe for Sha256Digest
impl Send for Sha256Digest
impl Sync for Sha256Digest
impl Unpin for Sha256Digest
impl UnsafeUnpin for Sha256Digest
impl UnwindSafe for Sha256Digest
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