Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/electionguard/chaum_pedersen.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,9 +389,10 @@ def make_disjunctive_chaum_pedersen(
:param plaintext: Zero or one
"""

assert (
0 <= plaintext <= 1
), "make_disjunctive_chaum_pedersen only supports plaintexts of 0 or 1"
if not (0 <= plaintext <= 1):
raise ValueError(
"make_disjunctive_chaum_pedersen only supports plaintexts of 0 or 1"
)
if plaintext == 0:
return make_disjunctive_chaum_pedersen_zero(message, r, k, q, seed)
return make_disjunctive_chaum_pedersen_one(message, r, k, q, seed)
Expand Down
3 changes: 2 additions & 1 deletion src/electionguard/elgamal.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,8 @@ def elgamal_add(*ciphertexts: ElGamalCiphertext) -> ElGamalCiphertext:
Homomorphically accumulates one or more ElGamal ciphertexts by pairwise multiplication. The exponents
of vote counters will add.
"""
assert len(ciphertexts) != 0, "Must have one or more ciphertexts for elgamal_add"
if len(ciphertexts) == 0:
raise ValueError("Must have one or more ciphertexts for elgamal_add")

result = ciphertexts[0]
for c in ciphertexts[1:]:
Expand Down
3 changes: 2 additions & 1 deletion src/electionguard/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ def mult_inv_p(e: ElementModPOrQorInt) -> ElementModP:
:param e: An element in [1, P).
"""
e = _get_mpz(e)
assert e != 0, "No multiplicative inverse for zero"
if e == 0:
raise ValueError("No multiplicative inverse for zero")
return ElementModP(powmod(e, -1, get_large_prime()))


Expand Down
3 changes: 2 additions & 1 deletion src/electionguard/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ def get_optional(optional: Optional[_T]) -> _T:
Raises an exception if it's actually `None`, otherwise
returns the internal type.
"""
assert optional is not None, "Unwrap called on None"
if optional is None:
raise ValueError("Unwrap called on None")
return optional


Expand Down
Loading