workaround for #9, try {} catch () {} on Buffer.from

This commit is contained in:
AJ ONeal 2016-08-10 11:18:36 -06:00
parent 2c6db04ab6
commit c728f25bc8
1 changed files with 7 additions and 1 deletions

View File

@ -7,7 +7,13 @@ function _bigIntToBase64Url(fbin) {
// Invalid hex string
hex = '0' + hex;
}
var buf = Buffer.from(hex, 'hex');
var buf;
// See https://github.com/Daplie/rsa-compat.js/issues/9
try {
buf = Buffer.from(hex, 'hex');
} catch(e) {
buf = new Buffer(hex, 'hex');
}
var b64 = buf.toString('base64');
var b64Url = b64.replace(/[+]/g, "-").replace(/\//g, "_").replace(/=/g,"");