forked from votingworks/electionguard-kotlin-multiplatform
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed jvm compilation in egklib and egk-cli
- Loading branch information
Showing
22 changed files
with
516 additions
and
359 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
81 changes: 81 additions & 0 deletions
81
egk-cli/src/commonTest/kotlin/electionguard/workflow/BallotInputBuilder.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,81 @@ | ||
package electionguard.workflow | ||
|
||
import electionguard.demonstrate.ManifestBuilder | ||
import electionguard.model.Manifest | ||
import electionguard.model.PlaintextBallot | ||
|
||
class BallotInputBuilder internal constructor(val manifest: Manifest, val id: String) { | ||
private val contests = ArrayList<ContestBuilder>() | ||
private var style = ManifestBuilder.styleDefault | ||
|
||
fun setStyle(style: String): BallotInputBuilder { | ||
this.style = style | ||
return this | ||
} | ||
|
||
fun addContest(contest_id: String, seqOrder : Int? = null): ContestBuilder { | ||
val c = ContestBuilder(contest_id, seqOrder) | ||
contests.add(c) | ||
return c | ||
} | ||
|
||
fun addContest(idx : Int): ContestBuilder { | ||
val contest = manifest.contests[idx] | ||
val c = ContestBuilder(contest.contestId, contest.sequenceOrder) | ||
contests.add(c) | ||
return c | ||
} | ||
|
||
fun build(): PlaintextBallot { | ||
return PlaintextBallot( | ||
id, | ||
style, | ||
contests.map {it.build() } | ||
) | ||
} | ||
|
||
inner class ContestBuilder internal constructor(val contestId: String, seqOrder : Int? = null) { | ||
private var seq = seqOrder?: 1 | ||
private val selections = ArrayList<SelectionBuilder>() | ||
private val writeIns = ArrayList<String>() | ||
|
||
fun addSelection(id: String, vote: Int, seqOrder : Int? = null): ContestBuilder { | ||
val s = SelectionBuilder(id, vote, seqOrder) | ||
selections.add(s) | ||
return this | ||
} | ||
|
||
fun addSelection(idx : Int, vote: Int): ContestBuilder { | ||
val contest = manifest.contests.find { it.contestId == contestId } | ||
?: throw IllegalArgumentException("Cant find contestId = $contestId") | ||
val selection = contest.selections[idx] | ||
val s = SelectionBuilder(selection.selectionId, vote, selection.sequenceOrder) | ||
selections.add(s) | ||
return this | ||
} | ||
|
||
fun addWriteIn(writeIn: String): ContestBuilder { | ||
writeIns.add(writeIn) | ||
return this | ||
} | ||
|
||
fun done(): BallotInputBuilder { | ||
return this@BallotInputBuilder | ||
} | ||
|
||
fun build(): PlaintextBallot.Contest { | ||
return PlaintextBallot.Contest( | ||
contestId, | ||
seq++, | ||
selections.map { it.build() }, | ||
writeIns | ||
) | ||
} | ||
|
||
inner class SelectionBuilder internal constructor(private val selectionId: String, private val vote: Int, private val seqOrder : Int? = null) { | ||
fun build(): PlaintextBallot.Selection { | ||
return PlaintextBallot.Selection(selectionId, seqOrder?: seq++, vote) | ||
} | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
egk-cli/src/commonTest/kotlin/electionguard/workflow/BallotTestUtils.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,34 @@ | ||
package electionguard.workflow | ||
|
||
import com.github.michaelbull.result.unwrap | ||
import electionguard.core.UInt256 | ||
import electionguard.decrypt.DecryptingTrusteeDoerre | ||
import electionguard.keyceremony.KeyCeremonyTrustee | ||
import electionguard.model.Guardian | ||
import electionguard.model.PublicKeys | ||
|
||
fun makeDoerreTrustee(ktrustee: KeyCeremonyTrustee, electionId : UInt256): DecryptingTrusteeDoerre { | ||
return DecryptingTrusteeDoerre( | ||
ktrustee.id(), | ||
ktrustee.xCoordinate(), | ||
ktrustee.guardianPublicKey(), | ||
ktrustee.computeSecretKeyShare(), | ||
) | ||
} | ||
|
||
fun makeGuardian(trustee: KeyCeremonyTrustee): Guardian { | ||
val publicKeys = trustee.publicKeys().unwrap() | ||
return Guardian( | ||
trustee.id(), | ||
trustee.xCoordinate(), | ||
publicKeys.coefficientProofs, | ||
) | ||
} | ||
|
||
fun makeGuardian(publicKeys: PublicKeys): Guardian { | ||
return Guardian( | ||
publicKeys.guardianId, | ||
publicKeys.guardianXCoordinate, | ||
publicKeys.coefficientProofs, | ||
) | ||
} |
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
1 change: 0 additions & 1 deletion
1
egk-cli/src/commonTest/kotlin/electionguard/workflow/FakeKeyCeremonyTest.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
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
Oops, something went wrong.