From 61f2bb9b883343c89fcb28b7ef4ed1d692110ee4 Mon Sep 17 00:00:00 2001 From: Owen Smith Date: Mon, 14 May 2018 10:01:53 -0400 Subject: [PATCH] deps: replace base64url with inline definition --- lib/sign-stream.js | 9 ++++++++- lib/verify-stream.js | 6 +++--- package.json | 1 - 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/sign-stream.js b/lib/sign-stream.js index a7bb2d5..9198457 100644 --- a/lib/sign-stream.js +++ b/lib/sign-stream.js @@ -1,11 +1,18 @@ /*global module*/ -var base64url = require('base64url'); var DataStream = require('./data-stream'); var jwa = require('jwa'); var Stream = require('stream'); var toBuffer = require('./to-buffer'); var util = require('util'); +function base64url(buf) { + return buf + .toString('base64') + .replace(/=/g, '') + .replace(/\+/g, '-') + .replace(/\//g, '_'); +} + function jwsSecuredInput(header, payload, encoding) { encoding = encoding || 'utf8'; var encodedHeader = base64url(toBuffer(header)); diff --git a/lib/verify-stream.js b/lib/verify-stream.js index d9bfa2b..39f7c73 100644 --- a/lib/verify-stream.js +++ b/lib/verify-stream.js @@ -1,5 +1,5 @@ /*global module*/ -var base64url = require('base64url'); +var Buffer = require('safe-buffer').Buffer; var DataStream = require('./data-stream'); var jwa = require('jwa'); var Stream = require('stream'); @@ -20,7 +20,7 @@ function safeJsonParse(thing) { function headerFromJWS(jwsSig) { var encodedHeader = jwsSig.split('.', 1)[0]; - return safeJsonParse(base64url.decode(encodedHeader, 'binary')); + return safeJsonParse(Buffer.from(encodedHeader, 'base64').toString('binary')); } function securedInputFromJWS(jwsSig) { @@ -34,7 +34,7 @@ function signatureFromJWS(jwsSig) { function payloadFromJWS(jwsSig, encoding) { encoding = encoding || 'utf8'; var payload = jwsSig.split('.')[1]; - return base64url.decode(payload, encoding); + return Buffer.from(payload, 'base64').toString(encoding); } function isValidJws(string) { diff --git a/package.json b/package.json index 2236e76..bc5e69e 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,6 @@ "readmeFilename": "readme.md", "gitHead": "c0f6b27bcea5a2ad2e304d91c2e842e4076a6b03", "dependencies": { - "base64url": "^2.0.0", "jwa": "^1.1.5", "safe-buffer": "^5.0.1" },