mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-12-23 02:31:56 +00:00
Refactor message signing and verifying logic
This commit is contained in:
parent
5770e29733
commit
7c13d31de0
@ -19,16 +19,20 @@ def message_checksum(message):
|
||||
|
||||
|
||||
def sign_message(key, message):
|
||||
signature = HMAC(key, message_bytes(message)).signature
|
||||
signature = message_signature(key, message)
|
||||
message['signature'] = b64encode(signature).decode()
|
||||
|
||||
|
||||
def message_signature(key, message):
|
||||
return HMAC(key, message_bytes(message)).signature
|
||||
|
||||
|
||||
def verify_message(key, message):
|
||||
message = deepcopy(message)
|
||||
try:
|
||||
signature_b64 = message.pop('signature')
|
||||
signature = b64decode(signature_b64)
|
||||
actual_signature = HMAC(key, message_bytes(message)).signature
|
||||
actual_signature = message_signature(key, message)
|
||||
return signature == actual_signature
|
||||
except KeyError:
|
||||
return False
|
||||
|
Loading…
Reference in New Issue
Block a user