2020import subprocess # nosec
2121import time
2222
23- from securesystemslib import exceptions , formats
23+ from securesystemslib import exceptions
2424from securesystemslib .gpg .common import (
2525 get_pubkey_bundle ,
2626 parse_signature_packet ,
@@ -73,9 +73,6 @@ def create_signature(content, keyid=None, homedir=None, timeout=GPG_TIMEOUT):
7373 gpg command timeout in seconds. Default is 10.
7474
7575 <Exceptions>
76- securesystemslib.exceptions.FormatError:
77- If the keyid was passed and does not match
78- securesystemslib.formats.KEYID_SCHEMA
7976
8077 ValueError:
8178 If the gpg command failed to create a valid signature.
@@ -98,8 +95,7 @@ def create_signature(content, keyid=None, homedir=None, timeout=GPG_TIMEOUT):
9895 None.
9996
10097 <Returns>
101- The created signature in the format:
102- securesystemslib.formats.GPG_SIGNATURE_SCHEMA.
98+ A signature dict.
10399
104100 """
105101 if not have_gpg (): # pragma: no cover
@@ -110,7 +106,6 @@ def create_signature(content, keyid=None, homedir=None, timeout=GPG_TIMEOUT):
110106
111107 keyarg = ""
112108 if keyid :
113- formats .KEYID_SCHEMA .check_match (keyid )
114109 keyarg = (
115110 "--local-user {}" .format ( # pylint: disable=consider-using-f-string
116111 keyid
@@ -211,12 +206,10 @@ def verify_signature(signature_object, pubkey_info, content):
211206
212207 <Arguments>
213208 signature_object:
214- A signature object in the format:
215- securesystemslib.formats.GPG_SIGNATURE_SCHEMA
209+ A signature dict.
216210
217211 pubkey_info:
218- A public key object in the format:
219- securesystemslib.formats.GPG_PUBKEY_SCHEMA
212+ A public key dict.
220213
221214 content:
222215 The content to be verified. (bytes)
@@ -238,9 +231,6 @@ def verify_signature(signature_object, pubkey_info, content):
238231 if not CRYPTO : # pragma: no cover
239232 raise exceptions .UnsupportedLibraryError (NO_CRYPTO_MSG )
240233
241- formats .GPG_PUBKEY_SCHEMA .check_match (pubkey_info )
242- formats .GPG_SIGNATURE_SCHEMA .check_match (signature_object )
243-
244234 handler = SIGNATURE_HANDLERS [pubkey_info ["type" ]]
245235 sig_keyid = signature_object ["keyid" ]
246236
@@ -270,13 +260,12 @@ def export_pubkey(keyid, homedir=None, timeout=GPG_TIMEOUT):
270260 """Exports a public key from a GnuPG keyring.
271261
272262 Arguments:
273- keyid: An OpenPGP keyid in KEYID_SCHEMA format .
263+ keyid: An OpenPGP keyid. .
274264 homedir (optional): A path to the GnuPG home directory. If not set the
275265 default GnuPG home directory is used.
276266 timeout (optional): gpg command timeout in seconds. Default is 10.
277267
278268 Raises:
279- ValueError: Keyid is not a string.
280269 UnsupportedLibraryError: The gpg command or pyca/cryptography are not
281270 available.
282271 KeyNotFoundError: No key or subkey was found for that keyid.
@@ -285,7 +274,7 @@ def export_pubkey(keyid, homedir=None, timeout=GPG_TIMEOUT):
285274 Calls system gpg command in a subprocess.
286275
287276 Returns:
288- An OpenPGP public key object in GPG_PUBKEY_SCHEMA format .
277+ An OpenPGP public key dict .
289278
290279 """
291280 if not have_gpg (): # pragma: no cover
@@ -294,14 +283,6 @@ def export_pubkey(keyid, homedir=None, timeout=GPG_TIMEOUT):
294283 if not CRYPTO : # pragma: no cover
295284 raise exceptions .UnsupportedLibraryError (NO_CRYPTO_MSG )
296285
297- if not formats .KEYID_SCHEMA .matches (keyid ):
298- # FIXME: probably needs smarter parsing of what a valid keyid is so as to
299- # not export more than one pubkey packet.
300- raise ValueError (
301- "we need to export an individual key. Please provide a " # pylint: disable=consider-using-f-string
302- " valid keyid! Keyid was '{}'." .format (keyid )
303- )
304-
305286 homearg = ""
306287 if homedir :
307288 homearg = (
@@ -330,7 +311,7 @@ def export_pubkeys(keyids, homedir=None, timeout=GPG_TIMEOUT):
330311 """Exports multiple public keys from a GnuPG keyring.
331312
332313 Arguments:
333- keyids: A list of OpenPGP keyids in KEYID_SCHEMA format .
314+ keyids: A list of OpenPGP keyids.
334315 homedir (optional): A path to the GnuPG home directory. If not set the
335316 default GnuPG home directory is used.
336317 timeout (optional): gpg command timeout in seconds. Default is 10.
@@ -346,7 +327,7 @@ def export_pubkeys(keyids, homedir=None, timeout=GPG_TIMEOUT):
346327 Calls system gpg command in a subprocess.
347328
348329 Returns:
349- A dict of OpenPGP public key objects in GPG_PUBKEY_SCHEMA format as values,
330+ A dict of OpenPGP public key dicts as values,
350331 and their keyids as dict keys.
351332
352333
0 commit comments