Commit 86ba7b7c authored by Nicolas Dandrimont's avatar Nicolas Dandrimont 🤔
Browse files

Factor in all the default arguments to gpg, and add a secret-keyring

option to avoid accidentally clobbering the system one.
parent 89fd4b43
...@@ -138,11 +138,8 @@ class GnuPG(object): ...@@ -138,11 +138,8 @@ class GnuPG(object):
path to public key ring (when not specified, the default GPG path to public key ring (when not specified, the default GPG
setting will be used (~/.gnupg/pubring.gpg)) setting will be used (~/.gnupg/pubring.gpg))
""" """
if pubring is None: args = ('--verify', signed_file)
pubring = self.default_keyring return self._run(args=args, pubring=pubring)
args = ('--no-options', '--batch', '--verify', '--keyring', pubring, '--no-default-keyring', signed_file)
return self._run(args=args)
def add_signature(self, signature_file, pubring=None): def add_signature(self, signature_file, pubring=None):
...@@ -156,11 +153,8 @@ class GnuPG(object): ...@@ -156,11 +153,8 @@ class GnuPG(object):
Returns a tuple (file output, return code) Returns a tuple (file output, return code)
""" """
if pubring is None: args = ('--import-options', 'import-minimal', '--import', signature_file)
pubring = self.default_keyring return self._run(args=args, pubring=pubring)
args = ('--no-options', '--batch', '--no-default-keyring', '--keyring', pubring, '--import-options', 'import-minimal', '--import', signature_file )
return self._run(args=args)
def remove_signature(self, keyid, pubring=None): def remove_signature(self, keyid, pubring=None):
...@@ -174,14 +168,11 @@ class GnuPG(object): ...@@ -174,14 +168,11 @@ class GnuPG(object):
Returns a tuple (file output, return code) Returns a tuple (file output, return code)
""" """
if pubring is None: args = ('--yes', '--delete-key', keyid)
pubring = self.default_keyring return self._run(args=args, pubring=pubring)
args = ('--no-options', '--batch', '--no-default-keyring', '--keyring', pubring, '--yes', '--delete-key', keyid )
return self._run(args=args)
def _run(self, stdin=None, args=None): def _run(self, stdin=None, args=None, pubring=None):
""" """
Run gpg with the given stdin and arguments and return the output and Run gpg with the given stdin and arguments and return the output and
exit status. exit status.
...@@ -190,12 +181,25 @@ class GnuPG(object): ...@@ -190,12 +181,25 @@ class GnuPG(object):
Feed gpg with this input to stdin Feed gpg with this input to stdin
``args`` ``args``
a list of strings to be passed as argument(s) to gpg a list of strings to be passed as argument(s) to gpg
``pubring``
the path to the public gpg keyring. Note that
``pubring + ".secret"`` will be used as the private keyring
""" """
if self.gpg_path is None: if self.gpg_path is None:
return (None, GnuPG.GPG_PATH_NOT_INITIALISED) return (None, GnuPG.GPG_PATH_NOT_INITIALISED)
cmd = [ self.gpg_path, ] if pubring is None:
pubring = self.default_keyring
cmd = [
self.gpg_path,
'--no-options',
'--batch',
'--no-default-keyring',
'--secret-keyring', pubring + ".secret",
'--keyring', pubring,
]
if not args is None: if not args is None:
cmd.extend(args) cmd.extend(args)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment