From 4ffe0aa08b926ae988360307fbce1d3a5fc68283 Mon Sep 17 00:00:00 2001 From: troyfactor4 Date: Mon, 13 Apr 2020 20:47:32 -0300 Subject: [PATCH 1/2] Async response for built in algo sign/verify --- lib/signed-xml.js | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/lib/signed-xml.js b/lib/signed-xml.js index b02ff078..c624b4a8 100644 --- a/lib/signed-xml.js +++ b/lib/signed-xml.js @@ -85,22 +85,24 @@ function RSASHA1() { * Sign the given string using the given key * */ - this.getSignature = function(signedInfo, signingKey) { + this.getSignature = function(signedInfo, signingKey, callback) { var signer = crypto.createSign("RSA-SHA1") signer.update(signedInfo) var res = signer.sign(signingKey, 'base64') - return res + if (callback) callback(null, res) + else return res } /** * Verify the given signature of the given string using key * */ - this.verifySignature = function(str, key, signatureValue) { + this.verifySignature = function(str, key, signatureValue, callback) { var verifier = crypto.createVerify("RSA-SHA1") verifier.update(str) var res = verifier.verify(key, signatureValue, 'base64') - return res + if (callback) callback(null, res) + else return res } this.getAlgorithmName = function() { @@ -120,22 +122,24 @@ function RSASHA256() { * Sign the given string using the given key * */ - this.getSignature = function(signedInfo, signingKey) { + this.getSignature = function(signedInfo, signingKey, callback) { var signer = crypto.createSign("RSA-SHA256") signer.update(signedInfo) var res = signer.sign(signingKey, 'base64') - return res + if (callback) callback(null, res) + else return res } /** * Verify the given signature of the given string using key * */ - this.verifySignature = function(str, key, signatureValue) { + this.verifySignature = function(str, key, signatureValue, callback) { var verifier = crypto.createVerify("RSA-SHA256") verifier.update(str) var res = verifier.verify(key, signatureValue, 'base64') - return res + if (callback) callback(null, res) + else return res } this.getAlgorithmName = function() { @@ -154,22 +158,24 @@ function RSASHA512() { * Sign the given string using the given key * */ - this.getSignature = function(signedInfo, signingKey) { + this.getSignature = function(signedInfo, signingKey, callback) { var signer = crypto.createSign("RSA-SHA512") signer.update(signedInfo) var res = signer.sign(signingKey, 'base64') - return res + if (callback) callback(null, res) + else return res } /** * Verify the given signature of the given string using key * */ - this.verifySignature = function(str, key, signatureValue) { + this.verifySignature = function(str, key, signatureValue, callback) { var verifier = crypto.createVerify("RSA-SHA512") verifier.update(str) var res = verifier.verify(key, signatureValue, 'base64') - return res + if (callback) callback(null, res) + else return res } this.getAlgorithmName = function() { From f982b0c66426890c22fdf88b8f0019c0cd463ff2 Mon Sep 17 00:00:00 2001 From: troyfactor4 Date: Mon, 13 Apr 2020 20:55:58 -0300 Subject: [PATCH 2/2] return response as well even if async --- lib/signed-xml.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/signed-xml.js b/lib/signed-xml.js index c624b4a8..8db07f21 100644 --- a/lib/signed-xml.js +++ b/lib/signed-xml.js @@ -90,7 +90,7 @@ function RSASHA1() { signer.update(signedInfo) var res = signer.sign(signingKey, 'base64') if (callback) callback(null, res) - else return res + return res } /** @@ -102,7 +102,7 @@ function RSASHA1() { verifier.update(str) var res = verifier.verify(key, signatureValue, 'base64') if (callback) callback(null, res) - else return res + return res } this.getAlgorithmName = function() { @@ -127,7 +127,7 @@ function RSASHA256() { signer.update(signedInfo) var res = signer.sign(signingKey, 'base64') if (callback) callback(null, res) - else return res + return res } /** @@ -139,7 +139,7 @@ function RSASHA256() { verifier.update(str) var res = verifier.verify(key, signatureValue, 'base64') if (callback) callback(null, res) - else return res + return res } this.getAlgorithmName = function() { @@ -163,7 +163,7 @@ function RSASHA512() { signer.update(signedInfo) var res = signer.sign(signingKey, 'base64') if (callback) callback(null, res) - else return res + return res } /** @@ -175,7 +175,7 @@ function RSASHA512() { verifier.update(str) var res = verifier.verify(key, signatureValue, 'base64') if (callback) callback(null, res) - else return res + return res } this.getAlgorithmName = function() {