|
@@ -181,20 +181,20 @@ static void TestEncodeDecodeIntoString(const TString& plain, const TString& enco
|
|
|
|
|
|
static void TestEncodeStrictDecodeIntoString(const TString& plain, const TString& encoded, const TString& encodedUrl) {
|
|
|
TString a, b;
|
|
|
-
|
|
|
- Base64Encode(plain, a);
|
|
|
- UNIT_ASSERT_VALUES_EQUAL(a, encoded);
|
|
|
-
|
|
|
- Base64StrictDecode(a, b);
|
|
|
- UNIT_ASSERT_VALUES_EQUAL(b, plain);
|
|
|
-
|
|
|
- Base64EncodeUrl(plain, a);
|
|
|
- UNIT_ASSERT_VALUES_EQUAL(a, encodedUrl);
|
|
|
-
|
|
|
- Base64StrictDecode(a, b);
|
|
|
- UNIT_ASSERT_VALUES_EQUAL(b, plain);
|
|
|
-}
|
|
|
-
|
|
|
+
|
|
|
+ Base64Encode(plain, a);
|
|
|
+ UNIT_ASSERT_VALUES_EQUAL(a, encoded);
|
|
|
+
|
|
|
+ Base64StrictDecode(a, b);
|
|
|
+ UNIT_ASSERT_VALUES_EQUAL(b, plain);
|
|
|
+
|
|
|
+ Base64EncodeUrl(plain, a);
|
|
|
+ UNIT_ASSERT_VALUES_EQUAL(a, encodedUrl);
|
|
|
+
|
|
|
+ Base64StrictDecode(a, b);
|
|
|
+ UNIT_ASSERT_VALUES_EQUAL(b, plain);
|
|
|
+}
|
|
|
+
|
|
|
Y_UNIT_TEST_SUITE(TBase64) {
|
|
|
Y_UNIT_TEST(TestEncode) {
|
|
|
UNIT_ASSERT_VALUES_EQUAL(Base64Encode("12z"), "MTJ6");
|
|
@@ -210,24 +210,24 @@ Y_UNIT_TEST_SUITE(TBase64) {
|
|
|
str += char(i);
|
|
|
|
|
|
const TString base64 =
|
|
|
- "AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJy"
|
|
|
- "gpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9Q"
|
|
|
- "UVJTVFVWV1hZWltcXV5fY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4eLj5OXm5-jp6uvs7e7v8PHy"
|
|
|
- "8_T19vf4-fr7_P3-_w,,";
|
|
|
+ "AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJy"
|
|
|
+ "gpKissLS4vMDEyMzQ1Njc4OTo7PD0-P0BBQkNERUZHSElKS0xNTk9Q"
|
|
|
+ "UVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eH"
|
|
|
+ "l6e3x9fn-AgYKDhIWGh4iJiouMjY6PkJGSk5SVlpeYmZqbnJ2en6Ch"
|
|
|
+ "oqOkpaanqKmqq6ytrq-wsbKztLW2t7i5uru8vb6_wMHCw8TFxsfIyc"
|
|
|
+ "rLzM3Oz9DR0tPU1dbX2Nna29zd3t_g4eLj5OXm5-jp6uvs7e7v8PHy"
|
|
|
+ "8_T19vf4-fr7_P3-_w,,";
|
|
|
|
|
|
TestEncodeDecodeIntoString(str, base64, base64Url);
|
|
|
- TestEncodeStrictDecodeIntoString(str, base64, base64Url);
|
|
|
+ TestEncodeStrictDecodeIntoString(str, base64, base64Url);
|
|
|
}
|
|
|
|
|
|
{
|
|
@@ -237,36 +237,36 @@ Y_UNIT_TEST_SUITE(TBase64) {
|
|
|
const TString base64Url = "aHR0cDovL3lhbmRleC5ydToxMjM0L3JlcXVlc3Q_cGFyYW09dmFsdWUmbGxsPWZmZiNmcmFnbWVudA,,";
|
|
|
|
|
|
TestEncodeDecodeIntoString(str, base64, base64Url);
|
|
|
- TestEncodeStrictDecodeIntoString(str, base64, base64Url);
|
|
|
+ TestEncodeStrictDecodeIntoString(str, base64, base64Url);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
Y_UNIT_TEST(TestDecode) {
|
|
|
- UNIT_ASSERT_EXCEPTION(Base64Decode("a"), yexception);
|
|
|
- UNIT_ASSERT_EXCEPTION(Base64StrictDecode("a"), yexception);
|
|
|
-
|
|
|
- UNIT_ASSERT_VALUES_EQUAL(Base64Decode(""), "");
|
|
|
- UNIT_ASSERT_VALUES_EQUAL(Base64StrictDecode(""), "");
|
|
|
-
|
|
|
+ UNIT_ASSERT_EXCEPTION(Base64Decode("a"), yexception);
|
|
|
+ UNIT_ASSERT_EXCEPTION(Base64StrictDecode("a"), yexception);
|
|
|
+
|
|
|
+ UNIT_ASSERT_VALUES_EQUAL(Base64Decode(""), "");
|
|
|
+ UNIT_ASSERT_VALUES_EQUAL(Base64StrictDecode(""), "");
|
|
|
+
|
|
|
UNIT_ASSERT_VALUES_EQUAL(Base64Decode("MTI="), "12");
|
|
|
- UNIT_ASSERT_VALUES_EQUAL(Base64StrictDecode("MTI="), "12");
|
|
|
-
|
|
|
- UNIT_ASSERT_VALUES_EQUAL(Base64Decode("QQ=="), "A");
|
|
|
- UNIT_ASSERT_VALUES_EQUAL(Base64StrictDecode("QQ=="), "A");
|
|
|
-
|
|
|
- UNIT_ASSERT_EXCEPTION(Base64StrictDecode("M=I="), yexception);
|
|
|
-
|
|
|
- UNIT_ASSERT_VALUES_EQUAL(Base64Decode("dnluZHg="), "vyndx");
|
|
|
- UNIT_ASSERT_VALUES_EQUAL(Base64StrictDecode("dnluZHg="), "vyndx");
|
|
|
-
|
|
|
- UNIT_ASSERT_VALUES_EQUAL(Base64StrictDecode("dnluZHg=dmlkZW8="), "vyndxvideo");
|
|
|
-
|
|
|
- UNIT_ASSERT_EXCEPTION(Base64StrictDecode("aHR0cDovL2ltZy5tZWdhLXBvcm5vLnJ1Lw=a"), yexception);
|
|
|
-
|
|
|
- UNIT_ASSERT_EXCEPTION(Base64StrictDecode("aHh=="), yexception);
|
|
|
- UNIT_ASSERT_EXCEPTION(Base64StrictDecode("\1\1\1\2"), yexception);
|
|
|
+ UNIT_ASSERT_VALUES_EQUAL(Base64StrictDecode("MTI="), "12");
|
|
|
+
|
|
|
+ UNIT_ASSERT_VALUES_EQUAL(Base64Decode("QQ=="), "A");
|
|
|
+ UNIT_ASSERT_VALUES_EQUAL(Base64StrictDecode("QQ=="), "A");
|
|
|
+
|
|
|
+ UNIT_ASSERT_EXCEPTION(Base64StrictDecode("M=I="), yexception);
|
|
|
+
|
|
|
+ UNIT_ASSERT_VALUES_EQUAL(Base64Decode("dnluZHg="), "vyndx");
|
|
|
+ UNIT_ASSERT_VALUES_EQUAL(Base64StrictDecode("dnluZHg="), "vyndx");
|
|
|
+
|
|
|
+ UNIT_ASSERT_VALUES_EQUAL(Base64StrictDecode("dnluZHg=dmlkZW8="), "vyndxvideo");
|
|
|
+
|
|
|
+ UNIT_ASSERT_EXCEPTION(Base64StrictDecode("aHR0cDovL2ltZy5tZWdhLXBvcm5vLnJ1Lw=a"), yexception);
|
|
|
+
|
|
|
+ UNIT_ASSERT_EXCEPTION(Base64StrictDecode("aHh=="), yexception);
|
|
|
+ UNIT_ASSERT_EXCEPTION(Base64StrictDecode("\1\1\1\2"), yexception);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
Y_UNIT_TEST(TestDecodeUneven) {
|
|
|
UNIT_ASSERT_VALUES_EQUAL(Base64DecodeUneven(""), "");
|
|
|
|
|
@@ -287,15 +287,15 @@ Y_UNIT_TEST_SUITE(TBase64) {
|
|
|
|
|
|
Y_UNIT_TEST(TestDecodeRandom) {
|
|
|
TString input;
|
|
|
- constexpr size_t testSize = 240000;
|
|
|
- for (size_t i = 0; i < testSize; ++i) {
|
|
|
- input.push_back(rand() % 256);
|
|
|
- }
|
|
|
+ constexpr size_t testSize = 240000;
|
|
|
+ for (size_t i = 0; i < testSize; ++i) {
|
|
|
+ input.push_back(rand() % 256);
|
|
|
+ }
|
|
|
TString output;
|
|
|
TString encoded = Base64Encode(input);
|
|
|
- UNIT_ASSERT_VALUES_EQUAL(Base64Decode(encoded), input);
|
|
|
- UNIT_ASSERT_VALUES_EQUAL(Base64StrictDecode(encoded), input);
|
|
|
- }
|
|
|
+ UNIT_ASSERT_VALUES_EQUAL(Base64Decode(encoded), input);
|
|
|
+ UNIT_ASSERT_VALUES_EQUAL(Base64StrictDecode(encoded), input);
|
|
|
+ }
|
|
|
|
|
|
Y_UNIT_TEST(TestAllPossibleOctets) {
|
|
|
const TString x("\0\x01\x02\x03\x04\x05\x06\x07\b\t\n\x0B\f\r\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\x7F"sv);
|