MCPcopy Create free account
hub / github.com/RustCrypto/utils / try_new

Method try_new

block-buffer/src/lib.rs:145–155  ·  view source on GitHub ↗
(buf: &[u8])

Source from the content-addressed store, hash-verified

143 /// If slice length is not valid for used buffer kind.
144 #[inline(always)]
145 pub fn try_new(buf: &[u8]) -> Result<Self, Error> {
146 if !K::invariant(buf.len(), BS::USIZE) {
147 return Err(Error);
148 }
149 let mut res = Self::default();
150 // SAFETY: we have checked that buffer length satisfies the buffer kind invariant
151 unsafe {
152 res.set_data_unchecked(buf);
153 }
154 Ok(res)
155 }
156
157 /// Digest data in `input` in blocks of size `BlockSize` using
158 /// the `compress` function, which accepts slice of blocks.

Callers

nothing calls this directly

Calls 3

defaultFunction · 0.85
lenMethod · 0.80
set_data_uncheckedMethod · 0.80

Tested by

no test coverage detected