From 84750280fdbf5a621e5812d289fd4e285210aa8a Mon Sep 17 00:00:00 2001 From: Martin Vrachev Date: Wed, 10 Feb 2021 22:30:07 +0200 Subject: [PATCH] Address Lukas comments for "Add the Signer..." Signed-off-by: Martin Vrachev --- securesystemslib/signer.py | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/securesystemslib/signer.py b/securesystemslib/signer.py index ceedadd8..3f9d4564 100644 --- a/securesystemslib/signer.py +++ b/securesystemslib/signer.py @@ -36,6 +36,21 @@ def __init__(self, keyid, sig): self.signature = sig + @classmethod + def from_dict(cls, signature_dict): + """ + + Creates a Signature object from its JSON/dict representation. + + + signature_dict: A dict containing that should contain valid keyid + and signature. + Note that the fields should be named "keyid" and "sig" respectively. + """ + + return cls(signature_dict["keyid"], signature_dict["sig"]) + + def to_dict(self): """ @@ -60,7 +75,7 @@ class Signer: def sign(payload): """ - Abstract function used for signig a given payload by the key assigned + Abstract function used for signing a given payload by the key assigned to the Signer instance. @@ -70,7 +85,7 @@ def sign(payload): Returns a "Signature" class instance containing the signature and the the keyid which uniquely identifies the key used for signature generation. """ - pass + raise NotImplementedError # pragma: no cover @@ -78,7 +93,7 @@ class SSlibSigner(Signer): """ Securesystemslib default implementation of the "Signer" interface. - With this implementation the following signature schemas are supported: + With this implementation the following signature schemes are supported: 'RSASSA-PSS' RFC3447 - RSASSA-PSS @@ -88,12 +103,14 @@ class SSlibSigner(Signer): ed25519 - high-speed high security signatures http://ed25519.cr.yp.to/ + 'ecdsa-sha2-nistp256' + https://tools.ietf.org/html/rfc5656 + key_dict: A dictionary containing the keys. Both private and public keys are needed. - Which signature to generate is determined by the key type of 'key_dict' - and the available cryptography library specified in 'settings'. + Which signature to generate is determined by the key type of 'key_dict'. An example RSA key dict has the form: @@ -120,7 +137,7 @@ def sign(self, payload): Returns a "Signature" class instance containing the signature and the - the keyid which uniquely identifies the key used for signature generation. + keyid which uniquely identifies the key used for signature generation. """ sig_dict = sslib_keys.create_signature(self.key_dict, payload)