pub fn remove_padding(data: &[u8]) -> Result<Vec<u8>>Expand description
Removes PKCS#7 padding from padded data.
Validates that the padding is correct before removing it. The padding value indicates how many bytes to remove.
§Arguments
data- The padded data
§Returns
Returns the original data with padding removed.
§Errors
Returns an error if:
- The data is empty
- The padding length is invalid (0, > 16, or > data length)
- The padding bytes are inconsistent
§Examples
use ruscrypt::utils::{pad_data_to_size, remove_padding};
let original = b"Hello, World!";
let padded = pad_data_to_size(original, 16);
let unpadded = remove_padding(&padded).unwrap();
assert_eq!(original, &unpadded[..]);