Merge branch 'master' of https://github.com/odin-lang/Odin
This commit is contained in:
commit
0fc5efa50b
5 files changed
+28
-18
No files matched your search
@@ -0,0 +1,2 @@
|
|||||||
|
// package pe implements a reader for the PE executable format for debug purposes
|
||||||
|
package debug_pe
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
|
package encoding_base32
|
||||||
|
|
||||||
// Base32 encoding/decoding implementation as specified in RFC 4648.
|
// Base32 encoding/decoding implementation as specified in RFC 4648.
|
||||||
// [[ More; https://www.rfc-editor.org/rfc/rfc4648.html ]]
|
// [[ More; https://www.rfc-editor.org/rfc/rfc4648.html ]]
|
||||||
package encoding_base32
|
|
||||||
|
|
||||||
// @note(zh): Encoding utility for Base32
|
// @note(zh): Encoding utility for Base32
|
||||||
// A secondary param can be used to supply a custom alphabet to
|
// A secondary param can be used to supply a custom alphabet to
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
// package base32 implements Base32 encoding/decoding, as specified in RFC 4648.
|
||||||
|
package encoding_base32
|
||||||
@@ -1,8 +1,11 @@
|
|||||||
#+test
|
#+test
|
||||||
package encoding_base32
|
package test_encoding_base32
|
||||||
|
|
||||||
import "core:testing"
|
import "core:testing"
|
||||||
import "core:bytes"
|
import "core:bytes"
|
||||||
|
import "core:encoding/base32"
|
||||||
|
|
||||||
|
Error :: base32.Error
|
||||||
|
|
||||||
@(test)
|
@(test)
|
||||||
test_base32_decode_valid :: proc(t: ^testing.T) {
|
test_base32_decode_valid :: proc(t: ^testing.T) {
|
||||||
@@ -20,7 +23,7 @@ test_base32_decode_valid :: proc(t: ^testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for c in cases {
|
for c in cases {
|
||||||
output, err := decode(c.input)
|
output, err := base32.decode(c.input)
|
||||||
if output != nil {
|
if output != nil {
|
||||||
defer delete(output)
|
defer delete(output)
|
||||||
}
|
}
|
||||||
@@ -50,7 +53,7 @@ test_base32_encode :: proc(t: ^testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for c in cases {
|
for c in cases {
|
||||||
output := encode(transmute([]byte)c.input)
|
output := base32.encode(transmute([]byte)c.input)
|
||||||
defer delete(output)
|
defer delete(output)
|
||||||
testing.expect(t, output == c.expected)
|
testing.expect(t, output == c.expected)
|
||||||
}
|
}
|
||||||
@@ -62,7 +65,7 @@ test_base32_decode_invalid :: proc(t: ^testing.T) {
|
|||||||
{
|
{
|
||||||
// Characters outside alphabet
|
// Characters outside alphabet
|
||||||
input := "MZ1W6YTB" // '1' not in alphabet (A-Z, 2-7)
|
input := "MZ1W6YTB" // '1' not in alphabet (A-Z, 2-7)
|
||||||
output, err := decode(input)
|
output, err := base32.decode(input)
|
||||||
if output != nil {
|
if output != nil {
|
||||||
defer delete(output)
|
defer delete(output)
|
||||||
}
|
}
|
||||||
@@ -71,7 +74,7 @@ test_base32_decode_invalid :: proc(t: ^testing.T) {
|
|||||||
{
|
{
|
||||||
// Lowercase not allowed
|
// Lowercase not allowed
|
||||||
input := "mzxq===="
|
input := "mzxq===="
|
||||||
output, err := decode(input)
|
output, err := base32.decode(input)
|
||||||
if output != nil {
|
if output != nil {
|
||||||
defer delete(output)
|
defer delete(output)
|
||||||
}
|
}
|
||||||
@@ -82,7 +85,7 @@ test_base32_decode_invalid :: proc(t: ^testing.T) {
|
|||||||
{
|
{
|
||||||
// Padding must only be at end
|
// Padding must only be at end
|
||||||
input := "MZ=Q===="
|
input := "MZ=Q===="
|
||||||
output, err := decode(input)
|
output, err := base32.decode(input)
|
||||||
if output != nil {
|
if output != nil {
|
||||||
defer delete(output)
|
defer delete(output)
|
||||||
}
|
}
|
||||||
@@ -91,7 +94,7 @@ test_base32_decode_invalid :: proc(t: ^testing.T) {
|
|||||||
{
|
{
|
||||||
// Missing padding
|
// Missing padding
|
||||||
input := "MZXQ" // Should be MZXQ====
|
input := "MZXQ" // Should be MZXQ====
|
||||||
output, err := decode(input)
|
output, err := base32.decode(input)
|
||||||
if output != nil {
|
if output != nil {
|
||||||
defer delete(output)
|
defer delete(output)
|
||||||
}
|
}
|
||||||
@@ -100,7 +103,7 @@ test_base32_decode_invalid :: proc(t: ^testing.T) {
|
|||||||
{
|
{
|
||||||
// Incorrect padding length
|
// Incorrect padding length
|
||||||
input := "MZXQ=" // Needs 4 padding chars
|
input := "MZXQ=" // Needs 4 padding chars
|
||||||
output, err := decode(input)
|
output, err := base32.decode(input)
|
||||||
if output != nil {
|
if output != nil {
|
||||||
defer delete(output)
|
defer delete(output)
|
||||||
}
|
}
|
||||||
@@ -109,7 +112,7 @@ test_base32_decode_invalid :: proc(t: ^testing.T) {
|
|||||||
{
|
{
|
||||||
// Too much padding
|
// Too much padding
|
||||||
input := "MY=========" // Extra padding chars
|
input := "MY=========" // Extra padding chars
|
||||||
output, err := decode(input)
|
output, err := base32.decode(input)
|
||||||
if output != nil {
|
if output != nil {
|
||||||
defer delete(output)
|
defer delete(output)
|
||||||
}
|
}
|
||||||
@@ -120,7 +123,7 @@ test_base32_decode_invalid :: proc(t: ^testing.T) {
|
|||||||
{
|
{
|
||||||
// Single character (invalid block)
|
// Single character (invalid block)
|
||||||
input := "M"
|
input := "M"
|
||||||
output, err := decode(input)
|
output, err := base32.decode(input)
|
||||||
if output != nil {
|
if output != nil {
|
||||||
defer delete(output)
|
defer delete(output)
|
||||||
}
|
}
|
||||||
@@ -141,9 +144,9 @@ test_base32_roundtrip :: proc(t: ^testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for input in cases {
|
for input in cases {
|
||||||
encoded := encode(transmute([]byte)input)
|
encoded := base32.encode(transmute([]byte)input)
|
||||||
defer delete(encoded)
|
defer delete(encoded)
|
||||||
decoded, err := decode(encoded)
|
decoded, err := base32.decode(encoded)
|
||||||
if decoded != nil {
|
if decoded != nil {
|
||||||
defer delete(decoded)
|
defer delete(decoded)
|
||||||
}
|
}
|
||||||
@@ -188,7 +191,7 @@ test_base32_custom_alphabet :: proc(t: ^testing.T) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
custom_validate :: proc(c: byte) -> bool {
|
custom_validate :: proc(c: byte) -> bool {
|
||||||
return (c >= '0' && c <= '9') || (c >= 'A' && c <= 'V') || c == byte(PADDING)
|
return (c >= '0' && c <= '9') || (c >= 'A' && c <= 'V') || c == byte(base32.PADDING)
|
||||||
}
|
}
|
||||||
|
|
||||||
cases := [?]struct {
|
cases := [?]struct {
|
||||||
@@ -202,12 +205,12 @@ test_base32_custom_alphabet :: proc(t: ^testing.T) {
|
|||||||
|
|
||||||
for c in cases {
|
for c in cases {
|
||||||
// Test encoding
|
// Test encoding
|
||||||
encoded := encode(transmute([]byte)c.input, custom_enc_table)
|
encoded := base32.encode(transmute([]byte)c.input, custom_enc_table)
|
||||||
defer delete(encoded)
|
defer delete(encoded)
|
||||||
testing.expect(t, encoded == c.enc_expected)
|
testing.expect(t, encoded == c.enc_expected)
|
||||||
|
|
||||||
// Test decoding
|
// Test decoding
|
||||||
decoded, err := decode(encoded, custom_dec_table, custom_validate)
|
decoded, err := base32.decode(encoded, custom_dec_table, custom_validate)
|
||||||
defer if decoded != nil {
|
defer if decoded != nil {
|
||||||
delete(decoded)
|
delete(decoded)
|
||||||
}
|
}
|
||||||
@@ -219,10 +222,10 @@ test_base32_custom_alphabet :: proc(t: ^testing.T) {
|
|||||||
// Test invalid character detection
|
// Test invalid character detection
|
||||||
{
|
{
|
||||||
input := "WXY=====" // Contains chars not in our alphabet
|
input := "WXY=====" // Contains chars not in our alphabet
|
||||||
output, err := decode(input, custom_dec_table, custom_validate)
|
output, err := base32.decode(input, custom_dec_table, custom_validate)
|
||||||
if output != nil {
|
if output != nil {
|
||||||
delete(output)
|
delete(output)
|
||||||
}
|
}
|
||||||
testing.expect_value(t, err, Error.Invalid_Character)
|
testing.expect_value(t, err, Error.Invalid_Character)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -13,6 +13,7 @@ download_assets :: proc "contextless" () {
|
|||||||
@(require) import "c/libc"
|
@(require) import "c/libc"
|
||||||
@(require) import "compress"
|
@(require) import "compress"
|
||||||
@(require) import "container"
|
@(require) import "container"
|
||||||
|
@(require) import "encoding/base32"
|
||||||
@(require) import "encoding/base64"
|
@(require) import "encoding/base64"
|
||||||
@(require) import "encoding/cbor"
|
@(require) import "encoding/cbor"
|
||||||
@(require) import "encoding/hex"
|
@(require) import "encoding/hex"
|
||||||
|
|||||||
Reference in new issue
Block a user