1
#![cfg_attr(docsrs, feature(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_time_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
#![allow(clippy::collapsible_if)] // See arti#2342
46
#![deny(clippy::unused_async)]
47
//! <!-- @@ end lint list maintained by maint/add_warning @@ -->
48

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

            
52
// TODO: write more comprehensive documentation when the API is a bit more
53
// stable
54

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

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

            
68
#[cfg(not(feature = "keymgr"))]
69
mod dummy;
70

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

            
85
#[cfg(feature = "experimental-api")]
86
pub use key_specifier::CertSpecifierPattern;
87

            
88
#[cfg(feature = "keymgr")]
89
pub use {
90
    keystore::arti::ArtiNativeKeystore,
91
    keystore::{Keystore, KeystoreEntryResult},
92
    mgr::{KeyMgr, KeyMgrBuilder, KeyMgrBuilderError, KeystoreEntry},
93
    ssh_key,
94
};
95

            
96
#[cfg(all(feature = "keymgr", feature = "ephemeral-keystore"))]
97
pub use keystore::ephemeral::ArtiEphemeralKeystore;
98

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

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

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

            
110
derive_deftly::template_export_semver_check! { "0.12.1" }
111

            
112
#[cfg(not(feature = "keymgr"))]
113
pub use dummy::*;
114

            
115
/// A boxed [`Keystore`].
116
pub(crate) type BoxedKeystore = Box<dyn Keystore>;
117

            
118
#[doc(hidden)]
119
pub use {derive_deftly, inventory};
120

            
121
use derive_more::{AsRef, Display, From};
122
use serde::{Deserialize, Serialize};
123
use std::str::FromStr;
124

            
125
/// A Result type for this crate.
126
pub type Result<T> = std::result::Result<T, Error>;
127

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

            
138
impl FromStr for KeystoreId {
139
    type Err = Error;
140

            
141
4712
    fn from_str(s: &str) -> Result<Self> {
142
4712
        Ok(Self(s.into()))
143
4712
    }
144
}
145

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