File: base.py

package info (click to toggle)
debsigs 0.2.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 420 kB
  • sloc: python: 1,160; perl: 728; makefile: 12; sh: 9
file content (53 lines) | stat: -rw-r--r-- 1,612 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# SPDX-FileCopyrightText: Peter Pentchev <roam@ringlet.net>
# SPDX-License-Identifier: GPL-2.0-or-later
"""The base class definition for invoking OpenPGP implementations."""

from __future__ import annotations

import abc
import typing


if typing.TYPE_CHECKING:
    import pathlib

    from testsigs import defs


class PGPCli(abc.ABC):
    """An OpenPGP implementation."""

    # Abstract dataclasses still have some quirks, so do this the hard way.

    cfg: defs.Config
    """The runtime configuration settings, e.g. the paths to the tools to invoke."""

    def __init__(self, cfg: defs.Config) -> None:
        """Initialize a `PGPCli` object."""
        self.cfg = cfg

    @abc.abstractmethod
    def generate_keys(self, uid: str) -> defs.KeyFiles:
        """Generate an OpenPGP key to sign with."""
        raise NotImplementedError

    @abc.abstractmethod
    def import_secret_key(self, keys: defs.KeyFiles, uid: str) -> defs.PublicKey:
        """Import a secret key, return the parts of the public key we care about."""
        raise NotImplementedError

    @abc.abstractmethod
    def sign_detached(self, keys: defs.KeyFiles, datafile: pathlib.Path) -> pathlib.Path:
        """Create an ASCII-armored detached signature, return the path to the new file."""
        raise NotImplementedError

    @abc.abstractmethod
    def verify_detached(
        self,
        keys: defs.KeyFiles,
        pub_key: defs.PublicKey,
        datafile: pathlib.Path,
        signature: pathlib.Path,
    ) -> None:
        """Verify an OpenPGP detached signature in a file."""
        raise NotImplementedError