Skip to content

Commit c6b30c9

Browse files
panvalinuxwolf
authored andcommitted
Update: use npm-published base64url implementation (#104)
remove urlsafe enc/dec tar dependency
1 parent 0d1a8cd commit c6b30c9

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

lib/util/base64url.js

+13-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
"use strict";
77

8-
var impl = require("urlsafe-base64");
8+
var impl = require("base64url");
99

1010
/**
1111
* @namespace base64url
@@ -25,15 +25,25 @@ var base64url = {
2525
* @param {String} [encoding = binary] The input encoding format.
2626
* @returns {String} the base64url encoding of {input}.
2727
*/
28-
encode: impl.encode,
28+
encode: function encode(buffer, encoding) {
29+
if (buffer instanceof ArrayBuffer) {
30+
buffer = new Uint8Array(buffer);
31+
}
32+
33+
if (!Buffer.isBuffer(buffer)) {
34+
buffer = new Buffer(buffer, encoding);
35+
}
36+
37+
return impl.encode(buffer);
38+
},
2939
/**
3040
* @function
3141
* Decodes the input from base64url.
3242
*
3343
* @param {String} input The data to decode.
3444
* @returns {Buffer|String} the base64url decoding of {input}.
3545
*/
36-
decode: impl.decode
46+
decode: impl.toBuffer
3747
};
3848

3949
module.exports = base64url;

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
],
2727
"license": "Apache-2.0",
2828
"dependencies": {
29+
"base64url": "^2.0.0",
2930
"es6-promise": "^4.0.5",
3031
"jsbn": "^1.1.0",
3132
"lodash.assign": "^4.0.8",
@@ -40,7 +41,6 @@
4041
"lodash.uniq": "^4.2.1",
4142
"long": "^3.1.0",
4243
"node-forge": "https://github.com/linuxwolf/forge/archive/browserify.tar.gz",
43-
"urlsafe-base64": "https://github.com/linuxwolf/urlsafe-base64/archive/encoding.tar.gz",
4444
"uuid": "^3.0.1"
4545
},
4646
"devDependencies": {

0 commit comments

Comments
 (0)