-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #398 from JohnLCaron/jsonR
First pass reading json output from eg-rust.
- Loading branch information
Showing
47 changed files
with
1,403 additions
and
14,679 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
egklib/src/commonMain/kotlin/electionguard/json/ElectionHashes.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package electionguard.json | ||
|
||
import electionguard.core.UInt256 | ||
import kotlinx.serialization.Serializable | ||
|
||
/* hashes.json | ||
{ | ||
"h_p": "H(BAD5EEBFE2C98C9031BA8C36E7E4FB76DAC20665FD3621DF33F3F666BEC9AC0D)", | ||
"h_m": "H(2FE7EA3C2E3C42F88647B4727254F960F1BB7B0D00A6A60C21D2F8984F5090B7)", | ||
"h_b": "H(3800F226CB90A422D293BDC0F35D3C6767C2945D8C957F29CD0EAC2EAC6394B1)" | ||
} | ||
*/ | ||
|
||
@Serializable | ||
data class ElectionHashesJsonR( | ||
val h_p : UInt256JsonR, | ||
val h_m : UInt256JsonR, | ||
val h_b : UInt256JsonR, | ||
) | ||
|
||
data class ElectionHashes( | ||
val Hp : UInt256, | ||
val Hm : UInt256, | ||
val Hb : UInt256, | ||
) | ||
|
||
fun ElectionHashesJsonR.import() = ElectionHashes( | ||
this.h_p.import(), | ||
this.h_m.import(), | ||
this.h_b.import(), | ||
) | ||
|
||
/* hashes_ext.json | ||
{ | ||
"h_e": "H(B1321998DB34667B3BD17021665D38274510BE53975496DA2EF3CBB38E799869)" | ||
} | ||
*/ | ||
|
||
@Serializable | ||
data class ElectionHashesExtJsonR( | ||
val h_e : UInt256JsonR, | ||
) | ||
|
||
fun ElectionHashesExtJsonR.import() = this.h_e.import() |
114 changes: 114 additions & 0 deletions
114
egklib/src/commonMain/kotlin/electionguard/json/ElectionManifest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
package electionguard.json | ||
|
||
import kotlinx.serialization.Serializable | ||
|
||
/* election_manifest.jcon | ||
{ | ||
"label": "General Election - The United Realms of Imaginaria", | ||
"contests": [ | ||
{ | ||
"label": "For President and Vice President of The United Realms of Imaginaria", | ||
"selection_limit": 1, | ||
"options": [ | ||
{ | ||
"label": "Thündéroak, Vâlêriana D.\nËverbright, Ålistair R. Jr.\n(Ætherwïng)" | ||
}, | ||
{ | ||
"label": "Stârførge, Cássánder A.\nMøonfire, Célestïa L.\n(Crystâlheärt)" | ||
} | ||
] | ||
}, | ||
{ | ||
"label": "Minister of Arcane Sciences", | ||
"selection_limit": 1, | ||
"options": [ | ||
{ | ||
"label": "Élyria Moonshadow\n(Crystâlheärt)" | ||
}, | ||
{ | ||
"label": "Archímedes Darkstone\n(Ætherwïng)" | ||
}, | ||
{ | ||
"label": "Seraphína Stormbinder\n(Independent)" | ||
}, | ||
{ | ||
"label": "Gávrïel Runëbørne\n(Stärsky)" | ||
} | ||
] | ||
}, | ||
], | ||
"ballot_styles": [ | ||
{ | ||
"label": "Smoothstone County Ballot", | ||
"contests": [ | ||
1, | ||
2, | ||
3, | ||
4, | ||
5, | ||
6, | ||
7, | ||
8, | ||
9, | ||
10 | ||
] | ||
}, | ||
{ | ||
"label": "Silvërspîre County Ballot", | ||
"contests": [ | ||
1, | ||
2, | ||
3, | ||
4, | ||
5, | ||
6, | ||
7, | ||
8, | ||
9, | ||
11 | ||
] | ||
} | ||
] | ||
} | ||
*/ | ||
|
||
@Serializable | ||
data class ElectionManifestJsonR( | ||
val label : String, | ||
val contests : List<ManifestContestJsonR>, | ||
val ballot_styles : List<BallotStyleJsonR>, | ||
) { | ||
override fun toString(): String { | ||
return "ElectionManifestJsonR(label='$label'\n contests=$contests\n ballot_styles=$ballot_styles)" | ||
} | ||
} | ||
|
||
@Serializable | ||
data class ManifestContestJsonR( | ||
val label : String, | ||
val selection_limit: Int, | ||
val options : List<ManifestOptionJsonR>, | ||
) { | ||
override fun toString(): String { | ||
return "\n ManifestContestJsonR(label='$label', selection_limit=$selection_limit, options=$options)\n" | ||
} | ||
} | ||
|
||
@Serializable | ||
data class ManifestOptionJsonR( | ||
val label : String, | ||
) { | ||
override fun toString(): String { | ||
return "\n ManifestOptionJsonR(label='$label')" | ||
} | ||
} | ||
|
||
@Serializable | ||
data class BallotStyleJsonR( | ||
val label : String, | ||
val contests : List<Int>, | ||
) { | ||
override fun toString(): String { | ||
return "\n BallotStyleJsonR(label='$label', contests=$contests)\n" | ||
} | ||
} |
82 changes: 82 additions & 0 deletions
82
egklib/src/commonMain/kotlin/electionguard/json/ElectionParameters.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package electionguard.json | ||
|
||
import electionguard.ballot.ElectionConstants | ||
import electionguard.core.Base64.fromBase64 | ||
import kotlinx.serialization.Serializable | ||
|
||
/* election_parameters.jcon | ||
{ | ||
"fixed_parameters": { | ||
"ElectionGuard_Design_Specification": { | ||
"Official": { | ||
"version": [ | ||
2, | ||
0 | ||
], | ||
"release": "Release" | ||
} | ||
}, | ||
"generation_parameters": { | ||
"q_bits_total": 256, | ||
"p_bits_total": 4096, | ||
"p_bits_msb_fixed_1": 256, | ||
"p_middle_bits_source": "ln_2", | ||
"p_bits_lsb_fixed_1": 256 | ||
}, | ||
"p": "base64://////////////////////////////////////////+xchf30c95q8njs5gD8vavQPNDJnKYti2KDRdbi6r6K+e4diBt66yYVZVS+0r6GxDtLq41wTghRCdXOykRabglPpbKFiJK6MUay9oRMXw4frnqm8OxNmA7JW+g7HZX90tyzoexnWVIyvXfpr04MDJIZV+hhy8g46LaLZfFDz/Vxgf0yhH7W/uQYQ0w+I/lUaLuVp1t/B76FX0uI94UALOWF0YHdduJkOXJQ+cytHnNM8zMTmWTk1FMTBoeC9HWCV0lZpszNWSjN2qcf4peFI6CB022AVz+eqMMSApUFzUNLJVdUXmx4XudrjE822xgbLEHj3NdGy2zG19QtRhQZMGLTRYts7NlhT11mKGVGuJz7lVwtsaPlpg0ltTm0zCviJtEoCVUcxzcjqFyk9Eiik75jW9Rd/vPB1UmilwflTi5gmGv/URrHKPPXpIiuIxm08VCIYPtyZQhCQu7Fvrz2UnyNuArIM7ohrkFwSjVPQvS+WITYxlq9QMCAGDkmQg5GgxXM5uivrp9BSrFthzE6SB87y8M4tc3OVjXYiZYkERXRPtfLaS3UQBYktNWiQ3v6crZudS3E+BhYqLY/dDfL9YI//////////////////////////////////////////8=", | ||
"q": "base64://///////////////////////////////////////0M=", | ||
"r": "base64:AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAC8sXIX99HPeavJ47OYA/L2r0DzQyZymLYtig0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J92rRrNmX66E2V1QeeexXQ35QTtqd0BEGFRbGQ/sw1tWK/M0otz/top7BKwGl64Y5mlk6nV9FDeOcuSlixexpJTSNtU0Sj9mcFLRX+IPsIBEqdaagWB09gKO07wnshvlVL/2hZT8TOqJTSYOm8xsO5Gl5Naax6i91uF5+uhUbpIYJTWhyKwVGM/7FHKPymzHnfjF7F4trnYrg8=" | ||
}, | ||
"varying_parameters": { | ||
"n": 5, | ||
"k": 3, | ||
"date": "11/29/2023", | ||
"info": "info", | ||
"ballot_chaining": "Prohibited" | ||
} | ||
} | ||
*/ | ||
|
||
@Serializable | ||
data class ElectionParametersJsonR( | ||
val fixed_parameters : FixedParametersJsonR, | ||
val varying_parameters : VaryingParameters, | ||
) | ||
|
||
fun ElectionParametersJsonR.import() = ElectionParameters( | ||
this.fixed_parameters.import(), | ||
this.varying_parameters, | ||
) | ||
|
||
@Serializable | ||
data class FixedParametersJsonR( | ||
val p: String, | ||
val q: String, | ||
val r: String, | ||
val g: String, | ||
) | ||
|
||
fun FixedParametersJsonR.import() : ElectionConstants { | ||
return ElectionConstants( "FixedParametersJsonR", | ||
this.p.substring(7).fromBase64()!!, // strip off "base64:" | ||
this.q.substring(7).fromBase64()!!, | ||
this.r.substring(7).fromBase64()!!, | ||
this.g.substring(7).fromBase64()!!, | ||
) | ||
} | ||
|
||
@Serializable | ||
data class VaryingParameters( | ||
val n: Int, | ||
val k: Int, | ||
val date: String, | ||
val info: String, | ||
val ballot_chaining: String, | ||
) | ||
|
||
data class ElectionParameters( | ||
val electionConstants : ElectionConstants, | ||
val varyingParameters : VaryingParameters, | ||
) |
Oops, something went wrong.