hash: use of_raw_string_opt
This commit is contained in:
parent
2f5489363e
commit
16774751d7
5 changed files with 43 additions and 30 deletions
15
test/b32.ml
15
test/b32.ml
|
|
@ -1,15 +0,0 @@
|
|||
let () =
|
||||
let id s = s |> B32.encode |> B32.decode |> Result.get_ok in
|
||||
let f s =
|
||||
let s' = id s in
|
||||
match s' = s with
|
||||
| false ->
|
||||
Fmt.failwith "b32 round trip failure: @\nin :`%S`@\nout:`%S`" s' s
|
||||
| true -> ()
|
||||
in
|
||||
let s = String.init 0xff Char.chr in
|
||||
let s_l = List.init 0x0f (fun i -> String.init i Char.chr) in
|
||||
f s;
|
||||
List.iter f s_l;
|
||||
|
||||
()
|
||||
28
test/crypto.ml
Normal file
28
test/crypto.ml
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
let round_trip s =
|
||||
let s' = s |> B32.encode |> B32.decode |> Result.get_ok in
|
||||
match s' = s with
|
||||
| false -> Fmt.failwith "b32 round trip failure: @\nin :`%S`@\nout:`%S`" s' s
|
||||
| true -> ()
|
||||
|
||||
let () =
|
||||
let s = String.init 0xff Char.chr in
|
||||
round_trip s;
|
||||
let s_l = List.init 0x0f (fun i -> String.init i Char.chr) in
|
||||
List.iter round_trip s_l; ()
|
||||
|
||||
let () =
|
||||
let input = "91JPRV3F5GG4EKJNDSJQ8" in
|
||||
let expected =
|
||||
"D0R24RZ1TPASVQ2NY56CT8AJDYZE9ZGDB0GVZ05E9D4YGZQW2RC5YFPQ0Q86EPW836DY7VYQTNFFJT3ZR2K508F4JVS5JNJKYN2MMFR"
|
||||
in
|
||||
let output =
|
||||
input
|
||||
|> B32.decode
|
||||
|> Result.get_ok
|
||||
|> Hash.H64.hash
|
||||
|> Hash.H64.to_octets
|
||||
|> B32.encode
|
||||
in
|
||||
assert (output = expected);
|
||||
|
||||
()
|
||||
|
|
@ -4,9 +4,9 @@
|
|||
(libraries mte fmt))
|
||||
|
||||
(test
|
||||
(name b32)
|
||||
(modules b32)
|
||||
(libraries b32 fmt))
|
||||
(name crypto)
|
||||
(modules crypto)
|
||||
(libraries mte fmt))
|
||||
|
||||
; TODO
|
||||
; cram test?
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue