Skip to content

Commit 79fc2ac

Browse files
authored
Merge pull request #209 from troyfactor4/master
Async response for built in algo sign/verify
2 parents 713f3d8 + f982b0c commit 79fc2ac

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

lib/signed-xml.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,21 +85,23 @@ 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+
if (callback) callback(null, res)
9293
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')
104+
if (callback) callback(null, res)
103105
return res
104106
}
105107

@@ -120,21 +122,23 @@ 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')
129+
if (callback) callback(null, res)
127130
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')
141+
if (callback) callback(null, res)
138142
return res
139143
}
140144

@@ -154,21 +158,23 @@ 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')
165+
if (callback) callback(null, res)
161166
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')
177+
if (callback) callback(null, res)
172178
return res
173179
}
174180

0 commit comments

Comments
 (0)