signstar_crypto/signer/error.rs
1//! Contains [`Error`] enum for the low-level signer interface.
2
3use pgp::{
4 crypto::hash::HashAlgorithm,
5 types::{Fingerprint, PublicParams},
6};
7
8use crate::key::base::SignatureType;
9
10/// An error that may occur when working with OpenPGP data.
11#[derive(Debug, thiserror::Error)]
12pub enum Error {
13 /// Certificate for the key has not been initialized
14 #[error("There is no OpenPGP certificate for the key")]
15 OpenPpgCertificateMissing,
16
17 /// Certificate for the key does not have any User IDs.
18 #[error("There are no User IDs in the OpenPGP certificate")]
19 OpenPpgUserIdsMissing {
20 /// The OpenPGP fingerprint of the certificate.
21 fingerprint: Fingerprint,
22 },
23
24 /// Elliptic curve error
25 #[error("Elliptic curve error: {0}")]
26 EllipticCurve(#[from] p256::elliptic_curve::Error),
27
28 /// Public key data is invalid.
29 #[error("Public key data is invalid because {context}")]
30 InvalidPublicKeyData {
31 /// The context in which the error occurred.
32 ///
33 /// This is meant to complete the sentence "Public key data is invalid because ".
34 context: String,
35 },
36
37 /// An OpenPGP error occurred.
38 #[error("OpenPGP error: {0}")]
39 Pgp(#[from] pgp::errors::Error),
40
41 /// An OpenPGP Transferable Secret Key (TSK) is passphrase protected.
42 #[error(
43 "The OpenPGP Transferable Secret Key (TSK) with fingerprint {fingerprint} is passphrase protected"
44 )]
45 OpenPgpTskIsPassphraseProtected {
46 /// The OpenPGP fingerprint of the TSK.
47 fingerprint: Fingerprint,
48 },
49
50 /// An OpenPGP Transferable Secret Key (TSK) contains multiple component keys.
51 #[error(
52 "The OpenPGP Transferable Secret Key (TSK) with fingerprint {fingerprint} contains multiple component keys, which is not supported"
53 )]
54 OpenPgpTskContainsMultipleComponentKeys {
55 /// The OpenPGP fingerprint of the TSK.
56 fingerprint: Fingerprint,
57 },
58
59 /// An invalid signature is encountered.
60 #[error("Invalid signature {signature_type} encountered while {context}")]
61 InvalidSignature {
62 /// The context in which an invalid signature has been detected.
63 ///
64 /// This is meant to complete the sentence "Invalid signature encountered
65 /// while ".
66 context: &'static str,
67
68 /// Signature type encountered when this error occurred.
69 signature_type: SignatureType,
70 },
71
72 /// An unsupported hash algorithm is requested.
73 #[error("Unsupported hash algorithm requested. Expected {expected}, but got {actual}")]
74 UnsupportedHashAlgorithm {
75 /// The hash algorithm that has been used.
76 actual: HashAlgorithm,
77
78 /// The hash algorithm that is supported.
79 expected: HashAlgorithm,
80 },
81
82 /// An unsupported signature algorithm is requested.
83 #[error("Unsupported signature algorithm requested: {0}")]
84 UnsupportedSignatureAlgorithm(SignatureType),
85
86 /// The key format used is unsupported
87 #[error("Unsupported key format {public_params:?} encountered while {context}")]
88 UnsupportedKeyFormat {
89 /// The context in which an unsupported key format has been detected.
90 ///
91 /// This is meant to complete the sentence "Unsupported key format encountered
92 /// while ".
93 context: &'static str,
94
95 /// The unsupported public key parameters.
96 public_params: Box<PublicParams>,
97 },
98
99 /// An HSM operation error.
100 #[error("HSM operation failed while {context}:\n{source}")]
101 Hsm {
102 /// The context in which an HSM error occurred.
103 ///
104 /// This is meant to complete the sentence "HSM operation failed
105 /// while ".
106 context: &'static str,
107 /// The source error.
108 source: Box<dyn std::error::Error + 'static + Send + Sync>,
109 },
110}