This commit is contained in:
parent
f8ef92b67e
commit
ec9e58ab6b
3 changed files with 19 additions and 13 deletions
|
|
@ -23,6 +23,4 @@ let decode s =
|
|||
| c -> c)
|
||||
s
|
||||
in
|
||||
match Base32.decode ~alphabet ~off:0 ~len:(String.length s) s with
|
||||
| Error (`Msg e) -> Error e
|
||||
| Ok v -> Ok v
|
||||
Base32.decode ~alphabet ~off:0 ~len:(String.length s) s
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
let bin =
|
||||
let of_octets o =
|
||||
match of_octets o with
|
||||
| Error e ->
|
||||
let e = Fmt.str "%a" Mirage_crypto_ec.pp_error e in
|
||||
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
|
||||
|
|
|
|||
10
src/util.ml
10
src/util.ml
|
|
@ -1,3 +1,5 @@
|
|||
exception Bin_error of string
|
||||
|
||||
(* TODO bin
|
||||
- no [Bin.of_string] ? *)
|
||||
let bin_of_string bin s =
|
||||
|
|
@ -52,7 +54,7 @@ module Bin_rsa = struct
|
|||
Bytes.unsafe_to_string b
|
||||
|
||||
let check = function
|
||||
| false -> Error "rsa of_octets error, invalid data"
|
||||
| false -> Error (`Msg "rsa of_octets error, invalid data")
|
||||
| true -> Ok ()
|
||||
|
||||
let z_array_of_octets ~nb s =
|
||||
|
|
@ -88,7 +90,7 @@ module Bin_rsa = struct
|
|||
let* arr = z_array_of_octets ~nb:2 s in
|
||||
match arr with
|
||||
| [| n; e |] ->
|
||||
let+ pub = Mirage_crypto_pk.Rsa.pub ~n ~e |> unwrap_err_msg in
|
||||
let+ pub = Mirage_crypto_pk.Rsa.pub ~n ~e in
|
||||
pub
|
||||
| _ -> assert false
|
||||
|
||||
|
|
@ -100,9 +102,7 @@ module Bin_rsa = struct
|
|||
let* arr = z_array_of_octets ~nb:8 s in
|
||||
match arr with
|
||||
| [| e; d; n; p; q; dp; dq; q' |] ->
|
||||
let+ priv =
|
||||
Mirage_crypto_pk.Rsa.priv ~e ~d ~n ~p ~q ~dp ~dq ~q' |> unwrap_err_msg
|
||||
in
|
||||
let+ priv = Mirage_crypto_pk.Rsa.priv ~e ~d ~n ~p ~q ~dp ~dq ~q' in
|
||||
priv
|
||||
| _ -> assert false
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue