27 lines
832 B
TypeScript
27 lines
832 B
TypeScript
|
import * as bcrypt from "https://deno.land/x/bcrypt@v0.4.1/mod.ts";
|
||
|
|
||
|
export interface Crypto {
|
||
|
hash(value: string): Promise<string>;
|
||
|
compare(value: string, hash: string): Promise<boolean>;
|
||
|
}
|
||
|
|
||
|
export class BcryptCrypto implements Crypto {
|
||
|
public hash(value: string): Promise<string> {
|
||
|
return bcrypt.hash(value);
|
||
|
}
|
||
|
public compare(value: string, hash: string): Promise<boolean> {
|
||
|
return bcrypt.compare(value, hash);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
export class MockCrypto implements Crypto {
|
||
|
// deno-lint-ignore require-await
|
||
|
public async hash(value: string): Promise<string> {
|
||
|
return bcrypt.hashSync(value, bcrypt.genSaltSync(4));
|
||
|
}
|
||
|
// deno-lint-ignore require-await
|
||
|
public async compare(value: string, hash: string): Promise<boolean> {
|
||
|
return bcrypt.compareSync(value, hash);
|
||
|
}
|
||
|
}
|