wip fix mess

This commit is contained in:
swrup 2025-12-15 08:56:44 +01:00
parent 26f5e392ee
commit 50a6137967
6 changed files with 115 additions and 96 deletions

View file

@ -49,16 +49,23 @@ module EddsaPrivateKey = struct
let pub_of_priv = pub_of_priv
let to_octets t = priv_to_octets t
let of_octets t = priv_of_octets t |> Result.get_ok
let bin = Bin.map (Bin.bytes 32) of_octets to_octets
let of_octets t =
priv_of_octets t |> function
| Error err ->
let err = Fmt.str "%a" Mirage_crypto_ec.pp_error err in
Error err
| Ok v -> Ok v
let bin =
let of_octets_exn t = of_octets t |> Result.get_ok in
Bin.map (Bin.bytes 32) of_octets_exn to_octets
let jsont =
let of_b32 s =
let open Syntax in
let* octets = B32.decode s in
match priv_of_octets octets with
| Error e -> Fmt.error "%a" Mirage_crypto_ec.pp_error e
| Ok priv -> Ok priv
of_octets octets
in
let to_b32 t = B32.encode (to_octets t) in
Jsont.of_of_string ~kind:"EddsaPrivateKey" of_b32 ~enc:to_b32
@ -70,7 +77,7 @@ module EddsaSignature : sig
val sign : key:EddsaPrivateKey.t -> string -> t
val verify : key:EddsaPublicKey.t -> t -> msg:string -> bool
val to_octets : t -> string
val of_octets : string -> t
val of_octets : string -> (t, string) result
val jsont : t Jsont.t
val bin : t Bin.t
val caqti : t Caqti_type.t
@ -89,10 +96,12 @@ end = struct
let of_octets v =
match String.length v = 64 with
| false ->
Fmt.failwith "EddsaSignature.of_octets failure: data is not 64 bytes."
| true -> v
Fmt.error "EddsaSignature.of_octets failure: data is not 64 bytes."
| true -> Ok v
let bin = Bin.map (Bin.bytes 64) of_octets to_octets
let bin =
let of_octets_exn t = of_octets t |> Result.get_ok in
Bin.map (Bin.bytes 64) of_octets_exn to_octets
let check_size t =
match String.length t = 64 with
@ -112,7 +121,7 @@ end = struct
let caqti =
Caqti_type.custom
~encode:(fun v -> Ok (to_octets v))
~decode:(fun s -> Ok (of_octets s))
~decode:(fun s -> of_octets s)
Caqti_type.octets
end