File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 638638 }
639639
640640 // Async
641- if ( typeof callback != 'undefined' ) {
641+ if ( typeof callback !== 'undefined' ) {
642642 next ( ) ;
643643 return null ;
644- // Sync
644+ // Sync
645645 } else {
646646 var res ;
647647 while ( true ) {
758758 // Browser, see: http://www.w3.org/TR/WebCryptoAPI/
759759 } else {
760760 var array = new Uint32Array ( len ) ;
761- global . crypto . getRandomValues ( array ) ; // Maybe use a polyfill
761+ if ( global . crypto && typeof global . crypto . getRandomValues === 'function' ) {
762+ global . crypto . getRandomValues ( array ) ;
763+ } else if ( typeof _getRandomValues === 'function' ) {
764+ _getRandomValues ( array ) ;
765+ } else {
766+ throw ( new Error ( "Failed to generate random values: Web Crypto API not available / no polyfill set" ) ) ;
767+ }
762768 return Array . prototype . slice . call ( array ) ;
763769 }
764770 }
787793 throw ( err ) ;
788794 }
789795 }
796+
797+ var _getRandomValues = null ;
798+
799+ /**
800+ * Sets the polyfill that should be used if window.crypto.getRandomValues is not available.
801+ * @param {function(Uint32Array) } getRandomValues The actual implementation
802+ */
803+ bcrypt . setRandomPolyfill = function ( getRandomValues ) {
804+ _getRandomValues = getRandomValues ;
805+ } ;
790806
791807 /**
792808 * Synchronously generates a salt.
You can’t perform that action at this time.
0 commit comments