From e8a80932e1d36155849010d2050ee194e09dff03 Mon Sep 17 00:00:00 2001 From: Vladislav Hristov Date: Fri, 1 Nov 2019 16:50:39 +0200 Subject: [PATCH] fit: key size is now calculated instead of hardcoded --- lib/keymanagers/Key.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/keymanagers/Key.js b/lib/keymanagers/Key.js index 1f17e78..9a7f90b 100644 --- a/lib/keymanagers/Key.js +++ b/lib/keymanagers/Key.js @@ -106,9 +106,7 @@ module.exports = class Key { const key = this.keyIsPublic ? this.publicKey : this.privateKey; const eKey = Buffer.from(key.e.toByteArray()); - return to === 'hex' - ? eKey.toString('hex') - : eKey; + return to === 'hex' ? eKey.toString('hex') : eKey; } d() { @@ -128,7 +126,10 @@ module.exports = class Key { // eslint-disable-next-line class-methods-use-this size() { - return 2048; + const keyN = this.n('hex'); + const bn = new BigInteger(keyN, 16); + + return bn.bitLength(); } toPem() {