Skip to content

Commit 9b0b182

Browse files
committed
Document progressCallback
1 parent f9f0ebd commit 9b0b182

3 files changed

Lines changed: 18 additions & 12 deletions

File tree

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,14 +156,15 @@ Synchronously generates a hash for the given string.
156156
| |||
157157
| **returns** | ?string | Resulting hash, actually never null
158158

159-
### bcrypt.hash(s, salt, callback)
159+
### bcrypt.hash(s, salt, callback, progressCallback=)
160160
Asynchronously generates a hash for the given string.
161161

162162
| Name | Type | Description |
163163
| ---- | ---- | ----------- |
164164
| s | string | String to hash |
165165
| salt | number ¦ string | Salt length to generate or salt to use |
166166
| callback | function(Error, ?string) | Callback receiving the error, if any, and the resulting hash |
167+
| progressCallback | function(number) | Callback successively called with the percentage of rounds completed (0.0 - 1.0), maximally once per `MAX_EXECUTION_TIME = 100` ms.
167168

168169
### bcrypt.compareSync(s, hash)
169170
Synchronously tests a string against a hash.
@@ -176,14 +177,15 @@ Synchronously tests a string against a hash.
176177
| **returns** | boolean | true if matching, otherwise false
177178
| **throws** | Error | If an argument is illegal
178179

179-
### bcrypt.compare(s, hash, callback)
180+
### bcrypt.compare(s, hash, callback, progressCallback=)
180181
Asynchronously compares the given data against the given hash.
181182

182183
| Name | Type | Description |
183184
| ---- | ---- | ----------- |
184185
| s | string | Data to compare |
185186
| hash | string | Data to be compared to |
186187
| callback | function(Error, boolean) | Callback receiving the error, if any, otherwise the result |
188+
| progressCallback | function(number) | Callback successively called with the percentage of rounds completed (0.0 - 1.0), maximally once per `MAX_EXECUTION_TIME = 100` ms.
187189
| |||
188190
| **throws** | Error | If the callback argument is invalid
189191

dist/bcrypt.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,7 @@
812812
// Validate the salt
813813
var minor, offset;
814814
if (salt.charAt(0) !== '$' || salt.charAt(1) !== '2') {
815-
err = new Error("Invalid salt version: "+salt.substring(0,2));
815+
err = Error("Invalid salt version: "+salt.substring(0,2));
816816
if (callback) {
817817
_nextTick(callback.bind(this, err));
818818
return;
@@ -1014,7 +1014,8 @@
10141014
* @param {string} s String to hash
10151015
* @param {number|string} salt Salt length to generate or salt to use
10161016
* @param {function(Error, string=)} callback Callback receiving the error, if any, and the resulting hash
1017-
* @param {function(number)=} progressCallback Callback called with the current progress
1017+
* @param {function(number)=} progressCallback Callback successively called with the percentage of rounds completed
1018+
* (0.0 - 1.0), maximally once per `MAX_EXECUTION_TIME = 100` ms.
10181019
* @expose
10191020
*/
10201021
bcrypt.hash = function(s, salt, callback, progressCallback) {
@@ -1059,15 +1060,16 @@
10591060
* @param {string} s Data to compare
10601061
* @param {string} hash Data to be compared to
10611062
* @param {function(Error, boolean)} callback Callback receiving the error, if any, otherwise the result
1062-
* @param {function(number)=} progressCallback Callback called with the current progress
1063+
* @param {function(number)=} progressCallback Callback successively called with the percentage of rounds completed
1064+
* (0.0 - 1.0), maximally once per `MAX_EXECUTION_TIME = 100` ms.
10631065
* @throws {Error} If the callback argument is invalid
10641066
* @expose
10651067
*/
10661068
bcrypt.compare = function(s, hash, callback, progressCallback) {
10671069
if (typeof callback !== 'function')
1068-
throw(new Error("Illegal callback: "+callback));
1070+
throw Error("Illegal callback: "+callback);
10691071
if (typeof s !== "string" || typeof hash !== "string") {
1070-
_nextTick(callback.bind(this, new Error("Illegal argument types: "+(typeof s)+', '+(typeof hash))));
1072+
_nextTick(callback.bind(this, Error("Illegal argument types: "+(typeof s)+', '+(typeof hash))));
10711073
return;
10721074
}
10731075
bcrypt.hash(s, hash.substr(0, 29), function(err, comp) {

src/bcrypt.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@
565565
// Validate the salt
566566
var minor, offset;
567567
if (salt.charAt(0) !== '$' || salt.charAt(1) !== '2') {
568-
err = new Error("Invalid salt version: "+salt.substring(0,2));
568+
err = Error("Invalid salt version: "+salt.substring(0,2));
569569
if (callback) {
570570
_nextTick(callback.bind(this, err));
571571
return;
@@ -767,7 +767,8 @@
767767
* @param {string} s String to hash
768768
* @param {number|string} salt Salt length to generate or salt to use
769769
* @param {function(Error, string=)} callback Callback receiving the error, if any, and the resulting hash
770-
* @param {function(number)=} progressCallback Callback called with the current progress
770+
* @param {function(number)=} progressCallback Callback successively called with the percentage of rounds completed
771+
* (0.0 - 1.0), maximally once per `MAX_EXECUTION_TIME = 100` ms.
771772
* @expose
772773
*/
773774
bcrypt.hash = function(s, salt, callback, progressCallback) {
@@ -812,15 +813,16 @@
812813
* @param {string} s Data to compare
813814
* @param {string} hash Data to be compared to
814815
* @param {function(Error, boolean)} callback Callback receiving the error, if any, otherwise the result
815-
* @param {function(number)=} progressCallback Callback called with the current progress
816+
* @param {function(number)=} progressCallback Callback successively called with the percentage of rounds completed
817+
* (0.0 - 1.0), maximally once per `MAX_EXECUTION_TIME = 100` ms.
816818
* @throws {Error} If the callback argument is invalid
817819
* @expose
818820
*/
819821
bcrypt.compare = function(s, hash, callback, progressCallback) {
820822
if (typeof callback !== 'function')
821-
throw(new Error("Illegal callback: "+callback));
823+
throw Error("Illegal callback: "+callback);
822824
if (typeof s !== "string" || typeof hash !== "string") {
823-
_nextTick(callback.bind(this, new Error("Illegal argument types: "+(typeof s)+', '+(typeof hash))));
825+
_nextTick(callback.bind(this, Error("Illegal argument types: "+(typeof s)+', '+(typeof hash))));
824826
return;
825827
}
826828
bcrypt.hash(s, hash.substr(0, 29), function(err, comp) {

0 commit comments

Comments
 (0)