npm stats
  • Search
  • About
  • Repo
  • Sponsor
  • more
    • Search
    • About
    • Repo
    • Sponsor

Made by Antonio Ramirez

safe-sodium-buffer

0.1.0

@tonygo

npmHomeRepoSnykSocket
Downloads:0
$ npm install safe-sodium-buffer
DailyWeeklyMonthlyYearly

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) - Allocates size bytes of secure memory
  • SafeBuffer.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 bytes
  • destroyed - Boolean indicating if memory has been freed

Methods

  • destroy() - Manually free and zero the memory
  • [Symbol.dispose]() - Automatic cleanup method (called by using)

SafeBuffer will expose all classic buffer methods: compare, copy, fill...

License

MIT