Coverage for oarepo_c4gh/key/key.py: 100%
15 statements
« prev ^ index » next coverage.py v7.10.2, created at 2025-08-07 12:05 +0000
« prev ^ index » next coverage.py v7.10.2, created at 2025-08-07 12:05 +0000
1"""An abstract Base Class for Asymmetric Secret Keys
3This module contains only the interface specification for all key
4classes implementations.
6"""
8from typing import Protocol, abstractmethod
11class Key(Protocol):
12 """This is an abstract class, containing only abstract methods
13 used to compute the Diffie-Hellman key exchange over the
14 Montgomery curve Curve25519 as specified by the X25519 standard
15 and auxilliary informative helpers.
17 """
19 @property
20 @abstractmethod
21 def public_key(self) -> bytes:
22 """The derived classes must implement providing corresponding
23 public key in this method.
25 Returns:
26 The 32 bytes of the public key.
28 """
29 ...
31 @abstractmethod
32 def compute_write_key(self, reader_public_key: bytes) -> bytes:
33 """Accepts the intended reader public key and computes the
34 shared secret based on the public and secret key (this key) of
35 the writer particular key source implementation.
37 Parameters:
38 reader_public_key: the 32 bytes of the reader public key
40 Returns:
41 The shared secret as 32 bytes - usable as symmetric key.
43 """
44 ...
46 @abstractmethod
47 def compute_read_key(self, writer_public_key: bytes) -> bytes:
48 """Accepts the writer public key and computes the shared
49 secret based on the public and secret key (this key) of the
50 reader particular key source implementation.
52 Parameters:
53 writer_public_key: the 32 bytes of the writer public key
55 Returns:
56 The shared secret as 32 bytes - usable as symmetric key.
58 """
59 ...
61 @property
62 @abstractmethod
63 def can_compute_symmetric_keys(self) -> bool:
64 """A predicate returning true if this key instance can perform
65 read/write key derivation. This is usually determined by
66 having access to the private key (for software implementation)
67 or some other means of working with the private key (for HSM).
69 Returns:
70 true if it can perform symmetric key derivation
72 """
73 return False
75 def __bytes__(self) -> bytes:
76 """Default converter to bytes returns the public key bytes."""
77 return self.public_key