signstar_config/config/state/
common.rs

1//! Common components used in state handling.
2
3use std::fmt::Display;
4
5#[cfg(doc)]
6use pgp::composed::SignedPublicKey;
7use signstar_crypto::key::CryptographicKeyContext;
8
9/// The state of a key certificate.
10///
11/// Key certificates are technology specific and carry information on the context in which a key is
12/// used. They can be derived e.g. from Signstar backends or Signstar configuration files.
13#[derive(Clone, Debug, Eq, PartialEq)]
14pub enum KeyCertificateState {
15    /// A [`CryptographicKeyContext`] describing the context in which a certificate is used.
16    KeyContext(CryptographicKeyContext),
17
18    /// There is no key certificate for the key.
19    Empty,
20
21    /// A key certificate could not be retrieved due to an error.
22    Error {
23        /// A string containing the error message.
24        message: String,
25    },
26
27    /// The key certificate cannot be turned into a [`CryptographicKeyContext`].
28    NotACryptographicKeyContext {
29        /// A message explaining that and why the [`CryptographicKeyContext`] cannot be created.
30        message: String,
31    },
32
33    /// The key certificate cannot be turned into a [`SignedPublicKey`] (an OpenPGP certificate).
34    NotAnOpenPgpCertificate {
35        /// A message explaining why the key certificate cannot be converted to a
36        /// [`SignedPublicKey`].
37        message: String,
38    },
39}
40
41impl Display for KeyCertificateState {
42    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
43        match self {
44            Self::KeyContext(context) => write!(f, "{context}"),
45            Self::Empty => write!(f, "Empty"),
46            Self::Error { message } => {
47                write!(f, "Error retrieving key certificate - {message}")
48            }
49            Self::NotACryptographicKeyContext { message } => {
50                write!(f, "Not a cryptographic key context - \"{message}\"")
51            }
52            Self::NotAnOpenPgpCertificate { message } => {
53                write!(f, "Not an OpenPGP certificate - \"{message}\"")
54            }
55        }
56    }
57}