Skip to content

Commit

Permalink
Moved toBuffer to an approach that doesn’t try to modify the Buffer o…
Browse files Browse the repository at this point in the history
…bject
  • Loading branch information
martinheidegger committed Jan 16, 2017
1 parent 7694af3 commit 5f5fbae
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 11 deletions.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

/* global Headers, fetch */
require('isomorphic-fetch')
require('./lib/bufferFix.js')

var defaults = require('101/defaults')
var crypto = require('crypto')
var createPad = require('./lib/pad')
var toBuffer = require('./lib/toBuffer.js')

/**
* create a graphql-fetch bound to a specific graphql url
Expand Down Expand Up @@ -44,7 +44,7 @@ module.exports = function factory (graphqlUrl, keyID, privateKey, cipherAlgorith
var decipher = function (data) {
var d = crypto.createDecipher(cipherAlgorithm, privateKey)
return Buffer.concat([
d.update(Buffer.from(data, 'base64')),
d.update(toBuffer(data, 'base64')),
d.final()
]).toString('utf8')
}
Expand Down
7 changes: 0 additions & 7 deletions lib/bufferFix.js

This file was deleted.

5 changes: 5 additions & 0 deletions lib/toBuffer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict'

module.exports = function (input, encoding) {
return Buffer.from ? Buffer.from(input, encoding ) : new Buffer(input, encoding)
}
4 changes: 2 additions & 2 deletions test/graphql-fetch.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

/* global Headers */
require('isomorphic-fetch')
require('../lib/bufferFix.js')

var test = require('blue-tape').test

Expand All @@ -12,6 +11,7 @@ require('sinon-as-promised')

var graphqlUrl = 'http://host/graphql'
var graphqlFactory = require('../index.js')
var toBuffer = require('../lib/toBuffer.js')

function _encrypt (cipher, key, pad, data) {
var c = crypto.createCipher(cipher, key)
Expand All @@ -29,7 +29,7 @@ function _encrypt (cipher, key, pad, data) {
function _decrypt (cipher, key, data) {
var d = crypto.createDecipher(cipher, key)
return Buffer.concat([
d.update(Buffer.from(data, 'base64')),
d.update(toBuffer(data, 'base64')),
d.final()
]).toString()
}
Expand Down

0 comments on commit 5f5fbae

Please sign in to comment.