diff options
author | Jesse Luehrs <doy@tozt.net> | 2023-02-18 18:32:28 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2023-02-18 18:32:28 -0500 |
commit | 66a535ce503c0b44a0a6481094ac5bbff85c872f (patch) | |
tree | 87f8214787b478dd57ff1742ac14f0ca7a514360 /src/cipherstring.rs | |
parent | 71fd9206176ab8a22969dcfc01772851604f99e7 (diff) | |
download | rbw-66a535ce503c0b44a0a6481094ac5bbff85c872f.tar.gz rbw-66a535ce503c0b44a0a6481094ac5bbff85c872f.zip |
test pkcs7_unpad
Diffstat (limited to 'src/cipherstring.rs')
-rw-r--r-- | src/cipherstring.rs | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/cipherstring.rs b/src/cipherstring.rs index 971929f..883cb34 100644 --- a/src/cipherstring.rs +++ b/src/cipherstring.rs @@ -290,3 +290,25 @@ fn pkcs7_unpad(b: &[u8]) -> Option<&[u8]> { Some(&b[..b.len() - padding_len]) } + +#[test] +fn test_pkcs7_unpad() { + let tests = [ + (&[][..], None), + (&[0x01][..], Some(&[][..])), + (&[0x02, 0x02][..], Some(&[][..])), + (&[0x03, 0x03, 0x03][..], Some(&[][..])), + (&[0x69, 0x01][..], Some(&[0x69][..])), + (&[0x69, 0x02, 0x02][..], Some(&[0x69][..])), + (&[0x69, 0x03, 0x03, 0x03][..], Some(&[0x69][..])), + (&[0x02][..], None), + (&[0x03][..], None), + (&[0x69, 0x69, 0x03, 0x03][..], None), + (&[0x00][..], None), + (&[0x02, 0x00][..], None), + ]; + for (input, expected) in tests { + let got = pkcs7_unpad(input); + assert_eq!(got, expected); + } +} |