Merge c10e1c44dde0f2963947903fbe19dd0526d2478d into 3c32e3f64de0c5fd60c25cdf7219640c099d04d6

This commit is contained in:
Anushka 2026-07-02 09:13:42 +01:00 committed by GitHub
commit 1157b0f62d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 33 additions and 12 deletions

View File

@ -5,6 +5,7 @@
*/
import Operation from "../Operation.mjs";
import OperationError from "../errors/OperationError.mjs";
import bcrypt from "bcryptjs";
import { isWorkerEnvironment } from "../Utils.mjs";
@ -41,13 +42,17 @@ class Bcrypt extends Operation {
*/
async run(input, args) {
const rounds = args[0];
const salt = await bcrypt.genSalt(rounds);
try {
const salt = await bcrypt.genSalt(rounds);
return await bcrypt.hash(input, salt, undefined, p => {
// Progress callback
if (isWorkerEnvironment())
self.sendStatusMessage(`Progress: ${(p * 100).toFixed(0)}%`);
});
return await bcrypt.hash(input, salt, undefined, p => {
// Progress callback
if (isWorkerEnvironment())
self.sendStatusMessage(`Progress: ${(p * 100).toFixed(0)}%`);
});
} catch (err) {
throw new OperationError(err.toString());
}
}

View File

@ -5,6 +5,7 @@
*/
import Operation from "../Operation.mjs";
import OperationError from "../errors/OperationError.mjs";
import bcrypt from "bcryptjs";
import { isWorkerEnvironment } from "../Utils.mjs";
@ -43,13 +44,17 @@ class BcryptCompare extends Operation {
async run(input, args) {
const hash = args[0];
const match = await bcrypt.compare(input, hash, undefined, p => {
// Progress callback
if (isWorkerEnvironment())
self.sendStatusMessage(`Progress: ${(p * 100).toFixed(0)}%`);
});
try {
const match = await bcrypt.compare(input, hash, undefined, p => {
// Progress callback
if (isWorkerEnvironment())
self.sendStatusMessage(`Progress: ${(p * 100).toFixed(0)}%`);
});
return match ? "Match: " + input : "No match";
return match ? "Match: " + input : "No match";
} catch (err) {
throw new OperationError(err.toString());
}
}

View File

@ -993,6 +993,17 @@ TestRegister.addTests([
}
]
},
{
name: "Bcrypt compare: invalid rounds",
input: "hello",
expectedOutput: "Error: Illegal number of rounds (4-31): 34",
recipeConfig: [
{
op: "Bcrypt compare",
args: ["$2b$34$K.H1WlFDQ/iIo/PiprT/puwluJ5rzuSE5q8D/Fk3NuLgU2aXiGR9m"]
}
]
},
{
name: "Scrypt: RFC test vector 1",
input: "",