This commit is contained in:
parent
2f5489363e
commit
3cafed77aa
3 changed files with 24 additions and 5 deletions
|
|
@ -49,7 +49,9 @@ module H64 = struct
|
||||||
|
|
||||||
let of_octets s =
|
let of_octets s =
|
||||||
match String.length s = 64 with
|
match String.length s = 64 with
|
||||||
| false -> Fmt.failwith "Hash.of_octets failure: data is not 64 bytes"
|
| false ->
|
||||||
|
Fmt.epr "s length: %d@." (String.length s);
|
||||||
|
Fmt.failwith "Hash.of_octets failure: data is not 64 bytes"
|
||||||
| true -> SHA512.of_raw_string s
|
| true -> SHA512.of_raw_string s
|
||||||
|
|
||||||
let to_octets v =
|
let to_octets v =
|
||||||
|
|
|
||||||
23
test/b32.ml
23
test/b32.ml
|
|
@ -1,6 +1,6 @@
|
||||||
let () =
|
let () =
|
||||||
let id s = s |> B32.encode |> B32.decode |> Result.get_ok in
|
let id s = s |> B32.encode |> B32.decode |> Result.get_ok in
|
||||||
let f s =
|
let round_trip s =
|
||||||
let s' = id s in
|
let s' = id s in
|
||||||
match s' = s with
|
match s' = s with
|
||||||
| false ->
|
| false ->
|
||||||
|
|
@ -8,8 +8,25 @@ let () =
|
||||||
| true -> ()
|
| true -> ()
|
||||||
in
|
in
|
||||||
let s = String.init 0xff Char.chr in
|
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
|
let s_l = List.init 0x0f (fun i -> String.init i Char.chr) in
|
||||||
f s;
|
List.iter round_trip s_l; ()
|
||||||
List.iter f s_l;
|
|
||||||
|
let () =
|
||||||
|
let input = "91JPRV3F5GG4EKJNDSJQ8" in
|
||||||
|
Fmt.epr "input length: %d@." (String.length input);
|
||||||
|
let output =
|
||||||
|
input
|
||||||
|
|> Hash.H64.of_b32
|
||||||
|
|> Result.get_ok
|
||||||
|
|> Hash.H64.to_octets
|
||||||
|
|> B32.encode
|
||||||
|
in
|
||||||
|
let expected =
|
||||||
|
"D0R24RZ1TPASVQ2NY56CT8AJDYZE9ZGDB0GVZ05E9D4YGZQW2RC5YFPQ0Q86EPW836DY7VYQTNFFJT3ZR2K508F4JVS5JNJKYN2MMFR"
|
||||||
|
in
|
||||||
|
Fmt.pr "input : %s@." input;
|
||||||
|
Fmt.pr "output : %s@." output;
|
||||||
|
Fmt.pr "expected: %s@." expected;
|
||||||
|
|
||||||
()
|
()
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
(test
|
(test
|
||||||
(name b32)
|
(name b32)
|
||||||
(modules b32)
|
(modules b32)
|
||||||
(libraries b32 fmt))
|
(libraries mte b32 fmt))
|
||||||
|
|
||||||
; TODO
|
; TODO
|
||||||
; cram test?
|
; cram test?
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue