2022-09-27 09:25:50 +03:00
|
|
|
import encoding.base32
|
|
|
|
|
|
|
|
// TODO: add more tests
|
|
|
|
|
|
|
|
fn test_encode_and_decode() {
|
|
|
|
input := 'hello v'
|
|
|
|
|
|
|
|
encoded := base32.encode_string_to_string(input)
|
|
|
|
assert encoded == 'NBSWY3DPEB3A===='
|
2022-09-27 09:29:44 +03:00
|
|
|
|
2022-11-15 16:53:13 +03:00
|
|
|
decoded := base32.decode_string_to_string(encoded) or { panic('error decoding: ${err}') }
|
2022-09-27 09:25:50 +03:00
|
|
|
assert decoded == input
|
|
|
|
|
|
|
|
encoder_no_padding := base32.new_std_encoding_with_padding(base32.no_padding)
|
|
|
|
encoded2 := encoder_no_padding.encode_string_to_string(input)
|
|
|
|
assert encoded2 == 'NBSWY3DPEB3A'
|
|
|
|
|
|
|
|
decoded2 := encoder_no_padding.decode_string_to_string(encoded2) or {
|
2022-11-15 16:53:13 +03:00
|
|
|
panic('error decoding: ${err}')
|
2022-09-27 09:25:50 +03:00
|
|
|
}
|
|
|
|
assert decoded2 == input
|
|
|
|
}
|