sodium-secretstream
Advanced tools
Comparing version 1.0.1 to 1.0.2
30
index.js
const sodium = require('sodium-universal') | ||
const b4a = require('b4a') | ||
@@ -10,10 +11,9 @@ const ABYTES = sodium.crypto_secretstream_xchacha20poly1305_ABYTES | ||
if (!TAG_FINAL) throw new Error('JavaScript sodium version needs to support crypto_secretstream_xchacha20poly') | ||
const EMPTY = b4a.alloc(0) | ||
const TAG = b4a.alloc(1) | ||
const FINAL = TAG_FINAL[0] | ||
const EMPTY = Buffer.alloc(0) | ||
const TMP = Buffer.alloc(1) | ||
class Push { | ||
constructor (key, state = b4a.allocUnsafe(STATEBYTES), header = b4a.allocUnsafe(HEADERBYTES)) { | ||
if (!TAG_FINAL) throw new Error('JavaScript sodium version needs to support crypto_secretstream_xchacha20poly') | ||
class Push { | ||
constructor (key, state = Buffer.allocUnsafe(STATEBYTES), header = Buffer.allocUnsafe(HEADERBYTES)) { | ||
this.key = key | ||
@@ -26,3 +26,3 @@ this.state = state | ||
next (message, cipher = Buffer.allocUnsafe(message.length + ABYTES)) { | ||
next (message, cipher = b4a.allocUnsafe(message.byteLength + ABYTES)) { | ||
sodium.crypto_secretstream_xchacha20poly1305_push(this.state, cipher, message, null, TAG_MESSAGE) | ||
@@ -32,3 +32,3 @@ return cipher | ||
final (message = EMPTY, cipher = Buffer.allocUnsafe(ABYTES)) { | ||
final (message = EMPTY, cipher = b4a.allocUnsafe(ABYTES)) { | ||
sodium.crypto_secretstream_xchacha20poly1305_push(this.state, cipher, message, null, TAG_FINAL) | ||
@@ -40,5 +40,7 @@ return cipher | ||
class Pull { | ||
constructor (key, state = Buffer.allocUnsafe(STATEBYTES)) { | ||
constructor (key, state = b4a.allocUnsafe(STATEBYTES)) { | ||
if (!TAG_FINAL) throw new Error('JavaScript sodium version needs to support crypto_secretstream_xchacha20poly') | ||
this.key = key | ||
this.state = Buffer.allocUnsafe(STATEBYTES) | ||
this.state = state | ||
this.final = false | ||
@@ -51,5 +53,5 @@ } | ||
next (cipher, message = Buffer.allocUnsafe(cipher.length - ABYTES)) { | ||
sodium.crypto_secretstream_xchacha20poly1305_pull(this.state, message, TMP, cipher, null) | ||
this.final = TMP[0] === FINAL | ||
next (cipher, message = b4a.allocUnsafe(cipher.byteLength - ABYTES)) { | ||
sodium.crypto_secretstream_xchacha20poly1305_pull(this.state, message, TAG, cipher, null) | ||
this.final = b4a.equals(TAG, TAG_FINAL) | ||
return message | ||
@@ -59,3 +61,3 @@ } | ||
function keygen (buf = Buffer.alloc(KEYBYTES)) { | ||
function keygen (buf = b4a.alloc(KEYBYTES)) { | ||
sodium.crypto_secretstream_xchacha20poly1305_keygen(buf) | ||
@@ -62,0 +64,0 @@ return buf |
{ | ||
"name": "sodium-secretstream", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Wraps libsodiums secretstream in a higher level abstraction", | ||
"main": "index.js", | ||
"dependencies": { | ||
"b4a": "^1.1.1", | ||
"sodium-universal": "^3.0.4" | ||
}, | ||
"devDependencies": {}, | ||
"devDependencies": { | ||
"standard": "^16.0.4" | ||
}, | ||
"scripts": { | ||
"test": "standard" | ||
}, | ||
"repository": { | ||
@@ -11,0 +17,0 @@ "type": "git", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5928
6
94
2
1
+ Addedb4a@^1.1.1