File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -111,6 +111,9 @@ Hmac.prototype._transform = Hash.prototype._transform;
111111//
112112// Note: hmac object can not be used after validate() method has been called.
113113Hmac . prototype . validate = function ( inputBuffer ) {
114+ if ( ! ( inputBuffer instanceof Buffer ) ) {
115+ throw new TypeError ( 'Argument should be a Buffer' ) ;
116+ }
114117 var ah = new Hmac ( 'sha256' , this . key ) . update ( this . digest ( ) ) . digest ( ) ;
115118 var bh = new Hmac ( 'sha256' , this . key ) . update ( inputBuffer ) . digest ( ) ;
116119 return ah . equals ( bh ) ;
@@ -687,7 +690,11 @@ function filterDuplicates(names) {
687690exports . timingSafeEqual = function ( a , b ) {
688691 var key = randomBytes ( 32 ) ;
689692 var ah = new Hmac ( 'sha256' , key ) . update ( a ) ;
690- return ah . validate ( new Hmac ( 'sha256' , key ) . update ( b ) . digest ( ) ) ;
693+ // The final === test is just in case of the vanishingly small chance of
694+ // a collision. It only fires if the digest comparison passes and so doesn't
695+ // leak timing information.
696+ return ah . validate ( new Hmac ( 'sha256' , key ) . update ( b ) . digest ( ) ) &&
697+ a . toString ( ) === b . toString ( ) ;
691698} ;
692699
693700// Legacy API
You can’t perform that action at this time.
0 commit comments