tor_keymgr/keystore/ephemeral/
err.rs

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