Skip to content

Commit 950eb5a

Browse files
committed
Refactoring, document setRandomFallback
1 parent 5981bf7 commit 950eb5a

File tree

8 files changed

+321
-343
lines changed

8 files changed

+321
-343
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
node_modules/
22
npm-debug.log
33
.idea/
4+
doco/

README.md

Lines changed: 72 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -112,102 +112,102 @@ bcrypt.hash('bacon', 8, function(err, hash) {
112112

113113
API
114114
---
115+
### setRandomFallback(random)
115116

116-
- [bcrypt](#bcrypt)
117-
- [bcrypt.genSaltSync(rounds=, seed_length=)](#bcryptgensaltsyncrounds-seed_length)
118-
- [bcrypt.genSalt(rounds=, seed_length=, callback)](#bcryptgensaltrounds-seed_length-callback)
119-
- [bcrypt.hashSync(s, salt=)](#bcrypthashsyncs-salt)
120-
- [bcrypt.hash(s, salt, callback, progressCallback=)](#bcrypthashs-salt-callback-progresscallback)
121-
- [bcrypt.compareSync(s, hash)](#bcryptcomparesyncs-hash)
122-
- [bcrypt.compare(s, hash, callback, progressCallback=)](#bcryptcompares-hash-callback-progresscallback)
123-
- [bcrypt.getRounds(hash)](#bcryptgetroundshash)
124-
- [bcrypt.getSalt(hash)](#bcryptgetsalthash)
117+
Sets the random number generator to use as a fallback if neither node's `crypto` module nor the Web Crypto API
118+
is available.
125119

126-
### bcrypt
127-
bcrypt namespace.
120+
| Parameter | Type | Description
121+
|-----------------|-----------------|---------------
122+
| random | *function(number):!Array.<number>* | Function taking the number of bytes to generate as its sole argument, returning the corresponding array of cryptographically secure random byte values.
123+
| **@see** | | http://nodejs.org/api/crypto.html
124+
| **@see** | | http://www.w3.org/TR/WebCryptoAPI/
128125

126+
### genSaltSync(rounds=, seed_length=)
129127

130-
### bcrypt.genSaltSync(rounds=, seed_length=)
131128
Synchronously generates a salt.
132129

133-
| Name | Type | Description |
134-
| ---- | ---- | ----------- |
135-
| rounds | number | Number of rounds to use, defaults to 10 if omitted |
136-
| seed_length | number | Not supported. |
137-
| |||
138-
| **returns** | string | Resulting salt
130+
| Parameter | Type | Description
131+
|-----------------|-----------------|---------------
132+
| rounds | *number* | Number of rounds to use, defaults to 10 if omitted
133+
| seed_length | *number* | Not supported.
134+
| **@returns** | *string* | Resulting salt
135+
| **@throws** | *Error* | If a random fallback is required but not set
136+
137+
### genSalt(rounds=, seed_length=, callback)
139138

140-
### bcrypt.genSalt(rounds=, seed_length=, callback)
141139
Asynchronously generates a salt.
142140

143-
| Name | Type | Description |
144-
| ---- | ---- | ----------- |
145-
| rounds | (number ¦ function(Error, ?string)) | Number of rounds to use, defaults to 10 if omitted |
146-
| seed_length | (number ¦ function(Error, ?string)) | Not supported. |
147-
| callback | function(Error, ?string) | Callback receiving the error, if any, and the resulting salt |
141+
| Parameter | Type | Description
142+
|-----------------|-----------------|---------------
143+
| rounds | *number | function(Error, string=)* | Number of rounds to use, defaults to 10 if omitted
144+
| seed_length | *number | function(Error, string=)* | Not supported.
145+
| callback | *function(Error, string=)* | Callback receiving the error, if any, and the resulting salt
146+
147+
### hashSync(s, salt=)
148148

149-
### bcrypt.hashSync(s, salt=)
150149
Synchronously generates a hash for the given string.
151150

152-
| Name | Type | Description |
153-
| ---- | ---- | ----------- |
154-
| s | string | String to hash |
155-
| salt | (number ¦ string) | Salt length to generate or salt to use, default to 10 |
156-
| |||
157-
| **returns** | ?string | Resulting hash, actually never null
151+
| Parameter | Type | Description
152+
|-----------------|-----------------|---------------
153+
| s | *string* | String to hash
154+
| salt | *number | string* | Salt length to generate or salt to use, default to 10
155+
| **@returns** | *string* | Resulting hash
156+
157+
### hash(s, salt, callback, progressCallback)
158158

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

162-
| Name | Type | Description |
163-
| ---- | ---- | ----------- |
164-
| s | string | String to hash |
165-
| salt | number ¦ string | Salt length to generate or salt to use |
166-
| 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.
161+
| Parameter | Type | Description
162+
|-----------------|-----------------|---------------
163+
| s | *string* | String to hash
164+
| salt | *number | string* | Salt length to generate or salt to use
165+
| callback | *function(Error, string=)* | Callback receiving the error, if any, and the resulting hash
166+
| progressCallback | *function(number)* | Callback successively called with the percentage of rounds completed (0.0 - 1.0), maximally once per `MAX_EXECUTION_TIME = 100` ms.
167+
168+
### compareSync(s, hash)
168169

169-
### bcrypt.compareSync(s, hash)
170170
Synchronously tests a string against a hash.
171171

172-
| Name | Type | Description |
173-
| ---- | ---- | ----------- |
174-
| s | string | String to compare |
175-
| hash | string | Hash to test against |
176-
| |||
177-
| **returns** | boolean | true if matching, otherwise false
178-
| **throws** | Error | If an argument is illegal
172+
| Parameter | Type | Description
173+
|-----------------|-----------------|---------------
174+
| s | *string* | String to compare
175+
| hash | *string* | Hash to test against
176+
| **@returns** | *boolean* | true if matching, otherwise false
177+
| **@throws** | *Error* | If an argument is illegal
178+
179+
### compare(s, hash, callback, progressCallback)
179180

180-
### bcrypt.compare(s, hash, callback, progressCallback=)
181181
Asynchronously compares the given data against the given hash.
182182

183-
| Name | Type | Description |
184-
| ---- | ---- | ----------- |
185-
| s | string | Data to compare |
186-
| hash | string | Data to be compared to |
187-
| 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.
189-
| |||
190-
| **throws** | Error | If the callback argument is invalid
183+
| Parameter | Type | Description
184+
|-----------------|-----------------|---------------
185+
| s | *string* | Data to compare
186+
| hash | *string* | Data to be compared to
187+
| 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.
189+
| **@throws** | *Error* | If the callback argument is invalid
190+
191+
### getRounds(hash)
191192

192-
### bcrypt.getRounds(hash)
193193
Gets the number of rounds used to encrypt the specified hash.
194194

195-
| Name | Type | Description |
196-
| ---- | ---- | ----------- |
197-
| hash | string | Hash to extract the used number of rounds from |
198-
| |||
199-
| **returns** | number | Number of rounds used
200-
| **throws** | Error | If hash is not a string
201-
202-
### bcrypt.getSalt(hash)
203-
Gets the salt portion from a hash.
204-
205-
| Name | Type | Description |
206-
| ---- | ---- | ----------- |
207-
| hash | string | Hash to extract the salt from |
208-
| |||
209-
| **returns** | string | Extracted salt part portion
210-
| **throws** | Error | If `hash` is not a string or otherwise invalid
195+
| Parameter | Type | Description
196+
|-----------------|-----------------|---------------
197+
| hash | *string* | Hash to extract the used number of rounds from
198+
| **@returns** | *number* | Number of rounds used
199+
| **@throws** | *Error* | If hash is not a string
200+
201+
### getSalt(hash)
202+
203+
Gets the salt portion from a hash. Does not validate the hash.
204+
205+
| Parameter | Type | Description
206+
|-----------------|-----------------|---------------
207+
| hash | *string* | Hash to extract the salt from
208+
| **@returns** | *string* | Extracted salt part
209+
| **@throws** | *Error* | If `hash` is not a string or otherwise invalid
210+
211211

212212
Command line
213213
------------

0 commit comments

Comments
 (0)