From caf278c63b57229d05ca981a9e553d9e76db31bc Mon Sep 17 00:00:00 2001 From: Jussi Kukkonen Date: Fri, 11 Jun 2021 09:57:08 +0300 Subject: [PATCH] Metadata API: Fix Metadata.sign() return value We've been returning Signature objects since 49aa0fc167. Also add a test case that does something with the returned signature. Signed-off-by: Jussi Kukkonen --- tests/test_api.py | 4 +++- tuf/api/metadata.py | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/test_api.py b/tests/test_api.py index 7d00a85720..40afc9a17f 100755 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -183,12 +183,14 @@ def test_sign_verify(self): sslib_signer = SSlibSigner(self.keystore['snapshot']) # Append a new signature with the unrelated key and assert that ... - metadata_obj.sign(sslib_signer, append=True) + sig = metadata_obj.sign(sslib_signer, append=True) # ... there are now two signatures, and self.assertTrue(len(metadata_obj.signatures) == 2) # ... both are valid for the corresponding keys. targets_key.verify_signature(metadata_obj) snapshot_key.verify_signature(metadata_obj) + # ... the returned (appended) signature is for snapshot key + self.assertEqual(sig.keyid, snapshot_keyid) sslib_signer = SSlibSigner(self.keystore['timestamp']) # Create and assign (don't append) a new signature and assert that ... diff --git a/tuf/api/metadata.py b/tuf/api/metadata.py index 5f6a210e45..25b24cc8ba 100644 --- a/tuf/api/metadata.py +++ b/tuf/api/metadata.py @@ -211,7 +211,7 @@ def sign( signer: Signer, append: bool = False, signed_serializer: Optional[SignedSerializer] = None, - ) -> Dict[str, Any]: + ) -> Signature: """Creates signature over 'signed' and assigns it to 'signatures'. Arguments: @@ -232,7 +232,7 @@ def sign( Signing errors. Returns: - A securesystemslib-style signature object. + Securesystemslib Signature object that was added into signatures. """ if signed_serializer is None: