mongoose-encryption
Advanced tools
Comparing version 0.11.0 to 0.11.1
25
index.js
@@ -5,2 +5,4 @@ (function() { | ||
var _ = require('underscore'); | ||
var mongoose = require('mongoose'); | ||
var semver = require('semver') | ||
var dotty = require('dotty'); | ||
@@ -15,2 +17,8 @@ | ||
if(semver.gt(process.version, '4.0.0')){ | ||
if(semver.lt(mongoose.version, '4.2.4')){ | ||
throw new Error('Mongoose version 4.2.4 or greater is required for Node version 4.0.0 or greater'); | ||
} | ||
} | ||
module.exports = function(schema, options) { | ||
@@ -20,2 +28,4 @@ | ||
if (!options.key) | ||
@@ -131,3 +141,3 @@ throw new Error('options.key is required as a 32 byte base64 string'); | ||
if (this._ct) { | ||
ctWithIV = this._ct.buffer || this._ct; | ||
ctWithIV = this._ct.hasOwnProperty('buffer') ? this._ct.buffer : this._ct; | ||
iv = ctWithIV.slice(0, IV_LENGTH); | ||
@@ -148,3 +158,9 @@ ct = ctWithIV.slice(IV_LENGTH, ctWithIV.length); | ||
decipheredVal = decryptedObject[field]; | ||
this[field] = decipheredVal; | ||
//JSON.parse returns {type: "Buffer", data: Buffer} for Buffers | ||
//https://nodejs.org/api/buffer.html#buffer_buf_tojson | ||
if(_.isObject(decipheredVal) && decipheredVal.type === "Buffer"){ | ||
this[field] = decipheredVal.data; | ||
}else { | ||
this[field] = decipheredVal; | ||
} | ||
} | ||
@@ -160,2 +176,7 @@ this._ct = undefined; | ||
module.exports.encryptedChildren = function(schema, options) { | ||
if (mongoose.version > '4.1.0') { | ||
console.warn('encryptedChildren plugin is not needed for mongoose versions above 4.1.1, continuing without plugin.'); | ||
return; | ||
} | ||
schema.post('validate', function(doc) { | ||
@@ -162,0 +183,0 @@ if (doc.errors) { |
{ | ||
"name": "mongoose-encryption", | ||
"description": "Simple encryption plugin for Mongoose", | ||
"version": "0.11.0", | ||
"version": "0.11.1", | ||
"author": { | ||
@@ -27,4 +27,8 @@ "name": "Joe Goldbeck" | ||
"dotty": "0.0.2", | ||
"underscore": "1.5.x" | ||
"underscore": "1.5.x", | ||
"semver": "5.1.x" | ||
}, | ||
"peerDependencies":{ | ||
"mongoose": ">=3.8.28" | ||
}, | ||
"devDependencies": { | ||
@@ -34,3 +38,2 @@ "mocha": "1.x.x", | ||
"coffee-script": "1.7.x", | ||
"mongoose": "3.8.x", | ||
"sinon": "~1.10.3" | ||
@@ -37,0 +40,0 @@ }, |
Sorry, the diff of this file is not supported yet
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
52092
4
156
4
+ Addedsemver@5.1.x
+ Added@mongodb-js/saslprep@1.1.9(transitive)
+ Added@types/webidl-conversions@7.0.3(transitive)
+ Added@types/whatwg-url@11.0.5(transitive)
+ Addedbson@6.10.1(transitive)
+ Addeddebug@4.4.0(transitive)
+ Addedkareem@2.6.3(transitive)
+ Addedmemory-pager@1.5.0(transitive)
+ Addedmongodb@6.12.0(transitive)
+ Addedmongodb-connection-string-url@3.0.1(transitive)
+ Addedmongoose@8.9.5(transitive)
+ Addedmpath@0.9.0(transitive)
+ Addedmquery@5.0.0(transitive)
+ Addedms@2.1.3(transitive)
+ Addedpunycode@2.3.1(transitive)
+ Addedsemver@5.1.1(transitive)
+ Addedsift@17.1.3(transitive)
+ Addedsparse-bitfield@3.0.3(transitive)
+ Addedtr46@4.1.1(transitive)
+ Addedwebidl-conversions@7.0.0(transitive)
+ Addedwhatwg-url@13.0.0(transitive)