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}")]
25 MalformedPath {
26 path: PathBuf,
28 #[source]
30 err: MalformedPathError,
31 },
32
33 #[error("{0}")]
35 UnknownKeyType(#[from] UnknownKeyTypeError),
36
37 #[error("Failed to parse OpenSSH with type {key_type:?}")]
39 SshKeyParse {
40 path: PathBuf,
42 key_type: KeyType,
44 #[source]
46 err: Arc<ssh_key::Error>,
47 },
48
49 #[error("Unexpected OpenSSH key type: wanted {wanted_key_algo}, found {found_key_algo}")]
51 UnexpectedSshKeyType {
52 path: PathBuf,
54 wanted_key_algo: SshKeyAlgorithm,
56 found_key_algo: SshKeyAlgorithm,
58 },
59
60 #[error("Failed to parse cert with type {cert_type:?}")]
62 CertParse {
63 path: PathBuf,
65 cert_type: CertType,
67 #[source]
69 err: tor_bytes::Error,
70 },
71
72 #[error("Raw entry {:?} not supported in an Arti keystore", _0)]
74 UnsupportedRawEntry(RawEntryId),
75
76 #[error("Internal error")]
78 Bug(#[from] tor_error::Bug),
79}
80
81#[derive(thiserror::Error, Debug, Clone)]
88pub(crate) enum MalformedPathError {
89 #[error("the path is not valid UTF-8")]
91 Utf8,
92
93 #[error("no extension")]
95 NoExtension,
96
97 #[error("not a valid ArtiPath")]
99 InvalidArtiPath(ArtiPathSyntaxError),
100}
101
102impl KeystoreError for ArtiNativeKeystoreError {}
103
104impl HasKind for ArtiNativeKeystoreError {
105 fn kind(&self) -> ErrorKind {
106 use ArtiNativeKeystoreError as KE;
107
108 match self {
109 KE::Filesystem(e) => e.kind(),
110 KE::MalformedPath { .. } => ErrorKind::KeystoreAccessFailed,
111 KE::UnknownKeyType(_) => ErrorKind::KeystoreAccessFailed,
112 KE::SshKeyParse { .. } | KE::UnexpectedSshKeyType { .. } | KE::CertParse { .. } => {
113 ErrorKind::KeystoreCorrupted
114 }
115 KE::UnsupportedRawEntry { .. } => ErrorKind::BadApiUsage,
116 KE::Bug(e) => e.kind(),
117 }
118 }
119}
120
121impl From<ArtiNativeKeystoreError> for crate::Error {
122 fn from(e: ArtiNativeKeystoreError) -> Self {
123 crate::Error::Keystore(Arc::new(e))
124 }
125}