diff options
author | Daniel Schadt <kingdread@gmx.de> | 2025-09-04 22:04:48 +0200 |
---|---|---|
committer | Daniel Schadt <kingdread@gmx.de> | 2025-09-04 22:04:48 +0200 |
commit | bf5a408e852c79f3373da59c7675c13e53434ff6 (patch) | |
tree | 246ef4943b3e89425fdbfbbfb69d3dc91d20a5f9 /src/block.rs | |
parent | 4b83bfcad25c8d8e36fe210a76faa5797f9c5aaf (diff) | |
download | zears-bf5a408e852c79f3373da59c7675c13e53434ff6.tar.gz zears-bf5a408e852c79f3373da59c7675c13e53434ff6.tar.bz2 zears-bf5a408e852c79f3373da59c7675c13e53434ff6.zip |
inline pad_to_blocks
I like the way with chunks_exact more, as we get the remainder for free
and we don't have to do the chunk.len() dance
Diffstat (limited to 'src/block.rs')
-rw-r--r-- | src/block.rs | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/block.rs b/src/block.rs index e1140e7..2b7907a 100644 --- a/src/block.rs +++ b/src/block.rs @@ -94,6 +94,16 @@ impl Block { result } + /// Pad the block to full length. + /// + /// Unlike [`pad`], this function takes the length in bytes. + pub fn pad_bytes(&self, length: u8) -> Block { + assert!(length <= 15); + let mut result = *self; + result[length as usize] = 0x80; + result + } + /// Clip the block by setting all bits beyond the given length to 0. pub fn clip(&self, length: usize) -> Block { match length { |