Skip to main content

hardware_enclave/
shell.rs

1// Copyright 2026 Jay Gowdy
2// SPDX-License-Identifier: MIT
3
4//! Shell config block injection and path/value quoting.
5//!
6//! [`BlockMarkers`] + the `install_block_in_file` / `remove_block_from_file`
7//! functions handle adding and removing managed blocks from `.bashrc`,
8//! `.zshrc`, SSH config, and similar files.
9//!
10//! The quoting functions produce correctly-escaped strings for embedding
11//! paths and values into config files.
12
13// Config block management
14pub use crate::internal::core::config_block::{
15    build_block, find_block, has_block, install_block_in_file, read_config_file, remove_block,
16    remove_block_from_file, upsert_block, write_config_file, BlockInstallResult, BlockMarkers,
17    BlockRemoveResult,
18};
19
20// Path and value quoting for config files
21pub use crate::internal::core::quoting::quote_config_value;
22
23/// Quote a filesystem path for embedding in an **SSH-style config file**.
24///
25/// On Windows, backslashes are converted to forward slashes — this is required
26/// by OpenSSH's config parser and by Git credential helper entries, which also
27/// use the same forward-slash convention.
28///
29/// Paths containing spaces are wrapped in double quotes.
30///
31/// # ⚠ Not suitable for all config formats
32///
33/// This function normalises Windows backslashes to forward slashes. Do **not**
34/// use it for formats that require backslash-escaped paths (e.g. the AWS
35/// `credential_process` INI directive). Use [`quote_credential_process_arg`]
36/// for those.
37///
38/// # Usage
39///
40/// ```
41/// use hardware_enclave::shell::quote_path_for_ssh_config;
42/// use std::path::Path;
43///
44/// let line = format!("IdentityFile {}", quote_path_for_ssh_config(Path::new("/home/user/.ssh/id")));
45/// ```
46pub fn quote_path_for_ssh_config(path: &std::path::Path) -> String {
47    crate::internal::core::quoting::quote_ssh_path(path)
48}
49
50/// Quote a path for the `credential_process` directive in AWS config.
51///
52/// Uses INI-style escaping (`\"` and `\\`) rather than forward-slash
53/// normalisation. Use this for AWS `~/.aws/credentials` or `~/.aws/config`
54/// entries. For SSH config paths use [`quote_path_for_ssh_config`] instead.
55pub use crate::internal::core::quoting::quote_credential_process_arg;