Move memory helpers to their own module

This commit is contained in:
Emil Bay 2020-06-24 14:01:48 +02:00
parent e77c70ef71
commit e9ac929b5a
2 changed files with 15 additions and 12 deletions

View File

@ -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'))

14
memory.js Normal file
View File

@ -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
}