-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathlib.rs
More file actions
92 lines (81 loc) · 2.68 KB
/
lib.rs
File metadata and controls
92 lines (81 loc) · 2.68 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
use anyhow::anyhow;
use std::{fmt, panic::Location};
pub mod client;
pub mod consts;
#[cfg(feature = "non-wasm")]
pub mod util {
pub mod file_handling;
pub mod key_setup;
pub mod meta_store;
#[cfg(any(test, feature = "testing", feature = "insecure"))]
pub mod random_free_port;
pub mod rate_limiter;
pub mod retry;
}
#[cfg(feature = "non-wasm")]
pub mod backup;
#[cfg(feature = "non-wasm")]
pub mod conf;
pub mod cryptography;
pub mod engine;
#[cfg(feature = "non-wasm")]
pub mod grpc;
/// Consolidated testing infrastructure
///
/// This module provides a unified API for writing isolated tests.
/// Import the prelude in your test files:
///
/// ```
/// use kms_lib::testing::prelude::*;
/// ```
#[cfg(all(feature = "non-wasm", any(test, feature = "testing")))]
pub mod testing;
#[cfg(feature = "non-wasm")]
pub mod vault;
#[cfg(feature = "heap-profiling")]
pub mod heap_profiling;
#[cfg(feature = "non-wasm")]
pub use kms_grpc::utils::tonic_result::BoxedStatus;
/// Truncate s to a maximum of 128 chars.
pub(crate) fn top_n_chars(mut s: String) -> String {
s.truncate(128);
s
}
/// Helper method for returning the optional value of `input` if it exists, otherwise
/// returning a custom anyhow error.
pub fn some_or_err<T>(input: Option<T>, error: String) -> anyhow::Result<T> {
input.ok_or_else(|| {
tracing::warn!(error);
anyhow!("Missing value: {}", top_n_chars(error.to_string()))
})
}
// NOTE: the below is copied from core/threshold
// since the calling tracing from another crate
// does not generate correct logs in tracing_test::traced_test
#[track_caller]
pub(crate) fn anyhow_error_and_log<S: AsRef<str> + fmt::Display>(msg: S) -> anyhow::Error {
tracing::error!("Error in {}: {}", Location::caller(), msg);
anyhow_tracked(msg)
}
#[track_caller]
pub(crate) fn anyhow_tracked<S: AsRef<str> + fmt::Display>(msg: S) -> anyhow::Error {
anyhow!("Error in {}: {}", Location::caller(), msg)
}
#[cfg(feature = "non-wasm")]
#[track_caller]
pub(crate) fn anyhow_error_and_warn_log<S: AsRef<str> + fmt::Display>(msg: S) -> anyhow::Error {
tracing::warn!("Warning in {}: {}", Location::caller(), msg);
anyhow!("Warning in {}: {}", Location::caller(), msg)
}
/// Create a dummy domain for testing
#[cfg(any(test, all(feature = "non-wasm", feature = "testing")))]
pub(crate) fn dummy_domain() -> alloy_sol_types::Eip712Domain {
alloy_sol_types::eip712_domain!(
name: "Authorization token",
version: "1",
chain_id: 8006,
verifying_contract: alloy_primitives::address!("66f9664f97F2b50F62D13eA064982f936dE76657"),
)
}
// re-export DecryptionMode
pub use threshold_fhe::execution::endpoints::decryption::DecryptionMode;