fix: base64 decoding

Fix the base64 decoding. If there's an 'A' character in the encoded
text, the base64 decode function returns an INVALID_PADDING error. The
reason lies in the way Base64Decoder.init tries to find a suitable
invalid character. Fix this by defining the invalid character as 0xff
(which is already the case for a decoding without padding).

This error has not been caught by the test harness, because no test
contains an 'A' character in the the encoded text yet. Add a new test.
This commit is contained in:
Koni Marti
2024-11-23 17:43:54 +01:00
committed by Christoffer Lerno
parent 201a6b350e
commit 9b94c1dda9
2 changed files with 10 additions and 19 deletions

View File

@@ -19,6 +19,7 @@ fn void encode()
{ "foob", "Zm9vYg==" },
{ "fooba", "Zm9vYmE=" },
{ "foobar", "Zm9vYmFy" },
{ "test", "dGVzdA==" },
};
foreach (tc : tcases)
{
@@ -41,6 +42,7 @@ fn void encode_nopadding()
{ "foob", "Zm9vYg" },
{ "fooba", "Zm9vYmE" },
{ "foobar", "Zm9vYmFy" },
{ "test", "dGVzdA" },
};
foreach (tc : tcases)
{
@@ -63,6 +65,8 @@ fn void decode()
{ "Zm9vYg==", "foob" },
{ "Zm9vYmE=", "fooba" },
{ "Zm9vYmFy", "foobar" },
{ "Zm9vYmFy", "foobar" },
{ "dGVzdA==", "test" },
};
foreach (tc : tcases)
{
@@ -85,6 +89,7 @@ fn void decode_nopadding()
{ "Zm9vYg", "foob" },
{ "Zm9vYmE", "fooba" },
{ "Zm9vYmFy", "foobar" },
{ "dGVzdA", "test" },
};
foreach (tc : tcases)
{
@@ -95,4 +100,4 @@ fn void decode_nopadding()
usz nn = b.decode(tc.in, buf[:n])!;
assert(buf[:nn] == tc.out);
}
}
}