rename to lib/
This commit is contained in:
parent
a774ea11ac
commit
7198d3f0f4
9 changed files with 27 additions and 22 deletions
28
src/b32.ml
28
src/b32.ml
|
|
@ -1,28 +0,0 @@
|
|||
(* TODO test *)
|
||||
(* Crockford's variant of Base32
|
||||
http://www.crockford.com/wrmg/base32.html
|
||||
except that:
|
||||
- 'U' is not excluded but also decodes to 'V'
|
||||
- '-' is not allowed
|
||||
- checksum is not allowed *)
|
||||
|
||||
(* 'I' 'L' 'O' 'U' excluded *)
|
||||
type t = string
|
||||
|
||||
let alphabet = Base32.make_alphabet "0123456789ABCDEFGHJKMNPQRSTVWXYZ"
|
||||
let encode s = Base32.encode_string ~alphabet s
|
||||
|
||||
let decode s =
|
||||
let s =
|
||||
String.map
|
||||
(fun c ->
|
||||
match Char.uppercase_ascii c with
|
||||
| 'O' -> '0'
|
||||
| 'I' | 'L' -> '1'
|
||||
| 'U' -> 'V'
|
||||
| c -> c)
|
||||
s
|
||||
in
|
||||
match Base32.decode ~alphabet ~off:0 ~len:(String.length s) s with
|
||||
| Error (`Msg e) -> Error e
|
||||
| Ok v -> Ok v
|
||||
Loading…
Add table
Add a link
Reference in a new issue