This commit is contained in:
Matthieu Dubuget committed 2026-11-22 18:19:16 +01:00
commit 42e5e3321a
12 files changed
+593

No files matched your search

+2
View File
@@ -0,0 +1,2 @@
(library
(name totpin_base32))
+18
View File
@@ -0,0 +1,18 @@
let decode s =
let value = function
| 'a' .. 'z' as c -> Char.code c - Char.code 'a'
| 'A' .. 'Z' as c -> Char.code c - Char.code 'A'
| c -> Char.code c - Char.code '2' + 26
in
let buf = Buffer.create 32 in
let acc = ref 0 and bits = ref 0 in
String.iter
(fun c ->
acc := (!acc lsl 5) lor value c;
bits := !bits + 5;
if !bits >= 8 then begin
bits := !bits - 8;
Buffer.add_char buf (Char.chr ((!acc lsr !bits) land 0xff))
end)
s;
Buffer.contents buf
+6
View File
@@ -0,0 +1,6 @@
(** Décodage base32 (RFC 4648) pour les secrets TOTP. *)
val decode : string -> string
(** [decode s] est la chaîne d'octets codée par [s], sans remplissage [=]. [s]
ne doit contenir que des caractères de [A-Za-z2-7] : aucune validation n'est
faite. Les bits restants à la fin sont ignorés. *)