Skip to content

Commit

Permalink
Used buffer-from ponyfill for compatibility with older node versions
Browse files Browse the repository at this point in the history
  • Loading branch information
balor committed Jul 1, 2018
1 parent 56a1790 commit a706cc4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/connect-memcached.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* connect-memcached
* MIT Licensed
*/
const bufferFrom = require('buffer-from');

var Memcached = require("memcached");
var oneDay = 86400;
Expand Down Expand Up @@ -203,7 +204,7 @@ module.exports = function(session) {

function encrypt(key, pt, algo) {
algo = algo || "aes-256-ctr";
pt = Buffer.isBuffer(pt) ? pt : new Buffer(pt);
pt = Buffer.isBuffer(pt) ? pt : new bufferFrom(pt);
var iv = this.crypto.randomBytes(16);
var hashedKey = this.crypto
.createHash("sha256")
Expand All @@ -220,7 +221,7 @@ module.exports = function(session) {

function decrypt(key, ct, algo) {
algo = algo || "aes-256-ctr";
var dataBuffer = Buffer.from(ct, "hex");
var dataBuffer = bufferFrom(ct, "hex");
var iv = dataBuffer.slice(0, 16);
var hashedKey = this.crypto
.createHash("sha256")
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"url": "https://github.com/balor/connect-memcached"
},
"dependencies": {
"buffer-from": "1.1.0",
"memcached": "2.2.x"
},
"engines": {
Expand Down

0 comments on commit a706cc4

Please sign in to comment.