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 ≤ sizeInBytes

    Declaration

    Swift

    func allocate(sizeInBytes: Int) -> UnsafeMutableRawPointer

    Parameters

    sizeInBytes

    The 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

    pointer

    A pointer to the guarded memory region.

  • Wipes a guarded memory region by overwriting it with zeroes.

    Precondition

    0 ≤ amountInBytes

    Declaration

    Swift

    func wipe(_ pointer: UnsafeMutableRawPointer, amountInBytes: Int)

    Parameters

    pointer

    A pointer to the guarded memory region.

    amountInBytes

    The 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

    bytes

    A byte array.

  • Compares two guarded memory regions in constant time.

    Precondition

    0 ≤ amountInBytes

    Declaration

    Swift

    func areEqual(_ lhs: UnsafeRawPointer, _ rhs: UnsafeRawPointer, amountInBytes: Int) -> Bool

    Parameters

    lhs

    A pointer to the guarded memory region.

    rhs

    A pointer to the guarded memory region.

    amountInBytes

    The amount of bytes that should be compared, starting at the beginning of the memory region.

    Return Value

    true if both regions are equal up to amountInBytes.

  • Makes a guarded memory region read-only.

    Declaration

    Swift

    func make_readonly(_ pointer: UnsafeMutableRawPointer)

    Parameters

    pointer

    A pointer to the guarded memory region.

  • Makes a guarded memory region read-writable.

    Declaration

    Swift

    func make_readwritable(_ pointer: UnsafeMutableRawPointer)

    Parameters

    pointer

    A pointer to the guarded memory region.

  • Makes a guarded memory region inaccessible.

    Declaration

    Swift

    func make_inaccessible(_ pointer: UnsafeMutableRawPointer)

    Parameters

    pointer

    A pointer to the guarded memory region.