secure_gate/traits/
expose_secret_mut.rs

1//! # Mutable Secret Exposure Traits
2//!
3//! This module defines the trait for mutable access to secrets.
4//!
5//! ## Key Traits
6//!
7//! - [`ExposeSecretMut`]: Mutable access to secret values
8//!
9/// ## Usage
10///
11/// Import this trait to enable `.expose_secret_mut()` on mutable secret wrappers.
12use super::ExposeSecret;
13use crate::{Dynamic, Fixed};
14
15/// Trait for mutable access to secrets.
16///
17/// Extends [`ExposeSecret`], so metadata and read access are included.
18/// Import this for `.expose_secret_mut()`.
19pub trait ExposeSecretMut: ExposeSecret {
20    /// Expose the secret for mutable access.
21    fn expose_secret_mut(&mut self) -> &mut Self::Inner;
22}
23
24// ============================================================================
25// Core Wrapper Implementations
26// ============================================================================
27
28/// Implementation for [`Fixed<[T; N]>`] - provides mutable access for arrays.
29///
30/// Extends the read-only implementation with mutation capabilities.
31impl<const N: usize, T> ExposeSecretMut for Fixed<[T; N]> {
32    #[inline(always)]
33    fn expose_secret_mut(&mut self) -> &mut [T; N] {
34        &mut self.0
35    }
36}
37
38/// Implementation for [`Dynamic<String>`] - provides mutable access.
39///
40/// Extends the read-only implementation with mutation capabilities.
41impl ExposeSecretMut for Dynamic<String> {
42    #[inline(always)]
43    fn expose_secret_mut(&mut self) -> &mut String {
44        &mut self.0
45    }
46}
47
48/// Implementation for [`Dynamic<Vec<T>>`] - provides mutable access.
49///
50/// Extends the read-only implementation with mutation capabilities.
51impl<T> ExposeSecretMut for Dynamic<Vec<T>> {
52    #[inline(always)]
53    fn expose_secret_mut(&mut self) -> &mut Vec<T> {
54        &mut self.0
55    }
56}
57
58/// Implementation for [`Fixed<CloneableArrayInner<N>>`] - provides mutable access.
59#[cfg(feature = "zeroize")]
60impl<const N: usize> ExposeSecretMut
61    for crate::Fixed<crate::cloneable::array::CloneableArrayInner<N>>
62{
63    #[inline(always)]
64    fn expose_secret_mut(&mut self) -> &mut crate::cloneable::array::CloneableArrayInner<N> {
65        &mut self.0
66    }
67}
68
69/// Implementation for [`Dynamic<CloneableStringInner>`] - provides mutable access.
70#[cfg(feature = "zeroize")]
71impl ExposeSecretMut for crate::Dynamic<crate::cloneable::string::CloneableStringInner> {
72    #[inline(always)]
73    fn expose_secret_mut(&mut self) -> &mut crate::cloneable::string::CloneableStringInner {
74        &mut self.0
75    }
76}
77
78/// Implementation for [`Dynamic<CloneableVecInner>`] - provides mutable access.
79#[cfg(feature = "zeroize")]
80impl ExposeSecretMut for crate::Dynamic<crate::cloneable::vec::CloneableVecInner> {
81    #[inline(always)]
82    fn expose_secret_mut(&mut self) -> &mut crate::cloneable::vec::CloneableVecInner {
83        &mut self.0
84    }
85}
86
87// ============================================================================
88// Specific Implementations for Test Types
89// ============================================================================
90
91/// Implementation for [`Fixed<u32>`] - provides mutable access.
92impl ExposeSecretMut for Fixed<u32> {
93    #[inline(always)]
94    fn expose_secret_mut(&mut self) -> &mut u32 {
95        &mut self.0
96    }
97}