mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-23 04:49:15 +08:00
Add bcrypt definitions and tests.
This commit is contained in:
34
bcrypt/bcrypt-tests.ts
Normal file
34
bcrypt/bcrypt-tests.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
/// <reference path="bcrypt.d.ts" />
|
||||
|
||||
import bcrypt = require("bcrypt");
|
||||
|
||||
var num: number;
|
||||
var str: string;
|
||||
var bool: boolean;
|
||||
|
||||
str = bcrypt.genSaltSync();
|
||||
str = bcrypt.genSaltSync(num);
|
||||
|
||||
bcrypt.genSalt(function (err: Error, salt: string): void {
|
||||
str = salt;
|
||||
});
|
||||
bcrypt.genSalt(num, function (err: Error, salt: string): void {
|
||||
str = salt;
|
||||
});
|
||||
|
||||
str = bcrypt.hashSync(str, str);
|
||||
str = bcrypt.hashSync(str, num);
|
||||
|
||||
bcrypt.hash(str, str, function (err: Error, encrypted: string):void {
|
||||
str = encrypted;
|
||||
})
|
||||
bcrypt.hash(str, num, function (err: Error, encrypted: string): void {
|
||||
str = encrypted;
|
||||
});
|
||||
|
||||
bool = bcrypt.compareSync(str, str);
|
||||
bcrypt.compare(str, str, function (err: Error, same: boolean): void {
|
||||
bool = same;
|
||||
});
|
||||
|
||||
num = bcrypt.getRounds(str);
|
||||
65
bcrypt/bcrypt.d.ts
vendored
Normal file
65
bcrypt/bcrypt.d.ts
vendored
Normal file
@@ -0,0 +1,65 @@
|
||||
// Type definitions for bcrypt
|
||||
// Project: https://github.com/ncb000gt/node.bcrypt.js
|
||||
// Definitions by: Peter Harris <https://github.com/codeanimal>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
declare module "bcrypt" {
|
||||
/**
|
||||
* @param rounds The cost of processing the data. Default 10.
|
||||
*/
|
||||
export function genSaltSync(rounds?: number): string;
|
||||
|
||||
/**
|
||||
* @param rounds The cost of processing the data. Default 10.
|
||||
* @param callback A callback to be fire once the sald has been generated. Uses eio making it asynchronous.
|
||||
*/
|
||||
export function genSalt(rounds: number, callback: (err: Error, salt: string) => void): void;
|
||||
/**
|
||||
* @param callback A callback to be fire once the sald has been generated. Uses eio making it asynchronous.
|
||||
*/
|
||||
export function genSalt(callback: (err: Error, salt: string) => void): void;
|
||||
|
||||
/**
|
||||
* @param data The data to be encrypted.
|
||||
* @param salt The salt to be used in encryption.
|
||||
*/
|
||||
export function hashSync(data: any, salt: string): string;
|
||||
/**
|
||||
* @param data The data to be encrypted.
|
||||
* @param rounds A salt will be generated using the rounds specified.
|
||||
*/
|
||||
export function hashSync(data: any, rounds: number): string;
|
||||
|
||||
/**
|
||||
* @param data The data to be encrypted.
|
||||
* @param salt The salt to be used in encryption.
|
||||
* @param callback A callback to be fired once the data has been encrypted. Uses eio making it asynchronous.
|
||||
*/
|
||||
export function hash(data: any, salt: string, callback: (err: Error, encrypted: string) => void): void;
|
||||
/**
|
||||
* @param data The data to be encrypted.
|
||||
* @param rounds A salt will be generated using the rounds specified.
|
||||
* @param callback A callback to be fired once the data has been encrypted. Uses eio making it asynchronous.
|
||||
*/
|
||||
export function hash(data: any, rounds: number, callback: (err: Error, encrypted: string) => void): void;
|
||||
|
||||
/**
|
||||
* @param data The data to be encrypted.
|
||||
* @param encrypted The data to be compared against.
|
||||
*/
|
||||
export function compareSync(data: any, encrypted: string): boolean;
|
||||
|
||||
/**
|
||||
* @param data The data to be encrypted.
|
||||
* @param encrypted The data to be compared against.
|
||||
* @param callback A callback to be fire once the data has been compared. Uses eio making it asynchronous.
|
||||
*/
|
||||
export function compare(data: any, encrypted: string, callback: (err: Error, same: boolean) => void): void;
|
||||
|
||||
/**
|
||||
* Return the number of rounds used to encrypt a given hash
|
||||
*
|
||||
* @param encrypted Hash from which the number of rounds used should be extracted.
|
||||
*/
|
||||
export function getRounds(encrypted: string): number;
|
||||
}
|
||||
Reference in New Issue
Block a user