From 66a535ce503c0b44a0a6481094ac5bbff85c872f Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sat, 18 Feb 2023 18:32:28 -0500 Subject: test pkcs7_unpad --- src/cipherstring.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) 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); + } +} -- cgit v1.2.3-54-g00ecf