Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow Box.decrypt to get passed a nonce parameter #135

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions install.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ var https = require('https');
var fs = require('fs');
var path = require('path');
var exec = require('child_process').exec;
var spawn = require('child_process').spawn;
var os = require('os');

var libFiles = [
Expand Down Expand Up @@ -270,8 +271,8 @@ function doDownloads(next) {
});
}

function run(cmdLine, expectedExitCode, next) {
var child = exec(cmdLine);
function run(cmdLine, args, expectedExitCode, next) {
var child = spawn(cmdLine, { shell: true });

if (typeof expectedExitCode === 'undefined') {
expectedExitCode = 0;
Expand Down Expand Up @@ -340,9 +341,9 @@ function isPreInstallMode() {
// Start
if (os.platform() !== 'win32') {
if (isPreInstallMode()) {
run('make libsodium');
run('make', ['libsodium']);
} else {
run('make nodesodium');
run('make', ['nodesodium']);
}
} else {
checkMSVSVersion();
Expand All @@ -357,7 +358,7 @@ if (os.platform() !== 'win32') {
});
} else {
console.log('Install Mode');
run('node-gyp rebuild', 0, function() {
run('node-gyp', ['rebuild'], 0, function() {
console.log('Copy lib files to Release folder');
files = libFiles.slice(0); // clone array
copyFiles(files, function() {
Expand All @@ -366,4 +367,4 @@ if (os.platform() !== 'win32') {
});
});
}
}
}
15 changes: 7 additions & 8 deletions lib/box.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ var assert = require('assert');
/**
* Public-key authenticated encryption: Box
*
* @param {String|Buffer|Array} secretKey sender's private key.
* @param {String|Buffer|Array} publicKey recipient's public key.
* @param {String|Buffer|Array} secretKey sender's private key.
* @param {Boolean} easy Use regular or easy mode. Defaults to regular
*
* @see Keys
Expand Down Expand Up @@ -144,17 +144,17 @@ module.exports = function Box(publicKey, secretKey, easy) {
* @param {Buffer|String|Array} nonce the nonce used to encrypt
* @param {String} [encoding] the encoding to used in cipherText, nonce, plainText
*/
self.decrypt = function (cipherBox, encoding) {
self.decrypt = function (cipherText, nonce, encoding) {
encoding = String(encoding || self.defaultEncoding);

assert(typeof cipherBox == 'object' && cipherBox.hasOwnProperty('cipherText') && cipherBox.hasOwnProperty('nonce'), 'cipherBox is an object with properties `cipherText` and `nonce`.');
assert(cipherBox.cipherText instanceof Buffer, 'cipherBox should have a cipherText property that is a buffer') ;
assert(cipherText instanceof Buffer, 'cipherText property that is a buffer') ;
assert(nonce instanceof Buffer, 'nonce property that is a buffer') ;

var nonce = new Nonce(cipherBox.nonce);
//var nonce = new Nonce(cipherBox.nonce); nonce.get()

var plainText = (self.easy ? binding.crypto_box_open_easy : binding.crypto_box_open)(
cipherBox.cipherText,
nonce.get(),
cipherText,
nonce,
self.boxKey.getPublicKey().get(),
self.boxKey.getSecretKey().get()
);
Expand All @@ -170,4 +170,3 @@ module.exports = function Box(publicKey, secretKey, easy) {
self.close = self.encrypt;
self.open = self.decrypt;
};

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"main": "index.js",
"description": "Lib Sodium port for node.js",
"dependencies": {
"nan": "^2.2.1"
"nan": "2.2.1"
},
"devDependencies": {
"mdextract": "^1.0.0",
Expand Down