pub struct Secret { /* private fields */ }Expand description
Secret is somewhat like a Vec
NOTE: This requires a fairly recent kernel (5.14+), with CONFIG_SECRETMEM enabled. Currently there is no fallback implementation, so if requirements aren’t met, then constructing Secrets will simply return an error.
NOTE: Memory allocated this way does count towards RLIMIT_MEMLOCK. In modern kernels this defaults to 8 MiB, but it may perhaps need to be increased depending on how you’re using this.
Implementations§
Source§impl Secret
impl Secret
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new Secret buffer, initially with length zero. Before the buffer can be meaningfully used, resize will have to be called.
Sourcepub fn with_len(len: usize) -> Result<Self>
pub fn with_len(len: usize) -> Result<Self>
Create a new Secret buffer with the given initial length. The given initial length can be zero.
Sourcepub fn resize(&mut self, len: usize) -> Result<()>
pub fn resize(&mut self, len: usize) -> Result<()>
Resize the buffer’s length in bytes. If the new length is smaller, the existing data is truncated. If the new length is larger, the new bytes will be zeros.
Sourcepub unsafe fn slice_ptr(&self) -> *mut u8
pub unsafe fn slice_ptr(&self) -> *mut u8
Returns a pointer to this Secret’s underlying memory. The returned pointer is guaranteed to be suitable for constructing a slice, even if this Secret is empty. This pointer is guaranteed to be non-NULL.
Sourcepub unsafe fn as_slice(&self) -> &[u8] ⓘ
pub unsafe fn as_slice(&self) -> &[u8] ⓘ
Access the underlying secret data. This function is unsafe primarily because you’re touching secrets that shouldn’t be exposed, so be very careful what you do with the data!
Sourcepub unsafe fn as_mut_slice(&mut self) -> &mut [u8] ⓘ
pub unsafe fn as_mut_slice(&mut self) -> &mut [u8] ⓘ
Mutably access the underlying secret data. This function is unsafe primarily because you’re touching secrets that shouldn’t be exposed, so be very careful what you do with the data!