base32: use '~pad:false'
This commit is contained in:
parent
3124ffb4ad
commit
7a5fe47162
1 changed files with 4 additions and 13 deletions
|
|
@ -5,19 +5,11 @@
|
|||
- '-' is not allowed
|
||||
- checksum is not allowed *)
|
||||
|
||||
(* 'I' 'L' 'O' 'U' excluded
|
||||
no '=' padding in encoded string *)
|
||||
type t = string
|
||||
|
||||
(* 'I' 'L' 'O' 'U' excluded *)
|
||||
let alphabet = Base32.make_alphabet "0123456789ABCDEFGHJKMNPQRSTVWXYZ"
|
||||
|
||||
let encode s =
|
||||
let s = Base32.encode_string ~alphabet s in
|
||||
(* remove '=' padding *)
|
||||
match String.index_opt s '=' with
|
||||
| None -> s
|
||||
| Some i -> String.sub s 0 i
|
||||
|
||||
let decode s =
|
||||
let s =
|
||||
String.map
|
||||
|
|
@ -29,9 +21,8 @@ let decode s =
|
|||
| c -> c)
|
||||
s
|
||||
in
|
||||
(* restore padding for base32 lib *)
|
||||
let n = 8 - (String.length s mod 8) in
|
||||
let pad = String.make n '=' in
|
||||
let s = s ^ pad in
|
||||
Base32.decode ~alphabet ~off:0 ~len:(String.length s) s
|
||||
|> Result.map_error (fun (`Msg e) -> e)
|
||||
|
||||
(* no '=' padding *)
|
||||
let encode s = Base32.encode_string ~pad:false ~alphabet s
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue