From bf5a408e852c79f3373da59c7675c13e53434ff6 Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Thu, 4 Sep 2025 22:04:48 +0200 Subject: 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 --- src/block.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/block.rs') 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 { -- cgit v1.2.3