diff --git a/src/crockford.ml b/src/crockford.ml index 7a412d24..e8df9ca4 100644 --- a/src/crockford.ml +++ b/src/crockford.ml @@ -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