(rounds, seed_length)
| 85 | * @throws {Error} If a random fallback is required but not set |
| 86 | */ |
| 87 | export function genSaltSync(rounds, seed_length) { |
| 88 | rounds = rounds || GENSALT_DEFAULT_LOG2_ROUNDS; |
| 89 | if (typeof rounds !== "number") |
| 90 | throw Error( |
| 91 | "Illegal arguments: " + typeof rounds + ", " + typeof seed_length, |
| 92 | ); |
| 93 | if (rounds < 4) rounds = 4; |
| 94 | else if (rounds > 31) rounds = 31; |
| 95 | var salt = []; |
| 96 | salt.push("$2b$"); |
| 97 | if (rounds < 10) salt.push("0"); |
| 98 | salt.push(rounds.toString()); |
| 99 | salt.push("$"); |
| 100 | salt.push(base64_encode(randomBytes(BCRYPT_SALT_LEN), BCRYPT_SALT_LEN)); // May throw |
| 101 | return salt.join(""); |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * Asynchronously generates a salt. |
no test coverage detected