From 77dfbc34bcf2dad729bc5df9409fb331d1e7d597 Mon Sep 17 00:00:00 2001 From: vladdd Date: Fri, 21 Feb 2014 12:16:56 -0500 Subject: [PATCH] Raise exception if key not found in the key-removal methods. Santiago's request: The key-removal methods in repository_tool.py should raise an exception if the key argument has not been previously loaded. They previously returned silently if the key was not found. --- tuf/repository_tool.py | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/tuf/repository_tool.py b/tuf/repository_tool.py index 39a1db11..2ec676cb 100755 --- a/tuf/repository_tool.py +++ b/tuf/repository_tool.py @@ -590,7 +590,7 @@ def remove_verification_key(self, key): """ Remove 'key' from the role's currently recognized list of role keys. - The role expects a threshold number of signatures + The role expects a threshold number of signatures. >>> >>> @@ -599,12 +599,15 @@ def remove_verification_key(self, key): key: The role's key, conformant to 'tuf.formats.ANYKEY_SCHEMA'. 'key' - should contain the only the public portion, as only the public key - is needed. The 'add_verification_key()' method should have previously added 'key'. + should contain only the public portion, as only the public key is + needed. The 'add_verification_key()' method should have previously + added 'key'. tuf.FormatError, if the 'key' argument is improperly formatted. - + + tuf.Error, if the 'key' argument has not been previously added. + Updates the role's 'tuf.roledb.py' entry. @@ -625,6 +628,9 @@ def remove_verification_key(self, key): roleinfo['keyids'].remove(keyid) tuf.roledb.update_roleinfo(self._rolename, roleinfo) + + else: + raise tuf.Error('Verification key not found.') @@ -705,6 +711,8 @@ def unload_signing_key(self, key): tuf.FormatError, if the 'key' argument is improperly formatted. + tuf.Error, if the 'key' argument has not been previously loaded. + Updates the signing keys of the role in 'tuf.roledb.py'. @@ -725,7 +733,10 @@ def unload_signing_key(self, key): roleinfo['signing_keyids'].remove(key['keyid']) tuf.roledb.update_roleinfo(self.rolename, roleinfo) - + + else: + raise tuf.Error('Signing key not found.') + def add_signature(self, signature): @@ -1809,7 +1820,8 @@ def remove_target(self, filepath): tuf.FormatError, if 'filepath' is improperly formatted. - tuf.Error, if 'filepath' is not under the repository's targets directory. + tuf.Error, if 'filepath' is not under the repository's targets directory, + or not found. Modifies this Targets 'tuf.roledb.py' entry. @@ -1840,8 +1852,10 @@ def remove_target(self, filepath): fileinfo = tuf.roledb.get_roleinfo(self.rolename) if relative_filepath in fileinfo['paths']: fileinfo['paths'].remove(relative_filepath) - - tuf.roledb.update_roleinfo(self.rolename, fileinfo) + tuf.roledb.update_roleinfo(self.rolename, fileinfo) + + else: + raise tuf.Error('Target file path not found.')