From c728f25bc8d9023e14ec76439b6bcd2cf4251a3f Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Wed, 10 Aug 2016 11:18:36 -0600 Subject: [PATCH] workaround for #9, try {} catch () {} on Buffer.from --- lib/rsa-extra.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/rsa-extra.js b/lib/rsa-extra.js index 2ba7dd1..38a3e77 100644 --- a/lib/rsa-extra.js +++ b/lib/rsa-extra.js @@ -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,"");