pub struct SodiumAllocator;Expand description
An Allocator which allocates and frees memory using Sodium’s secure
memory utilities.
Allocation of memory using this struct is expensive - it shouldn’t be used as a global allocator, but rather confied to manage memory for data structures storing sensitive information, such as keys, passwords, etc.
When this Allocator frees memory, it is securely zeroed, so there is no need to implement Zeroize or similar constructions for types with memory managed via this struct.
If the canary Sodium places before the allocated memory is altered, or if an attempt to access a guard page surrounding the allocated memory is made, the program will automatically terminate. This behaviour should never occur in safe Rust.
Trait Implementations§
Source§impl Allocator for SodiumAllocator
impl Allocator for SodiumAllocator
Source§fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
🔬This is a nightly-only experimental API. (
allocator_api)Attempts to allocate a block of memory. Read more
Source§unsafe fn deallocate(&self, ptr: NonNull<u8>, _layout: Layout)
unsafe fn deallocate(&self, ptr: NonNull<u8>, _layout: Layout)
🔬This is a nightly-only experimental API. (
allocator_api)Deallocates the memory referenced by
ptr. Read moreSource§fn allocate_zeroed(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
fn allocate_zeroed(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
🔬This is a nightly-only experimental API. (
allocator_api)Behaves like
allocate, but also ensures that the returned memory is zero-initialized. Read moreSource§unsafe fn grow(
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout,
) -> Result<NonNull<[u8]>, AllocError>
unsafe fn grow( &self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout, ) -> Result<NonNull<[u8]>, AllocError>
🔬This is a nightly-only experimental API. (
allocator_api)Attempts to extend the memory block. Read more
Source§unsafe fn grow_zeroed(
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout,
) -> Result<NonNull<[u8]>, AllocError>
unsafe fn grow_zeroed( &self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout, ) -> Result<NonNull<[u8]>, AllocError>
🔬This is a nightly-only experimental API. (
allocator_api)Behaves like
grow, but also ensures that the new contents are set to zero before being
returned. Read moreSource§impl Clone for SodiumAllocator
impl Clone for SodiumAllocator
Source§fn clone(&self) -> SodiumAllocator
fn clone(&self) -> SodiumAllocator
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for SodiumAllocator
impl Debug for SodiumAllocator
impl Copy for SodiumAllocator
Auto Trait Implementations§
impl Freeze for SodiumAllocator
impl RefUnwindSafe for SodiumAllocator
impl Send for SodiumAllocator
impl Sync for SodiumAllocator
impl Unpin for SodiumAllocator
impl UnwindSafe for SodiumAllocator
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more