From bb8d1cfaa072f7b4f291d77f97c9dab6fac95381 Mon Sep 17 00:00:00 2001 From: nanov Date: Wed, 6 Nov 2019 17:16:56 +0200 Subject: [PATCH] wip: migrate MFG1 to BigNumber --- lib/crypto/MGF1.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/crypto/MGF1.js b/lib/crypto/MGF1.js index d68a691..0a7aeed 100644 --- a/lib/crypto/MGF1.js +++ b/lib/crypto/MGF1.js @@ -1,13 +1,13 @@ 'use strict'; const crypto = require('crypto'); -const BN = require('bn.js'); + +const BigNumber = require('../BigNumber.js'); const MFG_LEN = 32; const divceil = (a, b) => ~~(((a + b) - 1) / b); // eslint-disable-line no-bitwise -const rjust = (string, width, padding) => { - padding = padding || ' '; +const rjust = (string, width, padding = ' ') => { padding = padding.substr(0, 1); if (string.length < width) return padding.repeat(width - string.length) + string; @@ -26,7 +26,7 @@ const i2osp = (x, len) => { if (x >= 256 ** len) throw new Error('Integer too large'); - return Buffer.from(rjust((Buffer.from((new BN(x)).toArray('be', 4)).toString()).replace(/\x00/gi, ''), len, '\x00')); // eslint-disable-line no-control-regex + return Buffer.from(rjust(new BigNumber(x).toBEBuffer(4).toString().replace(/\x00/gi, ''), len, '\x00')); // eslint-disable-line no-control-regex }; module.exports = {