Skip to content

Commit 03986b7

Browse files
When creating placeholders set the IsPlaceholder to true. (#317)
Unit test added to make sure the value is read properly.
1 parent f3046c3 commit 03986b7

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/electionguard/encrypt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ namespace electionguard
502502
auto placeholderSelection = selectionFrom(placeholder, true, selectPlaceholder);
503503
encryptedSelections.push_back(encryptSelection(
504504
*placeholderSelection, placeholder, *elgamalPublicKey_ptr,
505-
*cryptoExtendedBaseHash_ptr, *sharedNonce.get(), false, shouldVerifyProofs));
505+
*cryptoExtendedBaseHash_ptr, *sharedNonce.get(), true, shouldVerifyProofs));
506506
}
507507

508508
// Derive the extendedDataNonce from the selection nonce and a constant

test/electionguard/test_encrypt.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,3 +473,27 @@ TEST_CASE("Create EncryptionMediator with different manifest hash")
473473
CHECK(internal->getManifestHash()->toHex() != context->getManifestHash()->toHex());
474474
}
475475
}
476+
477+
TEST_CASE("Verify placeholder flag")
478+
{
479+
// Arrange
480+
auto secret = ElementModQ::fromHex(a_fixed_secret);
481+
auto keypair = ElGamalKeyPair::fromSecret(*secret);
482+
auto manifest = ManifestGenerator::getManifestFromFile(TEST_SPEC_VERSION, TEST_USE_SAMPLE);
483+
auto internal = make_unique<InternalManifest>(*manifest);
484+
auto context = ElectionGenerator::getFakeContext(*internal, *keypair->getPublicKey());
485+
auto device = make_unique<EncryptionDevice>(12345UL, 23456UL, 34567UL, "Location");
486+
487+
auto ballot = BallotGenerator::getFakeBallot(*internal);
488+
489+
// Act
490+
auto ciphertext = encryptBallot(*ballot, *internal, *context, *device->getHash());
491+
492+
// Assert
493+
// TODO: compare other values
494+
CHECK(
495+
ciphertext->getContests().front().get().getSelections().front().get().getIsPlaceholder() ==
496+
false);
497+
CHECK(ciphertext->getContests().front().get().getSelections().back().get().getIsPlaceholder() ==
498+
true);
499+
}

0 commit comments

Comments
 (0)