mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 23:58:50 +00:00
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.
This commit is contained in:
@@ -56,7 +56,7 @@ encode :: proc(data: []byte, ENC_TBL := ENC_TABLE, allocator := context.allocato
|
|||||||
out_length := (len(data) + 4) / 5 * 8
|
out_length := (len(data) + 4) / 5 * 8
|
||||||
out := make([]byte, out_length, allocator)
|
out := make([]byte, out_length, allocator)
|
||||||
defer delete(out)
|
defer delete(out)
|
||||||
_encode(out, data)
|
_encode(out, data, ENC_TBL)
|
||||||
return string(out[:])
|
return string(out[:])
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,26 +69,26 @@ _encode :: proc(out, data: []byte, ENC_TBL := ENC_TABLE, allocator := context.al
|
|||||||
carry: byte
|
carry: byte
|
||||||
switch len(data) {
|
switch len(data) {
|
||||||
case:
|
case:
|
||||||
out[7] = ENC_TABLE[data[4] & 0x1f]
|
out[7] = ENC_TBL[data[4] & 0x1f]
|
||||||
carry = data[4] >> 5
|
carry = data[4] >> 5
|
||||||
fallthrough
|
fallthrough
|
||||||
case 4:
|
case 4:
|
||||||
out[6] = ENC_TABLE[carry | (data[3] << 3) & 0x1f]
|
out[6] = ENC_TBL[carry | (data[3] << 3) & 0x1f]
|
||||||
out[5] = ENC_TABLE[(data[3] >> 2) & 0x1f]
|
out[5] = ENC_TBL[(data[3] >> 2) & 0x1f]
|
||||||
carry = data[3] >> 7
|
carry = data[3] >> 7
|
||||||
fallthrough
|
fallthrough
|
||||||
case 3:
|
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
|
carry = (data[2] >> 4) & 0x1f
|
||||||
fallthrough
|
fallthrough
|
||||||
case 2:
|
case 2:
|
||||||
out[3] = ENC_TABLE[carry | (data[1] << 4) & 0x1f]
|
out[3] = ENC_TBL[carry | (data[1] << 4) & 0x1f]
|
||||||
out[2] = ENC_TABLE[(data[1] >> 1) & 0x1f]
|
out[2] = ENC_TBL[(data[1] >> 1) & 0x1f]
|
||||||
carry = (data[1] >> 6) & 0x1f
|
carry = (data[1] >> 6) & 0x1f
|
||||||
fallthrough
|
fallthrough
|
||||||
case 1:
|
case 1:
|
||||||
out[1] = ENC_TABLE[carry | (data[0] << 2) & 0x1f]
|
out[1] = ENC_TBL[carry | (data[0] << 2) & 0x1f]
|
||||||
out[0] = ENC_TABLE[data[0] >> 3]
|
out[0] = ENC_TBL[data[0] >> 3]
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(data) < 5 {
|
if len(data) < 5 {
|
||||||
|
|||||||
Reference in New Issue
Block a user