safe-sodium-buffer
v0.1.0
Published
A secure memory management class for sodium-native with automatic resource cleanup
Downloads
41
Maintainers
Readme
safe-sodium-buffer
A secure memory management class for sodium-native for automatic resource cleanup.
Usage
Automatic cleanup with using
const SafeBuffer = require('safe-sodium-buffer')
{
using safeBuffer = new SafeBuffer(32)
safeBuffer.fill(0x42)
safeBuffer.fill(0xff, 1)
}Manual cleanup
const sb = new SafeBuffer(32)
sb.fill(0x42)
sb.destroy()Example integration
{
using key = new SafeBuffer(32)
using nonce = new SafeBuffer(24)
sodium.randombytes_buf(key.buffer)
sodium.randombytes_buf(nonce.buffer)
}Documentation
Constructor
new SafeBuffer(size)- Allocatessizebytes of secure memorySafeBuffer.from(buffer)- Allocates a buffer from another one
Properties
buffer- The allocated Buffer (null if size is 0 or after destroy)size- The allocated size in bytesdestroyed- Boolean indicating if memory has been freed
Methods
destroy()- Manually free and zero the memory[Symbol.dispose]()- Automatic cleanup method (called byusing)
SafeBuffer will expose all classic buffer methods: compare, copy, fill...
License
MIT
