aboutsummaryrefslogtreecommitdiff
path: root/core/encoding
diff options
context:
space:
mode:
authorzhibog <zhibog-github@web.de>2019-11-01 22:34:19 +0100
committerzhibog <zhibog-github@web.de>2019-11-01 22:34:19 +0100
commit614ea5c16888fccbedf521dc2f7e0e891284f66f (patch)
treedec668228edbc60d36041d7c4428a3d9381b0267 /core/encoding
parent57565b78a632fe67c191fcbe6a18830e67bfb569 (diff)
Added official test vectors from the RFC
Diffstat (limited to 'core/encoding')
-rw-r--r--core/encoding/base64/base64.odin37
1 files changed, 36 insertions, 1 deletions
diff --git a/core/encoding/base64/base64.odin b/core/encoding/base64/base64.odin
index 0224e93e4..b33f9cd5f 100644
--- a/core/encoding/base64/base64.odin
+++ b/core/encoding/base64/base64.odin
@@ -90,4 +90,39 @@ decode :: proc(data: string, DEC_TBL := DEC_TABLE, allocator := context.allocato
out[j + 2] = byte(b2);
}
return out;
-} \ No newline at end of file
+}
+
+// @note(zh): Test inputs. Taken from RFC4648
+/*
+import "core:fmt"
+main :: proc() {
+ Test :: struct {
+ plain: string,
+ encoded: string,
+ };
+
+ test_vectors := [?]Test {
+ Test{"", ""},
+ Test{"f", "Zg=="},
+ Test{"fo", "Zm8="},
+ Test{"foo", "Zm9v"},
+ Test{"foob", "Zm9vYg=="},
+ Test{"fooba", "Zm9vYmE="},
+ Test{"foobar", "Zm9vYmFy"},
+ };
+
+ // Encode test
+ for v in test_vectors {
+ enc := encode(([]byte)(v.plain));
+ fmt.printf("encode(\"%s\") => \"%s\" \t| want: \"%s\"\n", v.plain, enc, v.encoded);
+ delete(enc);
+ }
+
+ // Decode test
+ for v in test_vectors {
+ dec := decode(v.encoded);
+ fmt.printf("decode(\"%s\") => \"%s\" \t| want: \"%s\"\n", v.encoded, string(dec), v.plain);
+ delete(dec);
+ }
+}
+*/ \ No newline at end of file