SodiumMemory
struct SodiumMemory
A wrapper for handling secure memory allocations.
-
The initializer is disabled.
Declaration
Swift
fileprivate init() -
Allocates a guarded memory region of a given size.
Precondition
0 ≤
sizeInBytesDeclaration
Swift
func allocate(sizeInBytes: Int) -> UnsafeMutableRawPointerParameters
sizeInBytesThe size of the allocated memory.
Return Value
A pointer to the guarded memory region.
-
Frees a guarded memory region.
Declaration
Swift
func free(_ pointer: UnsafeMutableRawPointer)Parameters
pointerA pointer to the guarded memory region.
-
Wipes a guarded memory region by overwriting it with zeroes.
Precondition
0 ≤
amountInBytesDeclaration
Swift
func wipe(_ pointer: UnsafeMutableRawPointer, amountInBytes: Int)Parameters
pointerA pointer to the guarded memory region.
amountInBytesThe amount of bytes that should be zeroed, starting at the beginning of the memory region.
-
Wipes a byte array by overwriting it with zeroes.
Declaration
Swift
func wipe(_ bytes: inout Bytes)Parameters
bytesA byte array.
-
Compares two guarded memory regions in constant time.
Precondition
0 ≤
amountInBytesDeclaration
Swift
func areEqual(_ lhs: UnsafeRawPointer, _ rhs: UnsafeRawPointer, amountInBytes: Int) -> BoolParameters
lhsA pointer to the guarded memory region.
rhsA pointer to the guarded memory region.
amountInBytesThe amount of bytes that should be compared, starting at the beginning of the memory region.
Return Value
trueif both regions are equal up toamountInBytes. -
Makes a guarded memory region read-only.
Declaration
Swift
func make_readonly(_ pointer: UnsafeMutableRawPointer)Parameters
pointerA pointer to the guarded memory region.
-
Makes a guarded memory region read-writable.
Declaration
Swift
func make_readwritable(_ pointer: UnsafeMutableRawPointer)Parameters
pointerA pointer to the guarded memory region.
-
Makes a guarded memory region inaccessible.
Declaration
Swift
func make_inaccessible(_ pointer: UnsafeMutableRawPointer)Parameters
pointerA pointer to the guarded memory region.
View on GitHub
SodiumMemory Structure Reference