Skip to content

Commit

Permalink
Change string handling to use begin and end instead of front (#318)
Browse files Browse the repository at this point in the history
* Change string handling to use begin and end instead of front
Added unit test to make sure the extended data is not null

* Fix multiple .net tests that had intermittent failures because of how c++ was handling data
  • Loading branch information
SteveMaier-IRT authored Jun 30, 2022
1 parent 03986b7 commit 9e8f3b2
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ public class TestChaumPedersen
[Test]
public void Test_DisjunctiveChaumPedersen()
{
var nonce = Constants.ONE_MOD_Q;
var nonce = new ElementModQ(Constants.ONE_MOD_Q.Data);
var keyPair = ElGamalKeyPair.FromSecret(Constants.TWO_MOD_Q);
const ulong vote = 0UL;
var ciphertext = Elgamal.Encrypt(vote, nonce, keyPair.PublicKey);

var proof = new DisjunctiveChaumPedersenProof(
ciphertext, nonce, keyPair.PublicKey, Constants.ONE_MOD_Q, vote);
ciphertext, nonce, keyPair.PublicKey, new ElementModQ(Constants.ONE_MOD_Q.Data), vote);

Assert.That(proof.IsValid(ciphertext, keyPair.PublicKey, Constants.ONE_MOD_Q));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void Test_Can_Create_Party()
"2022-holidays",
new InternationalizedText(new[] { candidateName }),
"new-years-id",
null,
string.Empty,
false);


Expand Down
3 changes: 1 addition & 2 deletions src/electionguard/encrypt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -510,8 +510,7 @@ namespace electionguard
make_unique<Nonces>(*sharedNonce->clone(), "constant-extended-data");
auto extendedDataNonce = noncesForExtendedData->get(0);

vector<uint8_t> extendedData_plaintext(
(uint8_t *)&extendedData.front(), (uint8_t *)&extendedData.front() + extendedData.size());
vector<uint8_t> extendedData_plaintext(extendedData.begin(), extendedData.end());

// Perform HashedElGamalCiphertext calculation
unique_ptr<HashedElGamalCiphertext> hashedElGamal =
Expand Down
2 changes: 1 addition & 1 deletion test/electionguard/test_encrypt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ TEST_CASE("Encrypt PlaintextBallot with EncryptionMediator against constructed "
// Assert
CHECK(ciphertext->isValidEncryption(*context->getManifestHash(), *keypair->getPublicKey(),
*context->getCryptoExtendedBaseHash()) == true);
CHECK(ciphertext->getContests().front().get().getHashedElGamalCiphertext().get() != nullptr);
}

TEST_CASE("Encrypt PlaintextBallot undervote succeeds")
Expand Down Expand Up @@ -490,7 +491,6 @@ TEST_CASE("Verify placeholder flag")
auto ciphertext = encryptBallot(*ballot, *internal, *context, *device->getHash());

// Assert
// TODO: compare other values
CHECK(
ciphertext->getContests().front().get().getSelections().front().get().getIsPlaceholder() ==
false);
Expand Down

0 comments on commit 9e8f3b2

Please sign in to comment.