This commit is contained in:
parent
4c511efae9
commit
747c1b4277
3 changed files with 27 additions and 6 deletions
23
src/api.ml
23
src/api.ml
|
|
@ -90,7 +90,26 @@ module RsaDenominationKey = struct
|
|||
|> Jsont.Object.finish
|
||||
end
|
||||
|
||||
(* Clause Schnorr cipher is not supported *)
|
||||
(* ! Clause Schnorr cipher is not supported *)
|
||||
module CSDenominationKey = struct
|
||||
type t = {
|
||||
age_mask: int;
|
||||
cs_pub: B32.t;
|
||||
}
|
||||
|
||||
(* TODO B32.jsont *)
|
||||
let b32_jsont = Jsont.of_of_string ~kind:"B32" B32.decode ~enc:B32.encode
|
||||
|
||||
let jsont =
|
||||
let make age_mask cs_pub = { age_mask; cs_pub } in
|
||||
let age_mask v = v.age_mask in
|
||||
let cs_pub v = v.cs_pub in
|
||||
Jsont.Object.map ~kind:"CSDenominationKey" make
|
||||
|> Jsont.Object.mem "age_mask" Jsont.int ~enc:age_mask
|
||||
|> Jsont.Object.mem "cs_pub" b32_jsont ~enc:cs_pub
|
||||
|> Jsont.Object.finish
|
||||
end
|
||||
|
||||
module DenominationKey = struct
|
||||
type t = Rsa of RsaDenominationKey.t
|
||||
(*| CS of CSDenominationKey.t*)
|
||||
|
|
@ -105,7 +124,7 @@ module DenominationKey = struct
|
|||
let jsont =
|
||||
let open Jsont.Object in
|
||||
let rsa = Case.map "RSA" RsaDenominationKey.jsont ~dec:of_rsa in
|
||||
let cs = Case.map "CS" RsaDenominationKey.jsont ~dec:of_cs in
|
||||
let cs = Case.map "CS" CSDenominationKey.jsont ~dec:of_cs in
|
||||
let enc_case = function Rsa v -> Case.value rsa v in
|
||||
let cases = Case.[ make rsa; make cs ] in
|
||||
map ~kind:"DenominationKey" Fun.id
|
||||
|
|
|
|||
|
|
@ -122,7 +122,7 @@ module DenominationKeyAnnouncementPS = struct
|
|||
let sign f r = f @@ Bin.to_string bin r
|
||||
let verify f s r = f s ~msg:(Bin.to_string bin r)
|
||||
|
||||
(* TODO use B32.jsont, for others types too *)
|
||||
(* TODO B32.jsont, for others types too *)
|
||||
let jsont = Jsont.string
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -15,11 +15,13 @@ let () =
|
|||
in
|
||||
()
|
||||
|
||||
let get_ok = function Error e -> failwith e | Ok v -> v
|
||||
|
||||
let () =
|
||||
let open Api in
|
||||
let check jsont s =
|
||||
let encode v = encode jsont v |> Result.get_ok in
|
||||
let decode v = decode jsont v |> Result.get_ok in
|
||||
let encode v = encode jsont v |> get_ok in
|
||||
let decode v = decode jsont v |> get_ok in
|
||||
let ts = decode s in
|
||||
let s' = encode ts in
|
||||
let ts' = decode s' in
|
||||
|
|
@ -39,9 +41,9 @@ let () =
|
|||
(*
|
||||
check DenominationKey.jsont
|
||||
{|{"cipher": "RSA", "age_mask": 18, "rsa_pub": "agagouh"}|};
|
||||
*)
|
||||
check DenominationKey.jsont
|
||||
{|{"cipher": "CS", "age_mask": 18, "cs_pub": "ouhagag"}|};
|
||||
*)
|
||||
()
|
||||
|
||||
let () =
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue