fn pad(buf: &[u8], len: usize) -> Result<Vec<u8>, Error>
Expand description
Creates a new vector with bytes in buf
, left-padded with zeros so
that the result is exactly len
big.
§Errors
Returns an crate::Error::Default
, if the input buffer buf
is
longer than the targeted len
.
§Examples
let input = vec![1, 2, 3];
let output = pad(&input, 4)?;
assert_eq!(output, vec![0, 1, 2, 3]);