wip better errors

This commit is contained in:
swrup 2025-12-07 06:39:33 +01:00
parent f8ef92b67e
commit e239f802b1
3 changed files with 16 additions and 6 deletions

View file

@ -10,15 +10,23 @@ module EddsaPublicKey = struct
type t = pub
let to_octets t = pub_to_octets t
let of_octets t = pub_of_octets t |> Result.get_ok
let bin = Bin.map (Bin.bytes 32) of_octets to_octets
let of_octets t =
pub_of_octets t |> function
| Error e -> Fmt.error "%a" Mirage_crypto_ec.pp_error e
| Ok v -> Ok v
let bin =
let of_octets o =
match of_octets o with Error e -> raise (Util.Bin_error e) | Ok v -> v
in
Bin.map (Bin.bytes 32) of_octets to_octets
let of_b32 s =
let open Syntax in
let* octets = B32.decode s in
match pub_of_octets octets with
| Error e -> Fmt.error "%a" Mirage_crypto_ec.pp_error e
| Ok pub -> Ok pub
let* pub = of_octets octets in
Ok pub
let to_b32 t = B32.encode (to_octets t)
let jsont = Jsont.of_of_string ~kind:"EddsaPublicKey" of_b32 ~enc:to_b32