1
#![cfg_attr(docsrs, feature(doc_auto_cfg, doc_cfg))]
2
#![doc = include_str!("../README.md")]
3
// @@ begin lint list maintained by maint/add_warning @@
4
#![allow(renamed_and_removed_lints)] // @@REMOVE_WHEN(ci_arti_stable)
5
#![allow(unknown_lints)] // @@REMOVE_WHEN(ci_arti_nightly)
6
#![warn(missing_docs)]
7
#![warn(noop_method_call)]
8
#![warn(unreachable_pub)]
9
#![warn(clippy::all)]
10
#![deny(clippy::await_holding_lock)]
11
#![deny(clippy::cargo_common_metadata)]
12
#![deny(clippy::cast_lossless)]
13
#![deny(clippy::checked_conversions)]
14
#![warn(clippy::cognitive_complexity)]
15
#![deny(clippy::debug_assert_with_mut_call)]
16
#![deny(clippy::exhaustive_enums)]
17
#![deny(clippy::exhaustive_structs)]
18
#![deny(clippy::expl_impl_clone_on_copy)]
19
#![deny(clippy::fallible_impl_from)]
20
#![deny(clippy::implicit_clone)]
21
#![deny(clippy::large_stack_arrays)]
22
#![warn(clippy::manual_ok_or)]
23
#![deny(clippy::missing_docs_in_private_items)]
24
#![warn(clippy::needless_borrow)]
25
#![warn(clippy::needless_pass_by_value)]
26
#![warn(clippy::option_option)]
27
#![deny(clippy::print_stderr)]
28
#![deny(clippy::print_stdout)]
29
#![warn(clippy::rc_buffer)]
30
#![deny(clippy::ref_option_ref)]
31
#![warn(clippy::semicolon_if_nothing_returned)]
32
#![warn(clippy::trait_duplication_in_bounds)]
33
#![deny(clippy::unchecked_duration_subtraction)]
34
#![deny(clippy::unnecessary_wraps)]
35
#![warn(clippy::unseparated_literal_suffix)]
36
#![deny(clippy::unwrap_used)]
37
#![deny(clippy::mod_module_files)]
38
#![allow(clippy::let_unit_value)] // This can reasonably be done for explicitness
39
#![allow(clippy::uninlined_format_args)]
40
#![allow(clippy::significant_drop_in_scrutinee)] // arti/-/merge_requests/588/#note_2812945
41
#![allow(clippy::result_large_err)] // temporary workaround for arti#587
42
#![allow(clippy::needless_raw_string_hashes)] // complained-about code is fine, often best
43
#![allow(clippy::needless_lifetimes)] // See arti#1765
44
#![allow(mismatched_lifetime_syntaxes)] // temporary workaround for arti#2060
45
//! <!-- @@ end lint list maintained by maint/add_warning @@ -->
46

            
47
// TODO #1645 (either remove this, or decide to have it everywhere)
48
#![cfg_attr(not(all(feature = "full", feature = "experimental")), allow(unused))]
49

            
50
// TODO: write more comprehensive documentation when the API is a bit more
51
// stable
52

            
53
mod arti_path;
54
pub mod config;
55
mod err;
56
mod key_specifier;
57
pub(crate) mod raw;
58
#[cfg(any(test, feature = "testing"))]
59
pub mod test_utils;
60

            
61
#[cfg(feature = "keymgr")]
62
mod keystore;
63
#[cfg(feature = "keymgr")]
64
mod mgr;
65

            
66
#[cfg(not(feature = "keymgr"))]
67
mod dummy;
68

            
69
pub use arti_path::{ArtiPath, DENOTATOR_SEP};
70
pub use err::{
71
    ArtiPathSyntaxError, Error, KeystoreCorruptionError, KeystoreError, UnknownKeyTypeError,
72
    UnrecognizedEntry, UnrecognizedEntryError,
73
};
74
pub use key_specifier::{
75
    ArtiPathRange, ArtiPathUnavailableError, CTorPath, CTorServicePath,
76
    InvalidKeyPathComponentValue, KeyCertificateSpecifier, KeyPath, KeyPathError, KeyPathInfo,
77
    KeyPathInfoBuilder, KeyPathInfoExtractor, KeyPathPattern, KeySpecifier, KeySpecifierComponent,
78
    KeySpecifierComponentViaDisplayFromStr, KeySpecifierPattern,
79
};
80
#[cfg(feature = "onion-service-cli-extra")]
81
#[cfg_attr(docsrs, doc(cfg(feature = "onion-service-cli-extra")))]
82
pub use raw::{RawEntryId, RawKeystoreEntry};
83

            
84
#[cfg(feature = "keymgr")]
85
#[cfg_attr(docsrs, doc(cfg(feature = "keymgr")))]
86
pub use {
87
    keystore::arti::ArtiNativeKeystore,
88
    keystore::{Keystore, KeystoreEntryResult},
89
    mgr::{KeyMgr, KeyMgrBuilder, KeyMgrBuilderError, KeystoreEntry},
90
    ssh_key,
91
};
92

            
93
#[cfg(all(feature = "keymgr", feature = "ephemeral-keystore"))]
94
#[cfg_attr(
95
    docsrs,
96
    doc(cfg(all(feature = "keymgr", feature = "ephemeral-keystore")))
97
)]
98
pub use keystore::ephemeral::ArtiEphemeralKeystore;
99

            
100
#[cfg(all(feature = "keymgr", feature = "ctor-keystore"))]
101
#[cfg_attr(docsrs, doc(cfg(all(feature = "keymgr", feature = "ctor-keystore"))))]
102
pub use keystore::ctor::{CTorClientKeystore, CTorServiceKeystore};
103

            
104
#[doc(hidden)]
105
pub use key_specifier::derive as key_specifier_derive;
106

            
107
pub use tor_key_forge::{
108
    EncodableItem, ErasedKey, KeyType, Keygen, KeygenRng, SshKeyAlgorithm, SshKeyData,
109
    ToEncodableKey,
110
};
111

            
112
derive_deftly::template_export_semver_check! { "0.12.1" }
113

            
114
#[cfg(not(feature = "keymgr"))]
115
#[cfg_attr(docsrs, doc(cfg(not(feature = "keymgr"))))]
116
pub use dummy::*;
117

            
118
/// A boxed [`Keystore`].
119
pub(crate) type BoxedKeystore = Box<dyn Keystore>;
120

            
121
#[doc(hidden)]
122
pub use {derive_deftly, inventory};
123

            
124
use derive_more::{AsRef, Display, From};
125
use serde::{Deserialize, Serialize};
126
use std::str::FromStr;
127

            
128
/// A Result type for this crate.
129
pub type Result<T> = std::result::Result<T, Error>;
130

            
131
/// An identifier for a particular [`Keystore`] instance.
132
//
133
// TODO (#1193): restrict the charset of this ID
134
#[derive(
135
    Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize, Display, AsRef,
136
)]
137
#[serde(transparent)]
138
#[non_exhaustive]
139
pub struct KeystoreId(String);
140

            
141
impl FromStr for KeystoreId {
142
    type Err = Error;
143

            
144
970
    fn from_str(s: &str) -> Result<Self> {
145
970
        Ok(Self(s.into()))
146
970
    }
147
}
148

            
149
/// Specifies which keystores a [`KeyMgr`] operation should apply to.
150
#[derive(Copy, Clone, Default, Debug, PartialEq, Eq, Hash, From)]
151
#[non_exhaustive]
152
pub enum KeystoreSelector<'a> {
153
    /// Try to use the keystore with the specified ID.
154
    Id(&'a KeystoreId),
155
    /// Use the primary key store.
156
    #[default]
157
    Primary,
158
}