-
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.
Add return value to RunEncryptBallot.
Add sample script that uses it
- Loading branch information
1 parent
04562ad
commit a61aa37
Showing
7 changed files
with
186 additions
and
96 deletions.
There are no files selected for viewing
Binary file not shown.
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,39 @@ | ||
#!/bin/bash | ||
|
||
INPUT_DIR="src/test/data/working/public" | ||
PLAINTEXT_BALLOT="src/test/data/working/private/input_ballots/pballot-ballot11.json" | ||
OUTPUT_DIR="src/test/data/testOut/egkmixnet/RunEncryptBallot" | ||
|
||
|
||
if [ -z "${INPUT_DIR}" ]; then | ||
echo "No input directory provided." | ||
exit 1 | ||
fi | ||
|
||
if [ -z "${PLAINTEXT_BALLOT}" ]; then | ||
echo "No ballot filename provided." | ||
exit 1 | ||
fi | ||
|
||
if [ -z "${OUTPUT_DIR}" ]; then | ||
echo "No output directory provided." | ||
exit 1 | ||
fi | ||
|
||
mkdir -p ${OUTPUT_DIR} | ||
|
||
CLASSPATH="build/libs/egk-ec-mixnet-2.1-SNAPSHOT-uber.jar" | ||
|
||
echo " RunEncryptBallot for ${PLAINTEXT_BALLOT}" | ||
|
||
/usr/bin/java -classpath $CLASSPATH \ | ||
org.cryptobiotic.eg.cli.RunEncryptBallot \ | ||
--inputDir ${INPUT_DIR} \ | ||
--ballotFilepath ${PLAINTEXT_BALLOT} \ | ||
--outputDir ${OUTPUT_DIR} \ | ||
-device device42 \ | ||
--noDeviceNameInDir | ||
|
||
retval=$? | ||
|
||
echo " [DONE] RunEncryptBallot return value $retval" |
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
48 changes: 0 additions & 48 deletions
48
src/test/kotlin/org/cryptobiotic/mixnet/writer/BinaryBallotRoundtripTest.kt
This file was deleted.
Oops, something went wrong.
78 changes: 78 additions & 0 deletions
78
src/test/kotlin/org/cryptobiotic/mixnet/writer/ShuffledBallotRoundtripTest.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,78 @@ | ||
package org.cryptobiotic.mixnet.writer | ||
|
||
import com.github.michaelbull.result.Ok | ||
import com.github.michaelbull.result.unwrap | ||
import org.cryptobiotic.eg.core.* | ||
import org.cryptobiotic.eg.core.elGamalKeyPairFromRandom | ||
import org.cryptobiotic.eg.core.encrypt | ||
import org.cryptobiotic.eg.core.productionGroup | ||
import org.cryptobiotic.maths.* | ||
import org.cryptobiotic.util.Testing | ||
import org.junit.jupiter.api.Assertions.assertTrue | ||
import org.opentest4j.AssertionFailedError | ||
import java.io.FileNotFoundException | ||
import kotlin.random.Random | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
import kotlin.test.assertFailsWith | ||
|
||
class ShuffledBallotRoundtripTest { | ||
val group = productionGroup() | ||
|
||
@Test | ||
fun testBallotWriter() { | ||
val testOutDir = "${Testing.testOutMixnet}/BinaryBallotRoundtripTest" | ||
createDirectories(testOutDir) | ||
|
||
println("group ${group.constants.name} write binary to ${testOutDir}") | ||
testBallotWriter(group, 1, 1, testOutDir, false) | ||
testBallotWriter(group, 100,34, testOutDir, false) | ||
} | ||
|
||
@Test | ||
fun testBallotWriterJson() { | ||
val testOutDir = "${Testing.testOutMixnet}/JsonBallotRoundtripTest" | ||
createDirectories(testOutDir) | ||
println("group ${group.constants.name} write JSON to ${testOutDir}") | ||
testBallotWriter(group, 100,34, testOutDir, true) | ||
} | ||
|
||
fun testBallotWriter(group: GroupContext, nrows: Int, width: Int, testOutDir: String, isJson: Boolean) { | ||
val keypair = elGamalKeyPairFromRandom(group) | ||
val ballots: List<VectorCiphertext> = List(nrows) { | ||
val ciphertexts = List(width) { Random.nextInt(11).encrypt(keypair) } | ||
VectorCiphertext(group, ciphertexts) | ||
} | ||
|
||
writeShuffledBallotsToFile(isJson, testOutDir, ballots) | ||
val roundtripResult = readShuffledBallotsFromFile(group, testOutDir, width) | ||
assertTrue( roundtripResult is Ok) | ||
val readBallots = roundtripResult.unwrap() | ||
|
||
assertEquals(nrows, ballots.size) | ||
assertEquals(ballots.size, readBallots.size) | ||
assertEquals(ballots, readBallots) | ||
} | ||
|
||
@Test | ||
fun testBallotWriterFails() { | ||
val testOutDir = "${Testing.testOutMixnet}/bad" | ||
assertFailsWith<FileNotFoundException> { | ||
testBallotWriter(group, 100,34, testOutDir, true) | ||
} | ||
assertFailsWith<FileNotFoundException> { | ||
testBallotWriter(group, 100,34, testOutDir, false) | ||
} | ||
} | ||
|
||
@Test | ||
fun testBallotWriterFailsBinOverides() { | ||
val testOutDir = "${Testing.testOutMixnet}/testBallotWriterFailsBinOverides" | ||
createDirectories(testOutDir) | ||
testBallotWriter(group, 100,34, testOutDir, false) | ||
val ex = assertFailsWith<AssertionFailedError> { | ||
testBallotWriter(group, 100,34, testOutDir, true) | ||
} | ||
} | ||
|
||
} |