blob: bf7a966e6056f5b2c70ebc8f6c1aad509ec981a1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
//! An error type for [`ArtiEphemeralKeystore`](crate::ArtiEphemeralKeystore).
use std::sync::Arc;
use tor_error::{ErrorKind, HasKind};
use crate::KeystoreError;
/// An error returned by [`ArtiEphemeralKeystore`](crate::ArtiEphemeralKeystore)'s
/// [`Keystore`](crate::Keystore) implementation.
#[derive(thiserror::Error, Debug, Clone)]
pub(crate) enum ArtiEphemeralKeystoreError {
/// An error that occurred building an ArtiPath from a KeySpecifier
#[error("unable to build ArtiPath from KeySpecifier")]
ArtiPathUnavailableError(#[from] crate::key_specifier::ArtiPathUnavailableError),
/// An error that occurred serializing a key to OpenSSH text format
#[error("{0}")]
SshKeySerialize(#[from] ssh_key::Error),
/// An unsupported operation.
#[error("Operation not supported: {action}")]
NotSupported {
/// The action we were trying to perform.
action: &'static str,
},
}
impl KeystoreError for ArtiEphemeralKeystoreError {}
impl HasKind for ArtiEphemeralKeystoreError {
fn kind(&self) -> ErrorKind {
match self {
// TODO: These could probably use more specific ErrorKinds. They
// are explicitly matched instead of using a default match to
// encourage future additions to use the appropriate ErrorKind
// rather than letting the default match handle it.
Self::ArtiPathUnavailableError(_) => ErrorKind::Other,
Self::SshKeySerialize(_) => ErrorKind::Other,
Self::NotSupported { .. } => ErrorKind::BadApiUsage,
}
}
}
impl From<ArtiEphemeralKeystoreError> for crate::Error {
fn from(e: ArtiEphemeralKeystoreError) -> Self {
crate::Error::Keystore(Arc::new(e))
}
}
|