add to_octets
This commit is contained in:
parent
78b08dcb4e
commit
812b81a966
3 changed files with 37 additions and 36 deletions
26
src/types.ml
26
src/types.ml
|
|
@ -82,6 +82,8 @@ module EddsaPublicKey = struct
|
|||
converted to Crockford Base32. *)
|
||||
type t = Mirage_crypto_ec.Ed25519.pub
|
||||
|
||||
let to_octets t = Mirage_crypto_ec.Ed25519.pub_to_octets t
|
||||
|
||||
let of_b32 s =
|
||||
let open Syntax in
|
||||
let open Mirage_crypto_ec in
|
||||
|
|
@ -90,13 +92,14 @@ module EddsaPublicKey = struct
|
|||
| Error e -> Fmt.error "%a" pp_error e
|
||||
| Ok pub -> Ok pub
|
||||
|
||||
let to_b32 pub = pub |> Mirage_crypto_ec.Ed25519.pub_to_octets |> B32.encode
|
||||
let to_b32 t = B32.encode (to_octets t)
|
||||
let jsont = Jsont.of_of_string ~kind:"EddsaPublicKey" of_b32 ~enc:to_b32
|
||||
end
|
||||
|
||||
module EddsaSignature : sig
|
||||
type t
|
||||
|
||||
val to_octets : t -> string
|
||||
val sign : key:Mirage_crypto_ec.Ed25519.priv -> string -> t
|
||||
val of_b32 : string -> (t, string) result
|
||||
val to_b32 : t -> string
|
||||
|
|
@ -108,6 +111,8 @@ end = struct
|
|||
They are signature over a c-struct like `TALER_xxxPS` + with a purpose *)
|
||||
type t = string
|
||||
|
||||
let to_octets t = t
|
||||
|
||||
(* TODO key format
|
||||
is it exactly like in GNU_CRYPTO?
|
||||
endianess issue? *)
|
||||
|
|
@ -128,6 +133,13 @@ end
|
|||
module RsaPublicKey = struct
|
||||
type t = Mirage_crypto_pk.Rsa.pub
|
||||
|
||||
let to_octets ({ n; e } : Mirage_crypto_pk.Rsa.pub) =
|
||||
let open Binary_formats.RsaPublicKey in
|
||||
let header = { n_len= Z.size n; e_len= Z.size e } in
|
||||
let v = { header; n; e } in
|
||||
let s = Bin.to_string bin v in
|
||||
s
|
||||
|
||||
let of_b32 s =
|
||||
let open Syntax in
|
||||
let* s = B32.decode s in
|
||||
|
|
@ -135,20 +147,14 @@ module RsaPublicKey = struct
|
|||
let+ v = Mirage_crypto_pk.Rsa.pub ~n:v.n ~e:v.e |> unwrap_err_msg in
|
||||
v
|
||||
|
||||
let to_b32 ({ n; e } : Mirage_crypto_pk.Rsa.pub) =
|
||||
let open Binary_formats.RsaPublicKey in
|
||||
let header = { n_len= Z.size n; e_len= Z.size e } in
|
||||
let v = { header; n; e } in
|
||||
let s = Bin.to_string bin v in
|
||||
let s = B32.encode s in
|
||||
s
|
||||
|
||||
let to_b32 t = B32.encode (to_octets t)
|
||||
let jsont = Jsont.of_of_string ~kind:"RsaPublicKey" of_b32 ~enc:to_b32
|
||||
end
|
||||
|
||||
module RsaSignature : sig
|
||||
type t
|
||||
|
||||
val to_octets : t -> string
|
||||
val sign : key:Mirage_crypto_pk.Rsa.priv -> string -> t
|
||||
val of_b32 : string -> (t, string) result
|
||||
val to_b32 : t -> string
|
||||
|
|
@ -156,6 +162,8 @@ module RsaSignature : sig
|
|||
end = struct
|
||||
type t = string
|
||||
|
||||
let to_octets t = t
|
||||
|
||||
(* no Rsa.sign(?):
|
||||
decrypt is equivalent to sign *)
|
||||
let sign ~key s =
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue