Debian Codegraph @

python/tests/testsigs/pgpcli/base.py

raw
1 # SPDX-FileCopyrightText: Peter Pentchev <[email protected]>
2 # SPDX-License-Identifier: GPL-2.0-or-later
3 """The base class definition for invoking OpenPGP implementations."""
4
5 from __future__ import annotations
6
7 import abc
8 import typing
9
10
11 if typing.TYPE_CHECKING:
12 import pathlib
13
14 from testsigs import defs
15
16
17 class PGPCli(abc.ABC):
18 """An OpenPGP implementation."""
19
20 # Abstract dataclasses still have some quirks, so do this the hard way.
21
22 cfg: defs.Config
23 """The runtime configuration settings, e.g. the paths to the tools to invoke."""
24
25 def __init__(self, cfg: defs.Config) -> None:
26 """Initialize a `PGPCli` object."""
27 self.cfg = cfg
28
29 @abc.abstractmethod
30 def generate_keys(self, uid: str) -> defs.KeyFiles:
31 """Generate an OpenPGP key to sign with."""
32 raise NotImplementedError
33
34 @abc.abstractmethod
35 def import_secret_key(self, keys: defs.KeyFiles, uid: str) -> defs.PublicKey:
36 """Import a secret key, return the parts of the public key we care about."""
37 raise NotImplementedError
38
39 @abc.abstractmethod
40 def sign_detached(self, keys: defs.KeyFiles, datafile: pathlib.Path) -> pathlib.Path:
41 """Create an ASCII-armored detached signature, return the path to the new file."""
42 raise NotImplementedError
43
44 @abc.abstractmethod
45 def verify_detached(
46 self,
47 keys: defs.KeyFiles,
48 pub_key: defs.PublicKey,
49 datafile: pathlib.Path,
50 signature: pathlib.Path,
51 ) -> None:
52 """Verify an OpenPGP detached signature in a file."""
53 raise NotImplementedError