Skip to content

Commit ddc17c9

Browse files
authored
Merge pull request #1 from LoneRifle/master
Miscellaneous fixes for PR
2 parents c140018 + 3d14db0 commit ddc17c9

File tree

4 files changed

+2012
-19
lines changed

4 files changed

+2012
-19
lines changed

lib/signed-xml.js

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ SignedXml.prototype.checkSignature = function(xml, callback) {
343343

344344
if (!this.keyInfoProvider) {
345345
var err = new Error("cannot validate signature since no key info resolver was provided")
346-
if (!callback){
346+
if (!callback) {
347347
throw err
348348
} else {
349349
callback(err)
@@ -354,7 +354,7 @@ SignedXml.prototype.checkSignature = function(xml, callback) {
354354
this.signingKey = this.keyInfoProvider.getKey(this.keyInfo)
355355
if (!this.signingKey) {
356356
var err = new Error("key info provider could not resolve key info " + this.keyInfo)
357-
if (!callback){
357+
if (!callback) {
358358
throw err
359359
} else {
360360
callback(err)
@@ -365,15 +365,15 @@ SignedXml.prototype.checkSignature = function(xml, callback) {
365365
var doc = new Dom().parseFromString(xml)
366366

367367
if (!this.validateReferences(doc)) {
368-
if (!callback){
368+
if (!callback) {
369369
return false;
370370
} else {
371371
callback(new Error('Could not validate references'))
372372
return
373373
}
374374
}
375375

376-
if (!callback){
376+
if (!callback) {
377377
//Syncronous flow
378378
if (!this.validateSignatureValue(doc)) {
379379
return false
@@ -691,11 +691,11 @@ SignedXml.prototype.addReference = function(xpath, transforms, digestAlgorithm,
691691
*
692692
*/
693693
SignedXml.prototype.computeSignature = function(xml, opts, callback) {
694-
if (typeof opts === 'function' && callback == null){
694+
if (typeof opts === 'function' && callback == null) {
695695
callback = opts
696696
}
697697

698-
if (callback != null && typeof callback !== 'function'){
698+
if (callback != null && typeof callback !== 'function') {
699699
throw new Error("Last paramater must be a callback function")
700700
}
701701

@@ -722,7 +722,7 @@ SignedXml.prototype.computeSignature = function(xml, opts, callback) {
722722
if (validActions.indexOf(location.action) === -1) {
723723
var err = new Error("location.action option has an invalid action: " + location.action +
724724
", must be any of the following values: " + validActions.join(", "));
725-
if (!callback){
725+
if (!callback) {
726726
throw err;
727727
} else {
728728
callback(err, null)
@@ -770,7 +770,7 @@ SignedXml.prototype.computeSignature = function(xml, opts, callback) {
770770

771771
if (!referenceNode || referenceNode.length === 0) {
772772
var err = new Error("the following xpath cannot be used because it was not found: " + location.reference);
773-
if (!callback){
773+
if (!callback) {
774774
throw err
775775
} else {
776776
callback(err, null)
@@ -794,7 +794,7 @@ SignedXml.prototype.computeSignature = function(xml, opts, callback) {
794794
var signedInfoNode = utils.findChilds(this.signatureNode, "SignedInfo")
795795
if (signedInfoNode.length == 0) {
796796
var err = new Error("could not find SignedInfo element in the message")
797-
if (!callback){
797+
if (!callback) {
798798
throw err
799799
} else {
800800
callback(err)
@@ -803,22 +803,23 @@ SignedXml.prototype.computeSignature = function(xml, opts, callback) {
803803
}
804804
signedInfoNode = signedInfoNode[0];
805805

806-
if (!callback){
806+
if (!callback) {
807807
//Synchronous flow
808808
this.calculateSignatureValue(doc)
809809
signatureDoc.insertBefore(this.createSignature(prefix), signedInfoNode.nextSibling)
810810
this.signatureXml = signatureDoc.toString()
811811
this.signedXml = doc.toString()
812812
} else {
813+
var self = this
813814
//Asynchronous flow
814-
this.calculateSignatureValue(doc, (err, signature) => {
815+
this.calculateSignatureValue(doc, function(err, signature) {
815816
if (err) {
816817
callback(err)
817818
} else {
818-
this.signatureValue = signature
819-
signatureDoc.insertBefore(this.createSignature(prefix), signedInfoNode.nextSibling)
820-
this.signatureXml = signatureDoc.toString()
821-
this.signedXml = doc.toString()
819+
self.signatureValue = signature
820+
signatureDoc.insertBefore(self.createSignature(prefix), signedInfoNode.nextSibling)
821+
self.signatureXml = signatureDoc.toString()
822+
self.signedXml = doc.toString()
822823
callback()
823824
}
824825
})

0 commit comments

Comments
 (0)