diff options
| author | Zoltán Kéri <z@zolk3ri.name> | 2024-12-26 14:48:02 +0100 |
|---|---|---|
| committer | Zoltán Kéri <z@zolk3ri.name> | 2024-12-26 14:48:02 +0100 |
| commit | 88c0e62095730354d139af3b90b7d91fa19f5e1a (patch) | |
| tree | 5f51ef8d127f81794b41f4dc4c7446fe6b05201a /core/encoding | |
| parent | e7fb02a84a24f5430199249934a3dc37b10a4d39 (diff) | |
encoding/base32: Use `ENC_TBL` parameter consistently in encode()
Fix encoding to properly use provided encoding table parameter instead of
hardcoded `ENC_TABLE`.
This makes encode properly support custom alphabets as documented.
Diffstat (limited to 'core/encoding')
| -rw-r--r-- | core/encoding/base32/base32.odin | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/core/encoding/base32/base32.odin b/core/encoding/base32/base32.odin index 7c70b7e9a..ea529ed63 100644 --- a/core/encoding/base32/base32.odin +++ b/core/encoding/base32/base32.odin @@ -56,7 +56,7 @@ encode :: proc(data: []byte, ENC_TBL := ENC_TABLE, allocator := context.allocato out_length := (len(data) + 4) / 5 * 8
out := make([]byte, out_length, allocator)
defer delete(out)
- _encode(out, data)
+ _encode(out, data, ENC_TBL)
return string(out[:])
}
@@ -69,26 +69,26 @@ _encode :: proc(out, data: []byte, ENC_TBL := ENC_TABLE, allocator := context.al carry: byte
switch len(data) {
case:
- out[7] = ENC_TABLE[data[4] & 0x1f]
+ out[7] = ENC_TBL[data[4] & 0x1f]
carry = data[4] >> 5
fallthrough
case 4:
- out[6] = ENC_TABLE[carry | (data[3] << 3) & 0x1f]
- out[5] = ENC_TABLE[(data[3] >> 2) & 0x1f]
+ out[6] = ENC_TBL[carry | (data[3] << 3) & 0x1f]
+ out[5] = ENC_TBL[(data[3] >> 2) & 0x1f]
carry = data[3] >> 7
fallthrough
case 3:
- out[4] = ENC_TABLE[carry | (data[2] << 1) & 0x1f]
+ out[4] = ENC_TBL[carry | (data[2] << 1) & 0x1f]
carry = (data[2] >> 4) & 0x1f
fallthrough
case 2:
- out[3] = ENC_TABLE[carry | (data[1] << 4) & 0x1f]
- out[2] = ENC_TABLE[(data[1] >> 1) & 0x1f]
+ out[3] = ENC_TBL[carry | (data[1] << 4) & 0x1f]
+ out[2] = ENC_TBL[(data[1] >> 1) & 0x1f]
carry = (data[1] >> 6) & 0x1f
fallthrough
case 1:
- out[1] = ENC_TABLE[carry | (data[0] << 2) & 0x1f]
- out[0] = ENC_TABLE[data[0] >> 3]
+ out[1] = ENC_TBL[carry | (data[0] << 2) & 0x1f]
+ out[0] = ENC_TBL[data[0] >> 3]
}
if len(data) < 5 {
|