Skip to content

Commit 4ffe0aa

Browse files
committed
Async response for built in algo sign/verify
1 parent 713f3d8 commit 4ffe0aa

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

lib/signed-xml.js

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -85,22 +85,24 @@ function RSASHA1() {
8585
* Sign the given string using the given key
8686
*
8787
*/
88-
this.getSignature = function(signedInfo, signingKey) {
88+
this.getSignature = function(signedInfo, signingKey, callback) {
8989
var signer = crypto.createSign("RSA-SHA1")
9090
signer.update(signedInfo)
9191
var res = signer.sign(signingKey, 'base64')
92-
return res
92+
if (callback) callback(null, res)
93+
else return res
9394
}
9495

9596
/**
9697
* Verify the given signature of the given string using key
9798
*
9899
*/
99-
this.verifySignature = function(str, key, signatureValue) {
100+
this.verifySignature = function(str, key, signatureValue, callback) {
100101
var verifier = crypto.createVerify("RSA-SHA1")
101102
verifier.update(str)
102103
var res = verifier.verify(key, signatureValue, 'base64')
103-
return res
104+
if (callback) callback(null, res)
105+
else return res
104106
}
105107

106108
this.getAlgorithmName = function() {
@@ -120,22 +122,24 @@ function RSASHA256() {
120122
* Sign the given string using the given key
121123
*
122124
*/
123-
this.getSignature = function(signedInfo, signingKey) {
125+
this.getSignature = function(signedInfo, signingKey, callback) {
124126
var signer = crypto.createSign("RSA-SHA256")
125127
signer.update(signedInfo)
126128
var res = signer.sign(signingKey, 'base64')
127-
return res
129+
if (callback) callback(null, res)
130+
else return res
128131
}
129132

130133
/**
131134
* Verify the given signature of the given string using key
132135
*
133136
*/
134-
this.verifySignature = function(str, key, signatureValue) {
137+
this.verifySignature = function(str, key, signatureValue, callback) {
135138
var verifier = crypto.createVerify("RSA-SHA256")
136139
verifier.update(str)
137140
var res = verifier.verify(key, signatureValue, 'base64')
138-
return res
141+
if (callback) callback(null, res)
142+
else return res
139143
}
140144

141145
this.getAlgorithmName = function() {
@@ -154,22 +158,24 @@ function RSASHA512() {
154158
* Sign the given string using the given key
155159
*
156160
*/
157-
this.getSignature = function(signedInfo, signingKey) {
161+
this.getSignature = function(signedInfo, signingKey, callback) {
158162
var signer = crypto.createSign("RSA-SHA512")
159163
signer.update(signedInfo)
160164
var res = signer.sign(signingKey, 'base64')
161-
return res
165+
if (callback) callback(null, res)
166+
else return res
162167
}
163168

164169
/**
165170
* Verify the given signature of the given string using key
166171
*
167172
*/
168-
this.verifySignature = function(str, key, signatureValue) {
173+
this.verifySignature = function(str, key, signatureValue, callback) {
169174
var verifier = crypto.createVerify("RSA-SHA512")
170175
verifier.update(str)
171176
var res = verifier.verify(key, signatureValue, 'base64')
172-
return res
177+
if (callback) callback(null, res)
178+
else return res
173179
}
174180

175181
this.getAlgorithmName = function() {

0 commit comments

Comments
 (0)