tor_keymgr/keystore/arti/
err.rs1use crate::keystore::fs_utils::FilesystemError;
4use crate::raw::RawEntryId;
5use crate::{ArtiPathSyntaxError, KeystoreError, UnknownKeyTypeError};
6use tor_error::{ErrorKind, HasKind};
7use tor_key_forge::{CertType, KeyType, SshKeyAlgorithm};
8
9use std::path::PathBuf;
10use std::sync::Arc;
11
12#[derive(thiserror::Error, Debug, Clone)]
15pub(crate) enum ArtiNativeKeystoreError {
16 #[error("{0}")]
18 Filesystem(#[from] FilesystemError),
19
20 #[error("Key has invalid path: {path}")]
22 MalformedPath {
23 path: PathBuf,
25 #[source]
27 err: MalformedPathError,
28 },
29
30 #[error("{0}")]
32 UnknownKeyType(#[from] UnknownKeyTypeError),
33
34 #[error("Failed to parse OpenSSH with type {key_type:?}")]
36 SshKeyParse {
37 path: PathBuf,
39 key_type: KeyType,
41 #[source]
43 err: Arc<ssh_key::Error>,
44 },
45
46 #[error("Unexpected OpenSSH key type: wanted {wanted_key_algo}, found {found_key_algo}")]
48 UnexpectedSshKeyType {
49 path: PathBuf,
51 wanted_key_algo: SshKeyAlgorithm,
53 found_key_algo: SshKeyAlgorithm,
55 },
56
57 #[error("Failed to parse cert with type {cert_type:?}")]
59 CertParse {
60 path: PathBuf,
62 cert_type: CertType,
64 #[source]
66 err: tor_bytes::Error,
67 },
68
69 #[error("Raw entry {:?} not supported in an Arti keystore", _0)]
71 UnsupportedRawEntry(RawEntryId),
72
73 #[error("Internal error")]
75 Bug(#[from] tor_error::Bug),
76}
77
78#[derive(thiserror::Error, Debug, Clone)]
85pub(crate) enum MalformedPathError {
86 #[error("the path is not valid UTF-8")]
88 Utf8,
89
90 #[error("no extension")]
92 NoExtension,
93
94 #[error("not a valid ArtiPath")]
96 InvalidArtiPath(ArtiPathSyntaxError),
97}
98
99impl KeystoreError for ArtiNativeKeystoreError {}
100
101impl HasKind for ArtiNativeKeystoreError {
102 fn kind(&self) -> ErrorKind {
103 use ArtiNativeKeystoreError as KE;
104
105 match self {
106 KE::Filesystem(e) => e.kind(),
107 KE::MalformedPath { .. } => ErrorKind::KeystoreAccessFailed,
108 KE::UnknownKeyType(_) => ErrorKind::KeystoreAccessFailed,
109 KE::SshKeyParse { .. } | KE::UnexpectedSshKeyType { .. } | KE::CertParse { .. } => {
110 ErrorKind::KeystoreCorrupted
111 }
112 KE::UnsupportedRawEntry { .. } => ErrorKind::BadApiUsage,
113 KE::Bug(e) => e.kind(),
114 }
115 }
116}
117
118impl From<ArtiNativeKeystoreError> for crate::Error {
119 fn from(e: ArtiNativeKeystoreError) -> Self {
120 crate::Error::Keystore(Arc::new(e))
121 }
122}