Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…iles with a slightly smaller change footprint (#1533)

* Attempt at doing https://github.com/balderdashy/waterline/pull/1532/files with a slightly smaller change footprint  (closes #1532)

* Tweak previous commit to ensure a good error msg is shown
  • Loading branch information
mikermcneil authored Oct 13, 2017
2 parents 52e61bc + fb8a1e4 commit 7aca522
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions lib/waterline.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ function Waterline() {
});//∞

// Only allow using at-rest encryption for compatible Node versions
var EA;
if (areAnyModelsUsingAtRestEncryption) {
var RX_NODE_MAJOR_DOT_MINOR = /^v([^.]+\.?[^.]+)\./;
var parsedNodeMajorAndMinorVersion = process.version.match(RX_NODE_MAJOR_DOT_MINOR) && (+(process.version.match(RX_NODE_MAJOR_DOT_MINOR)[1]));
Expand All @@ -185,6 +186,7 @@ function Waterline() {
if (!isNativeCryptoFullyCapable) {
throw new Error('Current installed node version\'s native `crypto` module is not fully capable of the necessary functionality for encrypting/decrypting data at rest with Waterline. To use this feature, please upgrade to Node v' + MIN_NODE_VERSION + ' or above, flush your node_modules, run npm install, and then try again. Otherwise, if you cannot upgrade Node.js, please remove the `encrypt` property from your models\' attributes.');
}
EA = require('encrypted-attr');
}//fi

_.each(wmds, function(wmd){
Expand Down Expand Up @@ -310,14 +312,15 @@ function Waterline() {
});
}//•

try {
var EA = require('encrypted-attr');
EA(undefined, { keys: modelDef.dataEncryptionKeys, keyId: dekId }).encryptAttribute(undefined, 'test-value-purely-for-validation');
} catch (err) {
throw flaverr({
code: 'E_INVALID_DATA_ENCRYPTION_KEYS',
dekId: dekId
}, err);
if (areAnyModelsUsingAtRestEncryption) {
try {
EA(undefined, { keys: modelDef.dataEncryptionKeys, keyId: dekId }).encryptAttribute(undefined, 'test-value-purely-for-validation');
} catch (err) {
throw flaverr({
code: 'E_INVALID_DATA_ENCRYPTION_KEYS',
dekId: dekId
}, err);
}
}

});//∞
Expand Down

0 comments on commit 7aca522

Please sign in to comment.