memoryProtection property

MemoryProtection get memoryProtection

Controls the memory protection level of the allocated memory

This provides convenient access to sodium_mprotect_noaccess, sodium_mprotect_readonly and sodium_mprotect_readwrite via a single property. All SodiumPointers are in MemoryProtection.readWrite mode by default, unless set otherwise in the constructor.

See https://libsodium.gitbook.io/doc/memory_management#guarded-heap-allocations

Implementation

MemoryProtection get memoryProtection => _memoryProtection;
set memoryProtection (MemoryProtection memoryProtection)

Implementation

set memoryProtection(MemoryProtection memoryProtection) {
  if (memoryProtection == _memoryProtection) {
    return;
  }

  int result;
  switch (memoryProtection) {
    case MemoryProtection.noAccess:
      result = sodium.sodium_mprotect_noaccess(ptr.cast());
    case MemoryProtection.readOnly:
      result = sodium.sodium_mprotect_readonly(ptr.cast());
    case MemoryProtection.readWrite:
      result = sodium.sodium_mprotect_readwrite(ptr.cast());
  }
  SodiumException.checkSucceededInt(result);

  _memoryProtection = memoryProtection;
}