Skip to content

Commit 9e8f3b2

Browse files
Change string handling to use begin and end instead of front (#318)
* 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
1 parent 03986b7 commit 9e8f3b2

File tree

4 files changed

+5
-6
lines changed

4 files changed

+5
-6
lines changed

bindings/netstandard/ElectionGuard/ElectionGuard.Encryption.Tests/TestChaumPedersen.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ public class TestChaumPedersen
1010
[Test]
1111
public void Test_DisjunctiveChaumPedersen()
1212
{
13-
var nonce = Constants.ONE_MOD_Q;
13+
var nonce = new ElementModQ(Constants.ONE_MOD_Q.Data);
1414
var keyPair = ElGamalKeyPair.FromSecret(Constants.TWO_MOD_Q);
1515
const ulong vote = 0UL;
1616
var ciphertext = Elgamal.Encrypt(vote, nonce, keyPair.PublicKey);
1717

1818
var proof = new DisjunctiveChaumPedersenProof(
19-
ciphertext, nonce, keyPair.PublicKey, Constants.ONE_MOD_Q, vote);
19+
ciphertext, nonce, keyPair.PublicKey, new ElementModQ(Constants.ONE_MOD_Q.Data), vote);
2020

2121
Assert.That(proof.IsValid(ciphertext, keyPair.PublicKey, Constants.ONE_MOD_Q));
2222
}

bindings/netstandard/ElectionGuard/ElectionGuard.Encryption.Tests/TestElection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public void Test_Can_Create_Party()
2727
"2022-holidays",
2828
new InternationalizedText(new[] { candidateName }),
2929
"new-years-id",
30-
null,
30+
string.Empty,
3131
false);
3232

3333

src/electionguard/encrypt.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -510,8 +510,7 @@ namespace electionguard
510510
make_unique<Nonces>(*sharedNonce->clone(), "constant-extended-data");
511511
auto extendedDataNonce = noncesForExtendedData->get(0);
512512

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

516515
// Perform HashedElGamalCiphertext calculation
517516
unique_ptr<HashedElGamalCiphertext> hashedElGamal =

test/electionguard/test_encrypt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ TEST_CASE("Encrypt PlaintextBallot with EncryptionMediator against constructed "
141141
// Assert
142142
CHECK(ciphertext->isValidEncryption(*context->getManifestHash(), *keypair->getPublicKey(),
143143
*context->getCryptoExtendedBaseHash()) == true);
144+
CHECK(ciphertext->getContests().front().get().getHashedElGamalCiphertext().get() != nullptr);
144145
}
145146

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

492493
// Assert
493-
// TODO: compare other values
494494
CHECK(
495495
ciphertext->getContests().front().get().getSelections().front().get().getIsPlaceholder() ==
496496
false);

0 commit comments

Comments
 (0)