Skip to content

Commit

Permalink
deps: replace base64url with inline definition
Browse files Browse the repository at this point in the history
  • Loading branch information
omsmith committed May 14, 2018
1 parent 61e7e24 commit 61f2bb9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
9 changes: 8 additions & 1 deletion lib/sign-stream.js
Original file line number Diff line number Diff line change
@@ -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, '')

This comment has been minimized.

Copy link
@caccialdo

caccialdo May 16, 2018

It seems that this line wasn't in the original definition from the base64url package #toBase64 function. This causes a bug in my app where the produced base64 string is invalid. What's the reason for adding this replace operation?

This comment has been minimized.

Copy link
@omsmith

omsmith May 16, 2018

Author Contributor

This comment has been minimized.

Copy link
@caccialdo

caccialdo May 16, 2018

You’re perfectly right. I mixed toBase64 and fromBase64 up. As to the bug I was talking to, it was coming from the remote server not decoding the payload correctly. Ignore my previous comment 👍

.replace(/\+/g, '-')
.replace(/\//g, '_');
}

function jwsSecuredInput(header, payload, encoding) {
encoding = encoding || 'utf8';
var encodedHeader = base64url(toBuffer(header));
Expand Down
6 changes: 3 additions & 3 deletions lib/verify-stream.js
Original file line number Diff line number Diff line change
@@ -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');
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
"readmeFilename": "readme.md",
"gitHead": "c0f6b27bcea5a2ad2e304d91c2e842e4076a6b03",
"dependencies": {
"base64url": "^2.0.0",
"jwa": "^1.1.5",
"safe-buffer": "^5.0.1"
},
Expand Down

0 comments on commit 61f2bb9

Please sign in to comment.