Skip to content

Commit

Permalink
Address Lukas comments for "Add the Signer..."
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Vrachev <[email protected]>
  • Loading branch information
MVrachev committed Feb 10, 2021
1 parent 61fd02a commit 8475028
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions securesystemslib/signer.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,21 @@ def __init__(self, keyid, sig):
self.signature = sig


@classmethod
def from_dict(cls, signature_dict):
"""
<Purpose>
Creates a Signature object from its JSON/dict representation.
<Arguments>
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):
"""
<Purpose>
Expand All @@ -60,7 +75,7 @@ class Signer:
def sign(payload):
"""
<Purpose>
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.
<Arguments>
Expand All @@ -70,15 +85,15 @@ 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



class SSlibSigner(Signer):
"""
<Purpose>
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
Expand All @@ -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
<Attributes>
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:
Expand All @@ -120,7 +137,7 @@ def sign(self, payload):
<Returns>
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)
Expand Down

0 comments on commit 8475028

Please sign in to comment.