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

Method unpad

block-padding/src/lib.rs:168–180  ·  view source on GitHub ↗
(block: &[u8], strict: bool)

Source from the content-addressed store, hash-verified

166impl Pkcs7 {
167 #[inline]
168 fn unpad(block: &[u8], strict: bool) -> Result<&[u8], Error> {
169 assert!(block.len() <= 255, "block size is too big for PKCS#7");
170 let bs = block.len();
171 let n = block[bs - 1];
172 if n == 0 || n as usize > bs {
173 return Err(Error);
174 }
175 let s = bs - n as usize;
176 if strict && block[s..bs - 1].iter().any(|&v| v != n) {
177 return Err(Error);
178 }
179 Ok(&block[..s])
180 }
181}
182
183impl Padding for Pkcs7 {

Callers

nothing calls this directly

Calls 1

lenMethod · 0.80

Tested by

no test coverage detected