[openpgp] Fix pyright errors
This commit is contained in:
@@ -24,6 +24,7 @@ from pathlib import Path
|
|||||||
|
|
||||||
import gpg
|
import gpg
|
||||||
from gpg.errors import KeyNotFound
|
from gpg.errors import KeyNotFound
|
||||||
|
from gpg.results import GenkeyResult
|
||||||
from gpg.results import ImportResult
|
from gpg.results import ImportResult
|
||||||
from nbxmpp.protocol import JID
|
from nbxmpp.protocol import JID
|
||||||
|
|
||||||
@@ -64,12 +65,15 @@ class GPGMe(BasePGPBackend):
|
|||||||
|
|
||||||
def generate_key(self) -> None:
|
def generate_key(self) -> None:
|
||||||
with self._get_context() as context:
|
with self._get_context() as context:
|
||||||
result = context.create_key(
|
result = cast(
|
||||||
|
GenkeyResult,
|
||||||
|
context.create_key(
|
||||||
f"xmpp:{self._jid}",
|
f"xmpp:{self._jid}",
|
||||||
algorithm="default",
|
algorithm="default",
|
||||||
expires=False,
|
expires=False,
|
||||||
passphrase=None,
|
passphrase=None,
|
||||||
force=False,
|
force=False,
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
log.info("Generated new key: %s", result.fpr)
|
log.info("Generated new key: %s", result.fpr)
|
||||||
@@ -174,6 +178,7 @@ class GPGMe(BasePGPBackend):
|
|||||||
|
|
||||||
def import_key(self, data: bytes, jid: JID) -> KeyringItem | None:
|
def import_key(self, data: bytes, jid: JID) -> KeyringItem | None:
|
||||||
log.info("Import key from %s", jid)
|
log.info("Import key from %s", jid)
|
||||||
|
item = None
|
||||||
with self._get_context() as context:
|
with self._get_context() as context:
|
||||||
result = context.key_import(data)
|
result = context.key_import(data)
|
||||||
if not isinstance(result, ImportResult) or result.imported != 1:
|
if not isinstance(result, ImportResult) or result.imported != 1:
|
||||||
@@ -183,6 +188,7 @@ class GPGMe(BasePGPBackend):
|
|||||||
|
|
||||||
fingerprint = result.imports[0].fpr
|
fingerprint = result.imports[0].fpr
|
||||||
key = self._get_key(fingerprint)
|
key = self._get_key(fingerprint)
|
||||||
|
assert key is not None
|
||||||
item = KeyringItem(key)
|
item = KeyringItem(key)
|
||||||
if not item.is_valid(jid):
|
if not item.is_valid(jid):
|
||||||
log.warning("Invalid key found")
|
log.warning("Invalid key found")
|
||||||
@@ -197,4 +203,4 @@ class GPGMe(BasePGPBackend):
|
|||||||
key = self._get_key(fingerprint)
|
key = self._get_key(fingerprint)
|
||||||
assert key is not None
|
assert key is not None
|
||||||
with self._get_context() as context:
|
with self._get_context() as context:
|
||||||
context.op_delete(key, True)
|
context.op_delete(key, True) # pyright: ignore
|
||||||
|
|||||||
@@ -80,8 +80,7 @@ class ContactData:
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def userid(self):
|
def userid(self):
|
||||||
if self.jid is None:
|
assert self.jid is not None, "JID not set"
|
||||||
raise ValueError("JID not set")
|
|
||||||
return "xmpp:%s" % self.jid
|
return "xmpp:%s" % self.jid
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
from .core import Context # noqa: F401
|
from .core import Context # noqa: F401 # pyright: ignore
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ from collections.abc import Iterator
|
|||||||
|
|
||||||
from gpg.results import DecryptResult
|
from gpg.results import DecryptResult
|
||||||
from gpg.results import EncryptResult
|
from gpg.results import EncryptResult
|
||||||
from gpg.results import Key
|
|
||||||
from gpg.results import SignResult
|
from gpg.results import SignResult
|
||||||
from gpg.results import VerifyResult
|
from gpg.results import VerifyResult
|
||||||
|
|
||||||
|
|||||||
@@ -50,13 +50,31 @@ class VerifyResult(Result):
|
|||||||
is_mime: int
|
is_mime: int
|
||||||
signatures: list[Signature]
|
signatures: list[Signature]
|
||||||
|
|
||||||
class ImportStatus(Result): ...
|
class ImportStatus(Result):
|
||||||
|
fpr: str
|
||||||
|
result: int
|
||||||
|
status: int
|
||||||
|
|
||||||
class ImportResult(Result):
|
class ImportResult(Result):
|
||||||
imports: ImportStatus
|
imported: int
|
||||||
|
imported_rsa: int
|
||||||
|
imports: list[ImportStatus]
|
||||||
|
new_revocations: int
|
||||||
|
new_signatures: int
|
||||||
|
new_sub_keys: int
|
||||||
|
new_user_ids: int
|
||||||
|
no_user_id: int
|
||||||
|
not_imported: int
|
||||||
|
secret_imported: int
|
||||||
|
secret_read: int
|
||||||
|
secret_unchanged: int
|
||||||
|
skipped_new_keys: int
|
||||||
|
skipped_v3_keys: int
|
||||||
|
unchanged: int
|
||||||
|
|
||||||
class GenkeyResult(Result):
|
class GenkeyResult(Result):
|
||||||
_type = dict(primary=bool, sub=bool)
|
_type = dict(primary=bool, sub=bool)
|
||||||
|
fpr: str
|
||||||
|
|
||||||
class KeylistResult(Result):
|
class KeylistResult(Result):
|
||||||
_type = dict(truncated=bool)
|
_type = dict(truncated=bool)
|
||||||
|
|||||||
Reference in New Issue
Block a user