This is an automated email from the ASF dual-hosted git repository.

gstein pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/steve.git

commit 347a08bd0f70dff35217356f25f5a3d8d51222e4
Author: Greg Stein <[email protected]>
AuthorDate: Sun May 29 17:30:51 2022 -0500

    Slight tweaks to the crypo functions.
    
    * return salt, then the value it was used for
    * gen_token() is usually used to recreate a token, so it needs the
      salt that was originally used -- meaning it comes from the app
    * clarify a few todo comments
---
 v3/steve/crypto.py | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/v3/steve/crypto.py b/v3/steve/crypto.py
index fb1271f..be7d560 100644
--- a/v3/steve/crypto.py
+++ b/v3/steve/crypto.py
@@ -36,23 +36,21 @@ def gen_salt() -> bytes:
 
 
 ### fix the types of the election metadata and issue data
-### fix return type
+### fix return type, to be a tuple
 def gen_opened_key(election: bytes, issues: bytes) -> bytes:
     "Generate the OpenedKey for this election."
     salt = gen_salt()
     ### TBD: map ELECTION and ISSUES parameters to bytes
     opened_key = _hash(election + issues, salt)
-    return opened_key, salt
+    return salt, opened_key
 
 
-### fix return type
-def gen_token(opened_key: bytes, value: bytes) -> bytes:
+def gen_token(opened_key: bytes, value: bytes, salt: bytes) -> bytes:
     "Generate a voter or issue token."
-    salt = gen_salt()
-    return _hash(opened_key + value, salt), salt
+    return _hash(opened_key + value, salt)
 
 
-### fix return type
+### fix return type, to be a tuple
 def create_vote(voter_token: bytes,
                 issue_token: bytes,
                 votestring: bytes) -> bytes:
@@ -61,7 +59,7 @@ def create_vote(voter_token: bytes,
     key = _hash(voter_token + issue_token, salt)
     b64key = base64.urlsafe_b64encode(key)
     f = cryptography.fernet.Fernet(b64key)
-    return voter_token, issue_token, salt, f.encrypt(votestring)
+    return salt, f.encrypt(votestring)
 
 
 def decrypt_votestring(voter_token: bytes,

Reply via email to