tor_keymgr/raw.rs
1//! Raw keystore entry identifiers used in plumbing CLI functionalities.
2
3use std::path::PathBuf;
4
5use tor_basic_utils::PathExt;
6use tor_key_forge::KeystoreItemType;
7
8use crate::ArtiPath;
9
10/// The raw identifier of a key inside a [`Keystore`](crate::Keystore).
11///
12/// The exact type of the identifier depends on the backing storage of the keystore
13/// (for example, an on-disk keystore will identify its entries by [`Path`](RawEntryId::Path)).
14#[cfg_attr(
15 any(feature = "onion-service-cli-extra", feature = "experimental-api"),
16 visibility::make(pub)
17)]
18#[non_exhaustive]
19#[derive(Debug, Clone, PartialEq, derive_more::Display)]
20pub(crate) enum RawEntryId {
21 /// An entry identified by path inside an on-disk keystore.
22 // NOTE: this will only be used by on-disk keystores like
23 // [`ArtiNativeKeystore`](crate::ArtiNativeKeystore)
24 #[display("{}", _0.display_lossy())]
25 Path(PathBuf),
26
27 /// An entry of an in-memory ephemeral key storage
28 /// [`ArtiEphemeralKeystore`](crate::ArtiEphemeralKeystore)
29 ///
30 // TODO: the concept of a "raw identifier" doesn't really make sense
31 // in the context of the `ArtiEphemeralKeystore`,
32 // which is why this "raw" identifier is of exactly the same type
33 // (`(ArtiPath, KeystoreItemType)`) as its non-"raw" counterpart.
34 // Ephemeral keystores are just in-memory key-value mappings;
35 // unlike file system-based keystores, these don't have entries with "raw"
36 // identifiers that need to be validated and parsed before they can be used.
37 //
38 // We might want to remove this variant entirely,
39 // and make `RawEntryId` optional in e.g. `KeystoreEntry`.
40 #[display("{} {:?}", _0.0, _0.1)]
41 Ephemeral((ArtiPath, KeystoreItemType)),
42 // TODO: when/if we add support for non on-disk keystores,
43 // new variants will be added
44}