signstar_crypto/key/
error.rs1use crate::key::base::{KeyMechanism, KeyType, MIN_RSA_BIT_LENGTH, SignatureType};
4
5#[derive(Debug, thiserror::Error)]
7pub enum Error {
8 #[error("PKCS#8 error: {0}")]
10 Pkcs8(#[from] rsa::pkcs8::Error),
11
12 #[error("No primes found")]
14 NoPrimes,
15
16 #[error("The {0} key type is not supported")]
18 UnsupportedKeyType(KeyType),
19
20 #[error(
22 "The input buffer is {buffer_len} bytes long, but should be padded to only {pad_len} bytes in length."
23 )]
24 PaddingInputTooLong {
25 buffer_len: usize,
27 pad_len: usize,
29 },
30
31 #[error(
33 "The key type {key_type} does not support the following key mechanisms: {invalid_mechanisms:?}"
34 )]
35 InvalidKeyMechanism {
36 key_type: KeyType,
38 invalid_mechanisms: Vec<KeyMechanism>,
40 },
41
42 #[error("Elliptic curve key ({key_type}) does not support setting length")]
44 KeyLengthUnsupported {
45 key_type: KeyType,
47 },
48
49 #[error("Generating a key of type {key_type} requires setting a length")]
51 KeyLengthRequired {
52 key_type: KeyType,
54 },
55
56 #[error(
58 "AES only defines key lengths of 128, 192 and 256. A key length of {key_length} is unsupported!"
59 )]
60 InvalidKeyLengthAes {
61 key_length: u32,
63 },
64
65 #[error(
67 "RSA keys shorter than {MIN_RSA_BIT_LENGTH} are not supported. A key length of {key_length} is unsafe!"
68 )]
69 InvalidKeyLengthRsa {
70 key_length: u32,
72 },
73
74 #[error("The key type {key_type} is not compatible with signature type: {signature_type}")]
76 InvalidKeyTypeForSignatureType {
77 key_type: KeyType,
79 signature_type: SignatureType,
81 },
82
83 #[error(
85 "The key mechanism {required_key_mechanism} must be used with signature type {signature_type}"
86 )]
87 InvalidKeyMechanismsForSignatureType {
88 required_key_mechanism: KeyMechanism,
90 signature_type: SignatureType,
92 },
93
94 #[error(
96 "The key type {key_type}, key mechanisms {key_mechanisms:?} and signature type {signature_type} are incompatible with raw cryptographic signing"
97 )]
98 InvalidRawSigningKeySetup {
99 key_type: KeyType,
101 key_mechanisms: Vec<KeyMechanism>,
103 signature_type: SignatureType,
105 },
106
107 #[error(
109 "The key type {key_type}, key mechanisms {key_mechanisms:?} and signature type {signature_type} are incompatible with OpenPGP signing"
110 )]
111 InvalidOpenPgpSigningKeySetup {
112 key_type: KeyType,
114 key_mechanisms: Vec<KeyMechanism>,
116 signature_type: SignatureType,
118 },
119}