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

Method deserialize

block-buffer/src/lib.rs:338–355  ·  view source on GitHub ↗

Deserialize buffer from a byte array. # Errors If `buf` does not represent a valid serialization of `BlockBuffer`.

(buf: &SerializedBuffer<BS, K>)

Source from the content-addressed store, hash-verified

336 /// # Errors
337 /// If `buf` does not represent a valid serialization of `BlockBuffer`.
338 pub fn deserialize(buf: &SerializedBuffer<BS, K>) -> Result<Self, Error> {
339 let (pos, block) = buf.split_at(1);
340 let pos = usize::from(pos[0]);
341
342 if !<K as sealed::Sealed>::invariant(pos, BS::USIZE) {
343 return Err(Error);
344 }
345
346 let (data, tail) = block.split_at(pos);
347
348 if tail.iter().any(|&b| b != 0) {
349 return Err(Error);
350 }
351
352 let mut res = Self::default();
353 unsafe { res.set_data_unchecked(data) };
354 Ok(res)
355 }
356}
357
358impl<BS: BlockSizes> BlockBuffer<BS, Eager> {

Callers

nothing calls this directly

Calls 3

defaultFunction · 0.85
split_atMethod · 0.80
set_data_uncheckedMethod · 0.80

Tested by

no test coverage detected