File tree Expand file tree Collapse file tree 2 files changed +22
-8
lines changed
Expand file tree Collapse file tree 2 files changed +22
-8
lines changed Original file line number Diff line number Diff line change 44from electionguard .ballot import (
55 CiphertextBallot ,
66)
7+ from electionguard .election import CiphertextElectionContext
8+ from electionguard .manifest import (
9+ Manifest ,
10+ )
711
812
913@dataclass
@@ -17,13 +21,23 @@ class Verification:
1721 message : Optional [str ]
1822
1923
20- def verify_ballot (ballot : CiphertextBallot ) -> Verification :
24+ def verify_ballot (
25+ ballot : CiphertextBallot ,
26+ manifest : Manifest ,
27+ context : CiphertextElectionContext ,
28+ ) -> Verification :
2129 """
2230 Method to verify the validity of a ballot
23-
24- TEMPORARY method that always returns True!!!
2531 """
2632
27- print (f"Verifying ballot { ballot .object_id } " )
33+ if not ballot .is_valid_encryption (
34+ manifest .crypto_hash (),
35+ context .elgamal_public_key ,
36+ context .crypto_extended_base_hash ,
37+ ):
38+ return Verification (
39+ False ,
40+ message = f"verify_ballot: mismatching ballot encryption { ballot .object_id } " ,
41+ )
2842
2943 return Verification (True , message = None )
Original file line number Diff line number Diff line change @@ -30,9 +30,9 @@ class TestVerify(BaseTestCase):
3030 @given (elgamal_keypairs ())
3131 def test_verify_ballot (self , keypair : ElGamalKeyPair ):
3232 # Arrange
33- election = election_factory .get_simple_manifest_from_file ()
33+ manifest = election_factory .get_simple_manifest_from_file ()
3434 internal_manifest , context = election_factory .get_fake_ciphertext_election (
35- election , keypair .public_key
35+ manifest , keypair .public_key
3636 )
3737
3838 data = ballot_factory .get_simple_ballot_from_file ()
@@ -43,8 +43,8 @@ def test_verify_ballot(self, keypair: ElGamalKeyPair):
4343 self .assertIsNotNone (encrypted_ballot )
4444
4545 # Act
46- verification = verify_ballot (encrypted_ballot )
46+ verification = verify_ballot (encrypted_ballot , manifest , context )
4747
4848 # Assert
4949 self .assertIsNotNone (verification )
50- self .assertTrue (verification )
50+ self .assertTrue (verification . verified )
You can’t perform that action at this time.
0 commit comments