Separated signing logic of the Watcher in sign_appointment function; added unit test

This commit is contained in:
Salvatore Ingala
2019-10-24 12:19:33 +08:00
parent 78a0fb46b0
commit a19bfa13ff
2 changed files with 22 additions and 10 deletions

View File

@@ -34,6 +34,10 @@ class Watcher:
secret_key_pem = key_file.read().encode("utf-8")
self.signing_key = load_pem_private_key(secret_key_pem, password=None, backend=default_backend())
def sign_appointment(self, appointment):
data = appointment.to_json().encode("utf-8")
return self.signing_key.sign(data, ec.ECDSA(hashes.SHA256()))
def add_appointment(self, appointment):
# Rationale:
# The Watcher will analyze every received block looking for appointment matches. If there is no work
@@ -73,10 +77,7 @@ class Watcher:
logger.info("New appointment accepted.", locator=appointment.locator)
signature = self.signing_key.sign(
appointment.to_json().encode("utf-8"),
ec.ECDSA(hashes.SHA256())
)
signature = self.sign_appointment(appointment)
else:
appointment_added = False