test: Add padding tests for Base32/Base64

This commit is contained in:
Lőrinc
2024-04-10 13:20:50 +02:00
parent e8cc790fe2
commit ae40cf1a8e
2 changed files with 38 additions and 8 deletions

View File

@@ -29,11 +29,28 @@ BOOST_AUTO_TEST_CASE(base32_testvectors)
BOOST_CHECK_MESSAGE(std::ranges::equal(*dec, vstrIn[i]), vstrOut[i]);
}
BOOST_CHECK(!DecodeBase32("AWSX3VPPinvalid")); // invalid size
BOOST_CHECK( DecodeBase32("AWSX3VPP")); // valid
// Decoding strings with embedded NUL characters should fail
BOOST_CHECK(!DecodeBase32("invalid\0"s)); // correct size, invalid due to \0
BOOST_CHECK(DecodeBase32("AWSX3VPP"s)); // valid
BOOST_CHECK(!DecodeBase32("AWSX3VPP\0invalid"s)); // correct size, invalid due to \0
BOOST_CHECK(!DecodeBase32("AWSX3VPPinvalid"s)); // invalid size
BOOST_CHECK(!DecodeBase32("invalid\0"sv)); // correct size, invalid due to \0
BOOST_CHECK(!DecodeBase32("AWSX3VPP\0invalid"sv)); // correct size, invalid due to \0
}
BOOST_AUTO_TEST_CASE(base32_padding)
{
// Is valid without padding
BOOST_CHECK_EQUAL(EncodeBase32("fooba"), "mzxw6ytb");
// Valid size
BOOST_CHECK(!DecodeBase32("========"));
BOOST_CHECK(!DecodeBase32("a======="));
BOOST_CHECK( DecodeBase32("aa======"));
BOOST_CHECK(!DecodeBase32("aaa====="));
BOOST_CHECK( DecodeBase32("aaaa===="));
BOOST_CHECK( DecodeBase32("aaaaa==="));
BOOST_CHECK(!DecodeBase32("aaaaaa=="));
BOOST_CHECK( DecodeBase32("aaaaaaa="));
}
BOOST_AUTO_TEST_SUITE_END()