From e9ac929b5adf117c60f4cb267bf895956359af1c Mon Sep 17 00:00:00 2001 From: Emil Bay Date: Wed, 24 Jun 2020 14:01:48 +0200 Subject: [PATCH] Move memory helpers to their own module --- index.js | 13 +------------ memory.js | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 12 deletions(-) create mode 100644 memory.js diff --git a/index.js b/index.js index 1a9f228..717ce28 100644 --- a/index.js +++ b/index.js @@ -2,24 +2,13 @@ // Based on https://github.com/dchest/tweetnacl-js/blob/6dcbcaf5f5cbfd313f2dcfe763db35c828c8ff5b/nacl-fast.js. -var sodium = module.exports - // Ported in 2014 by Dmitry Chestnykh and Devi Mandiri. // Public domain. // // Implementation derived from TweetNaCl version 20140427. // See for details: http://tweetnacl.cr.yp.to/ -// also forwarded at the bottom but randombytes is non-enumerable - -sodium.sodium_memzero = function (arr) { - arr.fill(0) -} - -sodium.sodium_malloc = function (n) { - return new Uint8Array(n) -} - +forward(require('./memory')) forward(require('./crypto_box')) forward(require('./crypto_generichash')) forward(require('./crypto_hash')) diff --git a/memory.js b/memory.js new file mode 100644 index 0000000..e641d6b --- /dev/null +++ b/memory.js @@ -0,0 +1,14 @@ +/* eslint-disable camelcase */ + +function sodium_malloc (n) { + return new Uint8Array(n) +} + +function sodium_memzero (arr) { + arr.fill(0) +} + +module.exports = { + sodium_malloc, + sodium_memzero +}