From 7a5fe47162a86c0563a15ba488f9585f6bb13286 Mon Sep 17 00:00:00 2001 From: swrup Date: Wed, 15 Apr 2026 02:45:25 +0200 Subject: [PATCH] base32: use '~pad:false' --- src/crockford.ml | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) 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