mirror of
https://github.com/Retropex/bitcoin.git
synced 2025-06-02 23:42:33 +02:00
test: Add padding tests for Base32/Base64
This commit is contained in:
parent
e8cc790fe2
commit
ae40cf1a8e
@ -29,11 +29,28 @@ BOOST_AUTO_TEST_CASE(base32_testvectors)
|
|||||||
BOOST_CHECK_MESSAGE(std::ranges::equal(*dec, vstrIn[i]), vstrOut[i]);
|
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
|
// Decoding strings with embedded NUL characters should fail
|
||||||
BOOST_CHECK(!DecodeBase32("invalid\0"s)); // correct size, invalid due to \0
|
BOOST_CHECK(!DecodeBase32("invalid\0"sv)); // correct size, invalid due to \0
|
||||||
BOOST_CHECK(DecodeBase32("AWSX3VPP"s)); // valid
|
BOOST_CHECK(!DecodeBase32("AWSX3VPP\0invalid"sv)); // correct size, invalid due to \0
|
||||||
BOOST_CHECK(!DecodeBase32("AWSX3VPP\0invalid"s)); // correct size, invalid due to \0
|
}
|
||||||
BOOST_CHECK(!DecodeBase32("AWSX3VPPinvalid"s)); // invalid size
|
|
||||||
|
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()
|
BOOST_AUTO_TEST_SUITE_END()
|
||||||
|
@ -36,11 +36,24 @@ BOOST_AUTO_TEST_CASE(base64_testvectors)
|
|||||||
BOOST_CHECK_EQUAL(EncodeBase64(in_s), out_exp);
|
BOOST_CHECK_EQUAL(EncodeBase64(in_s), out_exp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOST_CHECK(DecodeBase64("nQB/pZw=")); // valid
|
||||||
|
|
||||||
// Decoding strings with embedded NUL characters should fail
|
// Decoding strings with embedded NUL characters should fail
|
||||||
BOOST_CHECK(!DecodeBase64("invalid\0"s));
|
BOOST_CHECK(!DecodeBase64("invalid\0"sv)); // correct size, invalid due to \0
|
||||||
BOOST_CHECK(DecodeBase64("nQB/pZw="s));
|
BOOST_CHECK(!DecodeBase64("nQB/pZw=\0invalid"sv));
|
||||||
BOOST_CHECK(!DecodeBase64("nQB/pZw=\0invalid"s));
|
BOOST_CHECK(!DecodeBase64("nQB/pZw=invalid\0"sv)); // invalid, padding only allowed at the end
|
||||||
BOOST_CHECK(!DecodeBase64("nQB/pZw=invalid\0"s));
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(base64_padding)
|
||||||
|
{
|
||||||
|
// Is valid without padding
|
||||||
|
BOOST_CHECK_EQUAL(EncodeBase64("foobar"), "Zm9vYmFy");
|
||||||
|
|
||||||
|
// Valid size
|
||||||
|
BOOST_CHECK(!DecodeBase64("===="));
|
||||||
|
BOOST_CHECK(!DecodeBase64("a==="));
|
||||||
|
BOOST_CHECK( DecodeBase64("YQ=="));
|
||||||
|
BOOST_CHECK( DecodeBase64("YWE="));
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE_END()
|
BOOST_AUTO_TEST_SUITE_END()
|
||||||
|
Loading…
Reference in New Issue
Block a user