crypto-pouch
Advanced tools
Comparing version 2.0.0 to 3.0.0
19
index.js
@@ -7,7 +7,8 @@ 'use strict'; | ||
var configId = '_local/crypto'; | ||
var defaultDigest = 'sha256'; | ||
var transform = require('transform-pouch').transform; | ||
var uuid = require('node-uuid'); | ||
function genKey(password, salt) { | ||
function genKey(password, salt, digest) { | ||
return new PouchPromise(function (resolve, reject) { | ||
pbkdf2.pbkdf2(password, salt, 1000, 256 / 8, function (err, key) { | ||
pbkdf2.pbkdf2(password, salt, 1000, 256 / 8, digest, function (err, key) { | ||
password = null; | ||
@@ -27,6 +28,12 @@ if (err) { | ||
if (options && options.ignore) { | ||
ignore = ignore.concat(options.ignore) | ||
if (!options) { | ||
options = {}; | ||
} | ||
if (options.ignore) { | ||
ignore = ignore.concat(options.ignore); | ||
} | ||
if (!options.digest) { | ||
options.digest = defaultDigest; | ||
} | ||
var pending = db.get(configId).then(function (doc){ | ||
@@ -58,3 +65,3 @@ if (!doc.salt) { | ||
}).then(function (doc) { | ||
return genKey(password, new Buffer(doc.salt, 'hex')); | ||
return genKey(password, new Buffer(doc.salt, 'hex'), options.digest); | ||
}).then(function (_key) { | ||
@@ -61,0 +68,0 @@ password = null; |
{ | ||
"name": "crypto-pouch", | ||
"version": "2.0.0", | ||
"version": "3.0.0", | ||
"description": "encrypted pouchdb/couchdb database", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -49,2 +49,4 @@ crypto pouch [![Build Status](https://travis-ci.org/calvinmetcalf/crypto-pouch.svg)](https://travis-ci.org/calvinmetcalf/crypto-pouch) | ||
String or Array of Strings of properties that will not be encrypted. | ||
- `options.digest` | ||
Any of `sha1`, `sha256`, `sha512` (default). | ||
@@ -51,0 +53,0 @@ |
32
test.js
@@ -116,1 +116,33 @@ var test = require('tape'); | ||
}) | ||
test('options.digest with sha512 default', function (t) { | ||
t.plan(2); | ||
var db1 = new PouchDB('ten', {db: memdown}); | ||
var db2 = new PouchDB('eleven', {db: memdown}); | ||
// simulate previously doc created with {digest: sha512} | ||
var docSha256 = { | ||
nonce: '619cf4a32914bc9b5ca26ddf', | ||
data: 'bdc160a9ff46151af37ccd6e20', | ||
tag: '1d082c358bc4cda3e8249bb0bb19eb3e', | ||
_id: 'baz' | ||
}; | ||
var cryptoDoc = { | ||
_id: '_local/crypto', | ||
salt: 'f5c011aea21f25b9e975dbacbe38d235' | ||
}; | ||
db1.bulkDocs([docSha256, cryptoDoc]).then(function () { | ||
db1.crypto('password'); | ||
return db1.get('baz'); | ||
}).then(function (doc) { | ||
t.equals(doc.foo, 'bar', 'returns doc for same write / read digest'); | ||
}); | ||
db2.bulkDocs([docSha256, cryptoDoc]).then(function () { | ||
db2.crypto('password', {digest: 'sha512'}); | ||
return db2.get('baz'); | ||
}).then(function () { | ||
t.error('does not throw error'); | ||
}).catch(function (err) { | ||
t.ok(err, 'throws error for different write / read digest');; | ||
}); | ||
}); |
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
1040516
23264
119