Commit c22e9546 authored by Stephane Glondu's avatar Stephane Glondu

Add a generic wrapped_pubkey type

parent 3de3ab79
{"description":"This is a test election.","name":"Test election","public_key":{"g":"14887492224963187634282421537186040801304008017743492304481737382571933937568724473847106029915040150784031882206090286938661464458896494215273989547889201144857352611058572236578734319505128042602372864570426550855201448111746579871811249114781674309062693442442368697449970648232621880001709535143047913661432883287150003429802392229361583608686643243349727791976247247948618930423866180410558458272606627111270040091203073580238905303994472202930783207472394578498507764703191288249547659899997131166130259700604433891232298182348403175947450284433411265966789131024573629546048637848902243503970966798589660808533","p":"16328632084933010002384055033805457329601614771185955389739167309086214800406465799038583634953752941675645562182498120750264980492381375579367675648771293800310370964745767014243638518442553823973482995267304044326777047662957480269391322789378384619428596446446984694306187644767462460965622580087564339212631775817895958409016676398975671266179637898557687317076177218843233150695157881061257053019133078545928983562221396313169622475509818442661047018436264806901023966236718367204710755935899013750306107738002364137917426595737403871114187750804346564731250609196846638183903982387884578266136503697493474682071","q":"61329566248342901292543872769978950870633559608669337131139375508370458778917","y":"14635082878118572654479921080249944001812293038810422159343238089595479240882299219246906288014009621479772514986719666120580071805977517512709536449580704387040200602501172760388225540685840285411774228955056554894778199335402959258815158862988075365242410449387167116346296481514414882426546780519521778091037414413395238663990507052035474205192620851516755387953867800973935897054822286902740224243498380336367014173394548123266419420289185997583417780349142205089750866593480737143971921887353321220824821931497851896766898090557192411266787781010869883177247094501345068629045693383217704047201748215908551010065"},"questions":[{"answers":["a","b","c","d","e"],"min":0,"max":1,"question":"Question 1?"},{"answers":["a","b","c","d","e","f"],"min":2,"max":3,"question":"Question 2?"},{"answers":["a","b","c"],"min":1,"max":1,"question":"Question 3?"}],"uuid":"6d122f00-2650-4de8-87de-30037a21f943","short_name":"test"}
{"description":"This is a test election.","name":"Test election","public_key":{"group":{"g":"14887492224963187634282421537186040801304008017743492304481737382571933937568724473847106029915040150784031882206090286938661464458896494215273989547889201144857352611058572236578734319505128042602372864570426550855201448111746579871811249114781674309062693442442368697449970648232621880001709535143047913661432883287150003429802392229361583608686643243349727791976247247948618930423866180410558458272606627111270040091203073580238905303994472202930783207472394578498507764703191288249547659899997131166130259700604433891232298182348403175947450284433411265966789131024573629546048637848902243503970966798589660808533","p":"16328632084933010002384055033805457329601614771185955389739167309086214800406465799038583634953752941675645562182498120750264980492381375579367675648771293800310370964745767014243638518442553823973482995267304044326777047662957480269391322789378384619428596446446984694306187644767462460965622580087564339212631775817895958409016676398975671266179637898557687317076177218843233150695157881061257053019133078545928983562221396313169622475509818442661047018436264806901023966236718367204710755935899013750306107738002364137917426595737403871114187750804346564731250609196846638183903982387884578266136503697493474682071","q":"61329566248342901292543872769978950870633559608669337131139375508370458778917"},"y":"14635082878118572654479921080249944001812293038810422159343238089595479240882299219246906288014009621479772514986719666120580071805977517512709536449580704387040200602501172760388225540685840285411774228955056554894778199335402959258815158862988075365242410449387167116346296481514414882426546780519521778091037414413395238663990507052035474205192620851516755387953867800973935897054822286902740224243498380336367014173394548123266419420289185997583417780349142205089750866593480737143971921887353321220824821931497851896766898090557192411266787781010869883177247094501345068629045693383217704047201748215908551010065"},"questions":[{"answers":["a","b","c","d","e"],"min":0,"max":1,"question":"Question 1?"},{"answers":["a","b","c","d","e","f"],"min":2,"max":3,"question":"Question 2?"},{"answers":["a","b","c"],"min":1,"max":1,"question":"Question 3?"}],"uuid":"6d122f00-2650-4de8-87de-30037a21f943","short_name":"test"}
......@@ -39,9 +39,8 @@ let read state buf =
(module G : GROUP)
let election_params_of_string x =
let params = params_of_string read_ff_pubkey x in
let {ffpk_g=g; ffpk_p=p; ffpk_q=q; ffpk_y=y} = params.e_public_key in
let group = {g; p; q} in
let params = params_of_string (read_wrapped_pubkey read_ff_params read_number) x in
let {wpk_group=group; wpk_y=y} = params.e_public_key in
let module X = struct
module G = (val Group_field.make group : Group_field.GROUP)
let params = {params with e_public_key = y}
......
......@@ -84,13 +84,7 @@ let unsafe_make group =
let compare = Z.compare
type group = ff_params
let group = group
type wrapped_pubkey = Serializable_t.ff_pubkey
let wrap_pubkey y =
Serializable_t.({ffpk_g=g; ffpk_p=p; ffpk_q=q; ffpk_y=y})
let write_wrapped_pubkey = write_ff_pubkey
let write_group = write_ff_params
end in (module G : GROUP)
......
......@@ -60,14 +60,11 @@ type ff_params = {
}
<doc text="Parameters for a multiplicative subgroup of a finite field.">
(* FIXME: use a "group" field of type 'a *)
type ff_pubkey = {
g : number;
p : number;
q : number;
y : number;
} <ocaml field_prefix="ffpk_">
<doc text="A finite field public key wrapped with its group parameters.">
type ('a, 'b) wrapped_pubkey = {
group : 'a;
y : 'b;
} <ocaml field_prefix="wpk_">
<doc text="A public key wrapped with its group parameters.">
type question = {
answers : string list <ocaml repr="array">;
......
......@@ -88,12 +88,7 @@ module type GROUP = sig
(** Serializable description of the group. *)
val group : group
type wrapped_pubkey
(** The type of a pubkey wrapped with group parameters. *)
val wrap_pubkey : t -> wrapped_pubkey
val write_wrapped_pubkey : wrapped_pubkey writer
val write_group : group writer
end
......
......@@ -81,7 +81,7 @@ module Make (P : PARSED_PARAMS) : S = struct
let params = {
e_description = template.t_description;
e_name = template.t_name;
e_public_key = G.wrap_pubkey y;
e_public_key = {wpk_group = G.group; wpk_y = y};
e_questions = template.t_questions;
e_uuid = uuid;
e_short_name = template.t_short_name;
......@@ -90,7 +90,7 @@ module Make (P : PARSED_PARAMS) : S = struct
(* Generate and serialize election.json *)
let mkelection () =
string_of_params G.write_wrapped_pubkey params
string_of_params (write_wrapped_pubkey G.write_group G.write) params
end
......
......@@ -789,7 +789,7 @@ let () =
let params = {
e_description = template.t_description;
e_name = template.t_name;
e_public_key = G.wrap_pubkey y;
e_public_key = {wpk_group = G.group; wpk_y = y};
e_questions = template.t_questions;
e_uuid = uuid;
e_short_name = template.t_short_name;
......@@ -812,7 +812,7 @@ let () =
~perm:0o600 ~mode:Lwt_io.Output fname
(fun oc -> Lwt_io.write oc what >> Lwt_io.write oc "\n")
in
create_file files.f_election (string_of_params G.write_wrapped_pubkey params) >>
create_file files.f_election (string_of_params (write_wrapped_pubkey G.write_group G.write) params) >>
create_file files.f_metadata (string_of_metadata se.se_metadata) >>
create_file files.f_voters (PString.concat "\n" se.se_voters) >>
Lwt_io.with_file
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment