[Python-modules-commits] [python-gnupg] 02/08: Avoid exceptions on unknown status keywords
Elena Grandi
valhalla-guest at moszumanska.debian.org
Sat Apr 8 06:44:43 UTC 2017
This is an automated email from the git hooks/post-receive script.
valhalla-guest pushed a commit to branch gpg2
in repository python-gnupg.
commit 6787db516ce3896d8e566ecc8343bc5d98d74795
Author: Daniel Kahn Gillmor <dkg at fifthhorseman.net>
Date: Fri Feb 17 17:23:05 2017 -0500
Avoid exceptions on unknown status keywords
in upstream GnuPG, doc/DETAILS says:
---------
* Format of the --status-fd output
Every line is prefixed with "[GNUPG:] ", followed by a keyword with
the type of the status line and some arguments depending on the type
(maybe none); an application should always be willing to ignore
unknown keywords that may be emitted by future versions of GnuPG.
Also, new versions of GnuPG may add arguments to existing keywords.
Any additional arguments should be ignored for forward-compatibility.
---------
This set of changes ensures that any time we're looking for status
messages it is only to look for them positively -- if we encounter an
unknown or other status message, we'll just let it slide by without an
error.
---
gnupg.py | 47 ++++-------------------------------------------
1 file changed, 4 insertions(+), 43 deletions(-)
diff --git a/gnupg.py b/gnupg.py
index 0412531..7ff9f11 100644
--- a/gnupg.py
+++ b/gnupg.py
@@ -240,14 +240,6 @@ class Verify(object):
if key in self.TRUST_LEVELS:
self.trust_text = key
self.trust_level = self.TRUST_LEVELS[key]
- elif key in ("RSA_OR_IDEA", "NODATA", "IMPORT_RES", "PLAINTEXT",
- "PLAINTEXT_LENGTH", "POLICY_URL", "DECRYPTION_INFO",
- "DECRYPTION_OKAY", "INV_SGNR", "FILE_START", "FILE_ERROR",
- "FILE_DONE", "PKA_TRUST_GOOD", "PKA_TRUST_BAD", "BADMDC",
- "GOODMDC", "NO_SGNR", "NOTATION_NAME", "NOTATION_DATA",
- "PROGRESS", "PINENTRY_LAUNCHED", "NEWSIG",
- "KEY_CONSIDERED"):
- pass
elif key == "BADSIG": # pragma: no cover
self.valid = False
self.status = 'signature bad'
@@ -286,12 +278,6 @@ class Verify(object):
self.valid = False
self.key_id = value
self.status = 'no public key'
- elif key in ("KEYEXPIRED", "SIGEXPIRED", "KEYREVOKED"): # pragma: no cover
- # these are useless in verify, since they are spit out for any
- # pub/subkeys on the key, not just the one doing the signing.
- # if we want to check for signatures with expired key,
- # the relevant flag is EXPKEYSIG or REVKEYSIG.
- pass
elif key in ("EXPKEYSIG", "REVKEYSIG"): # pragma: no cover
# signed with expired or revoked key
self.valid = False
@@ -309,8 +295,6 @@ class Verify(object):
else:
# N.B. there might be other reasons
self.status = 'incorrect passphrase'
- else:
- raise ValueError("Unknown status message: %r" % key)
class ImportResult(object):
"Handle status messages for --import"
@@ -385,8 +369,6 @@ class ImportResult(object):
elif key == "SIGEXPIRED": # pragma: no cover
self.results.append({'fingerprint': None,
'problem': '0', 'text': 'Signature expired'})
- else: # pragma: no cover
- raise ValueError("Unknown status message: %r" % key)
def summary(self):
l = []
@@ -552,14 +534,8 @@ class Crypt(Verify, TextHandler):
__bool__ = __nonzero__
def handle_status(self, key, value):
- if key in ("ENC_TO", "USERID_HINT", "GOODMDC", "END_DECRYPTION",
- "BEGIN_SIGNING", "NO_SECKEY", "ERROR", "NODATA", "PROGRESS",
- "CARDCTRL", "BADMDC", "SC_OP_FAILURE", "SC_OP_SUCCESS",
- "PINENTRY_LAUNCHED"):
- # in the case of ERROR, this is because a more specific error
- # message will have come first
- if key == "NODATA":
- self.status = "no data was provided"
+ if key == "NODATA":
+ self.status = "no data was provided"
elif key in ("NEED_PASSPHRASE", "BAD_PASSPHRASE", "GOOD_PASSPHRASE",
"MISSING_PASSPHRASE", "DECRYPTION_FAILED",
"KEY_NOT_CREATED", "NEED_PASSPHRASE_PIN"):
@@ -604,13 +580,8 @@ class GenKey(object):
return self.fingerprint or ''
def handle_status(self, key, value):
- if key in ("PROGRESS", "GOOD_PASSPHRASE", "NODATA", "KEY_NOT_CREATED",
- "PINENTRY_LAUNCHED"):
- pass
- elif key == "KEY_CREATED":
+ if key == "KEY_CREATED":
(self.type,self.fingerprint) = value.split()
- else:
- raise ValueError("Unknown status message: %r" % key)
class ExportResult(GenKey):
"""Handle status messages for --export[-secret-key].
@@ -643,8 +614,6 @@ class DeleteResult(object):
if key == "DELETE_PROBLEM": # pragma: no cover
self.status = self.problem_reason.get(value,
"Unknown error: %r" % value)
- else: # pragma: no cover
- raise ValueError("Unknown status message: %r" % key)
def __nonzero__(self):
return self.status == 'ok'
@@ -666,13 +635,7 @@ class Sign(TextHandler):
__bool__ = __nonzero__
def handle_status(self, key, value):
- if key in ("USERID_HINT", "NEED_PASSPHRASE", "BAD_PASSPHRASE",
- "GOOD_PASSPHRASE", "BEGIN_SIGNING", "CARDCTRL", "INV_SGNR",
- "NO_SGNR", "MISSING_PASSPHRASE", "NEED_PASSPHRASE_PIN",
- "SC_OP_FAILURE", "SC_OP_SUCCESS", "PROGRESS",
- "PINENTRY_LAUNCHED"):
- pass
- elif key in ("KEYEXPIRED", "SIGEXPIRED"): # pragma: no cover
+ if key in ("KEYEXPIRED", "SIGEXPIRED"): # pragma: no cover
self.status = 'key expired'
elif key == "KEYREVOKED": # pragma: no cover
self.status = 'key revoked'
@@ -681,8 +644,6 @@ class Sign(TextHandler):
algo, self.hash_algo, cls,
self.timestamp, self.fingerprint
) = value.split()
- else: # pragma: no cover
- raise ValueError("Unknown status message: %r" % key)
VERSION_RE = re.compile(r'gpg \(GnuPG\) (\d+(\.\d+)*)'.encode('ascii'), re.I)
HEX_DIGITS_RE = re.compile(r'[0-9a-f]+$', re.I)
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-gnupg.git
More information about the Python-modules-commits
mailing list