@@ -343,7 +343,7 @@ SignedXml.prototype.checkSignature = function(xml, callback) {
343
343
344
344
if ( ! this . keyInfoProvider ) {
345
345
var err = new Error ( "cannot validate signature since no key info resolver was provided" )
346
- if ( ! callback ) {
346
+ if ( ! callback ) {
347
347
throw err
348
348
} else {
349
349
callback ( err )
@@ -354,7 +354,7 @@ SignedXml.prototype.checkSignature = function(xml, callback) {
354
354
this . signingKey = this . keyInfoProvider . getKey ( this . keyInfo )
355
355
if ( ! this . signingKey ) {
356
356
var err = new Error ( "key info provider could not resolve key info " + this . keyInfo )
357
- if ( ! callback ) {
357
+ if ( ! callback ) {
358
358
throw err
359
359
} else {
360
360
callback ( err )
@@ -365,15 +365,15 @@ SignedXml.prototype.checkSignature = function(xml, callback) {
365
365
var doc = new Dom ( ) . parseFromString ( xml )
366
366
367
367
if ( ! this . validateReferences ( doc ) ) {
368
- if ( ! callback ) {
368
+ if ( ! callback ) {
369
369
return false ;
370
370
} else {
371
371
callback ( new Error ( 'Could not validate references' ) )
372
372
return
373
373
}
374
374
}
375
375
376
- if ( ! callback ) {
376
+ if ( ! callback ) {
377
377
//Syncronous flow
378
378
if ( ! this . validateSignatureValue ( doc ) ) {
379
379
return false
@@ -691,11 +691,11 @@ SignedXml.prototype.addReference = function(xpath, transforms, digestAlgorithm,
691
691
*
692
692
*/
693
693
SignedXml . prototype . computeSignature = function ( xml , opts , callback ) {
694
- if ( typeof opts === 'function' && callback == null ) {
694
+ if ( typeof opts === 'function' && callback == null ) {
695
695
callback = opts
696
696
}
697
697
698
- if ( callback != null && typeof callback !== 'function' ) {
698
+ if ( callback != null && typeof callback !== 'function' ) {
699
699
throw new Error ( "Last paramater must be a callback function" )
700
700
}
701
701
@@ -722,7 +722,7 @@ SignedXml.prototype.computeSignature = function(xml, opts, callback) {
722
722
if ( validActions . indexOf ( location . action ) === - 1 ) {
723
723
var err = new Error ( "location.action option has an invalid action: " + location . action +
724
724
", must be any of the following values: " + validActions . join ( ", " ) ) ;
725
- if ( ! callback ) {
725
+ if ( ! callback ) {
726
726
throw err ;
727
727
} else {
728
728
callback ( err , null )
@@ -770,7 +770,7 @@ SignedXml.prototype.computeSignature = function(xml, opts, callback) {
770
770
771
771
if ( ! referenceNode || referenceNode . length === 0 ) {
772
772
var err = new Error ( "the following xpath cannot be used because it was not found: " + location . reference ) ;
773
- if ( ! callback ) {
773
+ if ( ! callback ) {
774
774
throw err
775
775
} else {
776
776
callback ( err , null )
@@ -794,7 +794,7 @@ SignedXml.prototype.computeSignature = function(xml, opts, callback) {
794
794
var signedInfoNode = utils . findChilds ( this . signatureNode , "SignedInfo" )
795
795
if ( signedInfoNode . length == 0 ) {
796
796
var err = new Error ( "could not find SignedInfo element in the message" )
797
- if ( ! callback ) {
797
+ if ( ! callback ) {
798
798
throw err
799
799
} else {
800
800
callback ( err )
@@ -803,22 +803,23 @@ SignedXml.prototype.computeSignature = function(xml, opts, callback) {
803
803
}
804
804
signedInfoNode = signedInfoNode [ 0 ] ;
805
805
806
- if ( ! callback ) {
806
+ if ( ! callback ) {
807
807
//Synchronous flow
808
808
this . calculateSignatureValue ( doc )
809
809
signatureDoc . insertBefore ( this . createSignature ( prefix ) , signedInfoNode . nextSibling )
810
810
this . signatureXml = signatureDoc . toString ( )
811
811
this . signedXml = doc . toString ( )
812
812
} else {
813
+ var self = this
813
814
//Asynchronous flow
814
- this . calculateSignatureValue ( doc , ( err , signature ) => {
815
+ this . calculateSignatureValue ( doc , function ( err , signature ) {
815
816
if ( err ) {
816
817
callback ( err )
817
818
} 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 ( )
822
823
callback ( )
823
824
}
824
825
} )
0 commit comments