[openpgp] Handle keys not suited for xmpp

This commit is contained in:
lovetox
2022-04-16 20:48:16 +02:00
parent 52bf024ef5
commit f6411db908

View File

@@ -32,6 +32,13 @@ class KeyringItem:
self._key = key self._key = key
self._uid = self._get_uid() self._uid = self._get_uid()
@property
def is_xmpp_key(self) -> bool:
try:
return self.jid is not None
except Exception:
return False
def _get_uid(self): def _get_uid(self):
for uid in self._key.uids: for uid in self._key.uids:
if uid.uid.startswith('xmpp:'): if uid.uid.startswith('xmpp:'):
@@ -55,7 +62,6 @@ class KeyringItem:
return hash(self.fingerprint) return hash(self.fingerprint)
class GPGME: class GPGME:
def __init__(self, jid, gnuhome): def __init__(self, jid, gnuhome):
self._jid = jid self._jid = jid
@@ -109,7 +115,13 @@ class GPGME:
keys = [] keys = []
with gpg.Context(**self._context_args) as context: with gpg.Context(**self._context_args) as context:
for key in context.keylist(): for key in context.keylist():
keys.append(KeyringItem(key)) keyring_item = KeyringItem(key)
if not keyring_item.is_xmpp_key:
log.warning('Key not suited for xmpp: %s', key.fpr)
continue
keys.append(keyring_item)
return keys return keys
def export_key(self, fingerprint): def export_key(self, fingerprint):