This commit is contained in:
swrup 2025-12-07 07:32:27 +01:00
parent c0765bac8e
commit 0e9c6d3860
4 changed files with 15 additions and 11 deletions

View file

@ -23,4 +23,6 @@ let decode s =
| c -> c) | c -> c)
s s
in in
Base32.decode ~alphabet ~off:0 ~len:(String.length s) s match Base32.decode ~alphabet ~off:0 ~len:(String.length s) s with
| Error (`Msg e) -> Error e
| Ok v -> Ok v

View file

@ -10,15 +10,15 @@ module EddsaPublicKey = struct
type t = pub type t = pub
let to_octets t = pub_to_octets t let to_octets t = pub_to_octets t
let of_octets t = pub_of_octets t
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 bin =
let of_octets o = let of_octets o =
match of_octets o with match of_octets o with Error e -> raise (Util.Bin_error e) | Ok v -> v
| Error e ->
let e = Fmt.str "%a" Mirage_crypto_ec.pp_error e in
raise (Util.Bin_error e)
| Ok v -> v
in in
Bin.map (Bin.bytes 32) of_octets to_octets Bin.map (Bin.bytes 32) of_octets to_octets

View file

@ -38,7 +38,7 @@ module Caqti_type = struct
let open EddsaPublicKey in let open EddsaPublicKey in
custom custom
~encode:(fun v -> Ok (to_octets v)) ~encode:(fun v -> Ok (to_octets v))
~decode:(fun v -> Ok (of_octets v)) ~decode:(fun v -> of_octets v)
octets octets
let eddsa_signature : EddsaSignature.t t = let eddsa_signature : EddsaSignature.t t =

View file

@ -54,7 +54,7 @@ module Bin_rsa = struct
Bytes.unsafe_to_string b Bytes.unsafe_to_string b
let check = function let check = function
| false -> Error (`Msg "rsa of_octets error, invalid data") | false -> Error "rsa of_octets error, invalid data"
| true -> Ok () | true -> Ok ()
let z_array_of_octets ~nb s = let z_array_of_octets ~nb s =
@ -90,7 +90,7 @@ module Bin_rsa = struct
let* arr = z_array_of_octets ~nb:2 s in let* arr = z_array_of_octets ~nb:2 s in
match arr with match arr with
| [| n; e |] -> | [| n; e |] ->
let+ pub = Mirage_crypto_pk.Rsa.pub ~n ~e in let+ pub = Mirage_crypto_pk.Rsa.pub ~n ~e |> unwrap_err_msg in
pub pub
| _ -> assert false | _ -> assert false
@ -102,7 +102,9 @@ module Bin_rsa = struct
let* arr = z_array_of_octets ~nb:8 s in let* arr = z_array_of_octets ~nb:8 s in
match arr with match arr with
| [| e; d; n; p; q; dp; dq; q' |] -> | [| e; d; n; p; q; dp; dq; q' |] ->
let+ priv = Mirage_crypto_pk.Rsa.priv ~e ~d ~n ~p ~q ~dp ~dq ~q' in let+ priv =
Mirage_crypto_pk.Rsa.priv ~e ~d ~n ~p ~q ~dp ~dq ~q' |> unwrap_err_msg
in
priv priv
| _ -> assert false | _ -> assert false
end end