fix(bcrypt-nodejs): allow null as hash progress callback (#42041)

- fixes async hash definition bug
- update module definition syntax
- update configuration to match latest DT specs

Thanks!
This commit is contained in:
Piotr Błażejewicz (Peter Blazejewicz) 2020-02-07 00:01:04 +01:00 committed by GitHub
parent 3731df0fc2
commit 1e566e7f37
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 48 additions and 111 deletions

View File

@ -1,29 +1,40 @@
import bCrypt = require("bcrypt-nodejs");
import bcrypt = require('bcrypt-nodejs');
function test_sync() {
var salt1 = bCrypt.genSaltSync();
var salt2 = bCrypt.genSaltSync(8);
const salt1 = bcrypt.genSaltSync();
const salt2 = bcrypt.genSaltSync(8);
var hash1 = bCrypt.hashSync('super secret');
var hash2 = bCrypt.hashSync('super secret', salt1);
const hash1 = bcrypt.hashSync('super secret');
const hash2 = bcrypt.hashSync('super secret', salt1);
var compare1 = bCrypt.compareSync('super secret', hash1);
const compare1 = bcrypt.compareSync('super secret', hash1);
var rounds1 = bCrypt.getRounds(hash2);
const rounds1 = bcrypt.getRounds(hash2);
}
function test_async() {
var cbString = (error: Error, result: string) => {};
var cbVoid = () => {};
var cbBoolean = (error: Error, result: boolean) => {};
const cbString = (error: Error, result: string) => {};
const cbVoid = () => {};
const cbBoolean = (error: Error, result: boolean) => {};
bCrypt.genSalt(8, cbString);
bcrypt.genSalt(8, cbString);
var salt = bCrypt.genSaltSync();
bCrypt.hash('super secret', salt, cbString);
bCrypt.hash('super secret', salt, cbVoid, cbString);
const salt = bcrypt.genSaltSync();
bcrypt.hash('super secret', salt, cbString);
bcrypt.hash('super secret', salt, cbVoid, cbString);
var hash = bCrypt.hashSync('super secret');
bCrypt.compare('super secret', hash, cbBoolean);
}
const hash = bcrypt.hashSync('super secret');
bcrypt.compare('super secret', hash, cbBoolean);
bcrypt.hash('bacon', salt, null, (err, hash) => {
// Store hash in your password DB.
});
// Load hash from your password DB.
bcrypt.compare('bacon', hash, (err, res) => {
// res == true
});
bcrypt.compare('veggies', hash, (err, res) => {
// res = false
});
}

View File

@ -1,22 +1,22 @@
// Type definitions for bcrypt-nodejs
// Type definitions for bcrypt-nodejs 0.0
// Project: https://github.com/shaneGirish/bcrypt-nodejs
// Definitions by: David Broder-Rodgers <https://github.com/DavidBR-SW/>
// Definitions by: David Broder-Rodgers <https://github.com/DavidBR-SW>
// Piotr Błażejewicz <https://github.com/peterblazejewicz>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/**
* Generate a salt synchronously
* @param rounds Number of rounds to process the data for (default - 10)
* @return Generated salt
*/
export declare function genSaltSync(rounds?: number): string;
export function genSaltSync(rounds?: number): string;
/**
* Generate a salt asynchronously
* @param rounds Number of rounds to process the data for (default - 10)
* @param callback Callback with error and resulting salt, to be fired once the salt has been generated
*/
export declare function genSalt(rounds: number, callback: (error: Error, result: string) => void): void;
export function genSalt(rounds: number, callback: (error: Error, result: string) => void): void;
/**
* Generate a hash synchronously
@ -24,7 +24,7 @@ export declare function genSalt(rounds: number, callback: (error: Error, result:
* @param salt Salt to be used in encryption (default - new salt generated with 10 rounds)
* @return Generated hash
*/
export declare function hashSync(data: string, salt?: string): string;
export function hashSync(data: string, salt?: string): string;
/**
* Generate a hash asynchronously
@ -32,7 +32,7 @@ export declare function hashSync(data: string, salt?: string): string;
* @param salt Salt to be used in encryption
* @param callback Callback with error and hashed result, to be fired once the data has been encrypted
*/
export declare function hash(data: string, salt: string, callback: (error: Error, result: string) => void): void;
export function hash(data: string, salt: string, callback: (error: Error, result: string) => void): void;
/**
* Generate a hash asynchronously
@ -41,7 +41,12 @@ export declare function hash(data: string, salt: string, callback: (error: Error
* @param progressCallback Callback to be fired multiple times during the hash calculation to signify progress
* @param callback Callback with error and hashed result, to be fired once the data has been encrypted
*/
export declare function hash(data: string, salt: string, progressCallback: () => void, callback: (error: Error, result: string) => void): void;
export function hash(
data: string,
salt: string,
progressCallback: null | (() => void),
callback: (error: Error, result: string) => void,
): void;
/**
* Compares data with a hash synchronously
@ -49,7 +54,7 @@ export declare function hash(data: string, salt: string, progressCallback: () =>
* @param hash Hash to be compared to
* @return true if matching, false otherwise
*/
export declare function compareSync(data: string, hash: string): boolean;
export function compareSync(data: string, hash: string): boolean;
/**
* Compares data with a hash asynchronously
@ -57,11 +62,11 @@ export declare function compareSync(data: string, hash: string): boolean;
* @param hash Hash to be compared to
* @param callback Callback with error and match result, to be fired once the data has been compared
*/
export declare function compare(data: string, hash: string, callback: (error: Error, result: boolean) => void): void;
export function compare(data: string, hash: string, callback: (error: Error, result: boolean) => void): void;
/**
* Get number of rounds used for hash
* @param hash Hash from which the number of rounds used should be extracted
* @return number of rounds used to encrypt a given hash
*/
export declare function getRounds(hash: string): number;
export function getRounds(hash: string): number;

View File

@ -6,8 +6,8 @@
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": false,
"strictFunctionTypes": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
@ -20,4 +20,4 @@
"index.d.ts",
"bcrypt-nodejs-tests.ts"
]
}
}

View File

@ -1,80 +1 @@
{
"extends": "dtslint/dt.json",
"rules": {
"adjacent-overload-signatures": false,
"array-type": false,
"arrow-return-shorthand": false,
"ban-types": false,
"callable-types": false,
"comment-format": false,
"dt-header": false,
"npm-naming": false,
"eofline": false,
"export-just-namespace": false,
"import-spacing": false,
"interface-name": false,
"interface-over-type-literal": false,
"jsdoc-format": false,
"max-line-length": false,
"member-access": false,
"new-parens": false,
"no-any-union": false,
"no-boolean-literal-compare": false,
"no-conditional-assignment": false,
"no-consecutive-blank-lines": false,
"no-construct": false,
"no-declare-current-package": false,
"no-duplicate-imports": false,
"no-duplicate-variable": false,
"no-empty-interface": false,
"no-for-in-array": false,
"no-inferrable-types": false,
"no-internal-module": false,
"no-irregular-whitespace": false,
"no-mergeable-namespace": false,
"no-misused-new": false,
"no-namespace": false,
"no-object-literal-type-assertion": false,
"no-padding": false,
"no-redundant-jsdoc": false,
"no-redundant-jsdoc-2": false,
"no-redundant-undefined": false,
"no-reference-import": false,
"no-relative-import-in-test": false,
"no-self-import": false,
"no-single-declare-module": false,
"no-string-throw": false,
"no-unnecessary-callback-wrapper": false,
"no-unnecessary-class": false,
"no-unnecessary-generics": false,
"no-unnecessary-qualifier": false,
"no-unnecessary-type-assertion": false,
"no-useless-files": false,
"no-var-keyword": false,
"no-var-requires": false,
"no-void-expression": false,
"no-trailing-whitespace": false,
"object-literal-key-quotes": false,
"object-literal-shorthand": false,
"one-line": false,
"one-variable-per-declaration": false,
"only-arrow-functions": false,
"prefer-conditional-expression": false,
"prefer-const": false,
"prefer-declare-function": false,
"prefer-for-of": false,
"prefer-method-signature": false,
"prefer-template": false,
"radix": false,
"semicolon": false,
"space-before-function-paren": false,
"space-within-parens": false,
"strict-export-declare-modifiers": false,
"trim-file": false,
"triple-equals": false,
"typedef-whitespace": false,
"unified-signatures": false,
"void-return": false,
"whitespace": false
}
}
{ "extends": "dtslint/dt.json" }