secmem_proc/harden.rs
1//! This module defines the `harden_process` function which performs all
2//! possible hardening steps available for the platform.
3
4use crate::config::Config;
5use crate::error::Result;
6
7/// Performs all possible stable hardening steps for the platform. This uses the
8/// default configuration, so unstable hardening methods are disabled regardless
9/// of the `unstable` crate feature.
10///
11/// # Errors
12/// Returns an error when one of the available hardening steps error due to a
13/// system or libc interface returning an error. In case of error it is
14/// recommended to issue an error and shut down the application without loading
15/// secrets into memory.
16pub fn harden_process() -> Result {
17 const CONF: Config = Config::DEFAULT;
18 CONF.harden_process()
19}
20
21#[cfg(test)]
22mod tests {
23 use super::harden_process;
24
25 #[test]
26 fn test_harden_process() {
27 assert!(harden_process().is_ok());
28 }
29
30 #[test]
31 #[cfg(feature = "std")]
32 fn comptest_hardenerror_impl_error() {
33 fn take_error<E: std::error::Error>(_e: E) {}
34
35 let _ = harden_process().map_err(|e| take_error(e));
36 }
37}