From 7a4b76f64fc08d667ac48f432a726061998bd81f Mon Sep 17 00:00:00 2001 From: J08nY Date: Wed, 2 Aug 2017 20:59:26 +0200 Subject: Fix use of key_usable(). --- src/mailman_pgp/commands/eml_key.py | 5 +++-- src/mailman_pgp/utils/pgp.py | 5 ++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/mailman_pgp/commands/eml_key.py b/src/mailman_pgp/commands/eml_key.py index e182451..b958b93 100644 --- a/src/mailman_pgp/commands/eml_key.py +++ b/src/mailman_pgp/commands/eml_key.py @@ -23,6 +23,7 @@ from mailman.interfaces.command import ContinueProcessing, IEmailCommand from mailman.interfaces.pending import IPendings from mailman.interfaces.subscriptions import ISubscriptionManager from mailman.interfaces.usermanager import IUserManager +from pgpy.constants import KeyFlags from public import public from zope.component import getUtility from zope.interface import implementer @@ -77,7 +78,7 @@ def _cmd_set(pgp_list, mlist, msg, msgdata, arguments, results): file=results) return ContinueProcessing.no - if not key_usable(key): + if not key_usable(key, {KeyFlags.EncryptCommunications, KeyFlags.Sign}): print('Need a key which can be used to encrypt communications.', file=results) return ContinueProcessing.no @@ -228,7 +229,7 @@ def _cmd_change(pgp_list, mlist, msg, msgdata, arguments, results): file=results) return ContinueProcessing.no - if not key_usable(key): + if not key_usable(key, {KeyFlags.EncryptCommunications, KeyFlags.Sign}): print('Need a key which can be used to encrypt communications.', file=results) return ContinueProcessing.no diff --git a/src/mailman_pgp/utils/pgp.py b/src/mailman_pgp/utils/pgp.py index 1dfdc5e..416e643 100644 --- a/src/mailman_pgp/utils/pgp.py +++ b/src/mailman_pgp/utils/pgp.py @@ -107,6 +107,7 @@ def key_usable(key, flags_required): :param key: :type key: pgpy.PGPKey :param flags_required: + :type flags_required: set :return: :rtype: bool """ @@ -125,6 +126,4 @@ def key_usable(key, flags_required): for subkey in key.subkeys.values(): usage_flags |= subkey.usage_flags() - if flags_required not in usage_flags: - return False - return True + return flags_required.issubset(usage_flags) -- cgit v1.2.3-70-g09d2