-
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 #319 from danwallach/baux0
Cast ballots, Baux0
- Loading branch information
Showing
221 changed files
with
65,578 additions
and
125,304 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
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
69 changes: 69 additions & 0 deletions
69
egklib/src/commonMain/kotlin/electionguard/encrypt/AddEncryptedBallot.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,69 @@ | ||
package electionguard.encrypt | ||
|
||
import electionguard.ballot.* | ||
import electionguard.core.ElGamalPublicKey | ||
import electionguard.core.GroupContext | ||
import electionguard.input.BallotInputValidation | ||
import electionguard.input.ManifestInputValidation | ||
import electionguard.publish.* | ||
import io.ktor.utils.io.core.Closeable | ||
import mu.KotlinLogging | ||
|
||
private val logger = KotlinLogging.logger("RunEncryptBallot") | ||
|
||
/** Encrypt a ballot and add to election record. Single threaded only. */ | ||
class AddEncryptedBallot( | ||
val group: GroupContext, | ||
val manifest: Manifest, | ||
val electionInit: ElectionInitialized, | ||
val outputDir: String, // write ballots here, must not have multiple writers to same directory | ||
val invalidDir: String, | ||
val isJson : Boolean, | ||
val chainCodes : Boolean, | ||
createNew : Boolean = false, | ||
): Closeable { | ||
|
||
val encryptor = Encryptor( | ||
group, | ||
manifest, | ||
ElGamalPublicKey(electionInit.jointPublicKey), | ||
electionInit.extendedBaseHash | ||
) | ||
val ballotValidator = BallotInputValidation(manifest) | ||
val publisher = makePublisher(outputDir, createNew, isJson) | ||
val sink: EncryptedBallotSinkIF = publisher.encryptedBallotSink() | ||
|
||
var codeBaux: ByteArray = ByteArray(0) | ||
|
||
init { | ||
val manifestValidator = ManifestInputValidation(manifest) | ||
val errors = manifestValidator.validate() | ||
if (errors.hasErrors()) { | ||
throw RuntimeException("ManifestInputValidation FAILED $errors") | ||
} | ||
} | ||
|
||
fun encryptAndAdd(ballot: PlaintextBallot, state : EncryptedBallot.BallotState): Boolean { | ||
val mess = ballotValidator.validate(ballot) | ||
if (mess.hasErrors()) { | ||
publisher.writePlaintextBallot(invalidDir, listOf(ballot)) // LOOK write just one ?? | ||
println(" wrote ${ballot.ballotId} invalid ballots to $invalidDir") | ||
return false | ||
} | ||
|
||
val ciphertextBallot = if (chainCodes) { | ||
encryptor.encrypt(ballot, null, null, codeBaux) | ||
} else { | ||
encryptor.encrypt(ballot, null) | ||
} | ||
|
||
codeBaux = ciphertextBallot.confirmationCode.bytes | ||
val eballot = ciphertextBallot.submit(state) | ||
sink.writeEncryptedBallot(eballot) // the sink must append | ||
return true | ||
} | ||
|
||
override fun close() { | ||
sink.close() | ||
} | ||
} |
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
Oops, something went wrong.