diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2021-03-13 07:54:12 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2021-03-13 07:54:12 +0000 |
commit | 4754ed45b607e82450a5e31fea1da3ba61433b04 (patch) | |
tree | 3554490bdc003e6004f605abe41929cdf98b0651 /src/test/test_base64url.lua | |
parent | Initial commit. (diff) | |
download | dnsjit-4754ed45b607e82450a5e31fea1da3ba61433b04.tar.xz dnsjit-4754ed45b607e82450a5e31fea1da3ba61433b04.zip |
Adding upstream version 1.1.0+debian.upstream/1.1.0+debian
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | src/test/test_base64url.lua | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/test/test_base64url.lua b/src/test/test_base64url.lua new file mode 100644 index 0000000..00aea6a --- /dev/null +++ b/src/test/test_base64url.lua @@ -0,0 +1,24 @@ +base64url = require("dnsjit.lib.base64url") +ffi = require("ffi") + +-- empty string works +assert(base64url.decode(base64url.encode("")) == "") + +-- regular string data +assert(base64url.encode("abcd") == "YWJjZA") +assert(base64url.decode(base64url.encode("abcd")) == "abcd") + +-- invalid base64 data +base64url.decode("+") + +-- check all symbols - arbitrary binary data +c_array = ffi.new("uint8_t[?]", 256) +bin_symbols = {} +for i = 0, 255 do + bin_symbols[i + 1] = string.char(i) + c_array[i] = i +end +bin_str = table.concat(bin_symbols) + +assert(base64url.decode(base64url.encode(bin_str)) == bin_str) +assert(base64url.encode(c_array, 256) == base64url.encode(bin_str)) |