| 12 | BOOST_AUTO_TEST_SUITE(base64_tests) |
| 13 | |
| 14 | BOOST_AUTO_TEST_CASE(base64_testvectors) |
| 15 | { |
| 16 | static const std::string vstrIn[] = {"","f","fo","foo","foob","fooba","foobar"}; |
| 17 | static const std::string vstrOut[] = {"","Zg==","Zm8=","Zm9v","Zm9vYg==","Zm9vYmE=","Zm9vYmFy"}; |
| 18 | for (unsigned int i=0; i<std::size(vstrIn); i++) |
| 19 | { |
| 20 | std::string strEnc = EncodeBase64(vstrIn[i]); |
| 21 | BOOST_CHECK_EQUAL(strEnc, vstrOut[i]); |
| 22 | std::string strDec = DecodeBase64(strEnc); |
| 23 | BOOST_CHECK_EQUAL(strDec, vstrIn[i]); |
| 24 | } |
| 25 | |
| 26 | { |
| 27 | const std::vector<uint8_t> in_u{0xff, 0x01, 0xff}; |
| 28 | const std::vector<std::byte> in_b{std::byte{0xff}, std::byte{0x01}, std::byte{0xff}}; |
| 29 | const std::string in_s{"\xff\x01\xff"}; |
| 30 | const std::string out_exp{"/wH/"}; |
| 31 | BOOST_CHECK_EQUAL(EncodeBase64(in_u), out_exp); |
| 32 | BOOST_CHECK_EQUAL(EncodeBase64(in_b), out_exp); |
| 33 | BOOST_CHECK_EQUAL(EncodeBase64(in_s), out_exp); |
| 34 | } |
| 35 | |
| 36 | // Decoding strings with embedded NUL characters should fail |
| 37 | bool failure; |
| 38 | (void)DecodeBase64("invalid\0"s, &failure); |
| 39 | BOOST_CHECK(failure); |
| 40 | (void)DecodeBase64("nQB/pZw="s, &failure); |
| 41 | BOOST_CHECK(!failure); |
| 42 | (void)DecodeBase64("nQB/pZw=\0invalid"s, &failure); |
| 43 | BOOST_CHECK(failure); |
| 44 | (void)DecodeBase64("nQB/pZw=invalid\0"s, &failure); |
| 45 | BOOST_CHECK(failure); |
| 46 | } |
| 47 | |
| 48 | BOOST_AUTO_TEST_SUITE_END() |
nothing calls this directly
no test coverage detected