better fix

This commit is contained in:
swrup 2025-11-30 23:57:09 +01:00
parent 4c511efae9
commit 00a642658a
3 changed files with 33 additions and 11 deletions

View file

@ -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

View file

@ -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

View file

@ -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
@ -35,13 +37,14 @@ let () =
check_bad Timestamp.jsont {|{"t_s": "123456780"}|};
check_bad Timestamp.jsont {|{"t_s": "agagou"}|};
(* TODO use a valid rsa_pub value *)
(*
check DenominationKey.jsont
{|{"cipher": "RSA", "age_mask": 18, "rsa_pub": "agagouh"}|};
check DenominationKey.jsont
(* CS not implemented *)
check_bad DenominationKey.jsont
{|{"cipher": "CS", "age_mask": 18, "cs_pub": "ouhagag"}|};
*)
(* TODO test with a valid rsa_pub value *)
(* TODO handle "rsa pub_of_octets failure" correctly *)
(* check_bad DenominationKey.jsont
{|{"cipher": "RSA", "age_mask": 18, "rsa_pub": "agagouh"}|}; *)
()
let () =