From bd53f59440a267d1f3f1a55535b846a55c9be811 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branislav=20Hol=C3=BD?= Date: Tue, 18 Sep 2018 21:16:57 +0200 Subject: [PATCH] [bcryptjs] Add missing base64 functions --- types/bcryptjs/bcryptjs-tests.ts | 5 +++++ types/bcryptjs/index.d.ts | 22 ++++++++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/types/bcryptjs/bcryptjs-tests.ts b/types/bcryptjs/bcryptjs-tests.ts index cd91eb4896..2fc9f0bc0c 100644 --- a/types/bcryptjs/bcryptjs-tests.ts +++ b/types/bcryptjs/bcryptjs-tests.ts @@ -3,6 +3,7 @@ import bcryptjs = require("bcryptjs"); let str: string; let num: number; let bool: boolean; +let arr: number[]; let error: Error; str = bcryptjs.genSaltSync(); @@ -63,3 +64,7 @@ bcryptjs.compare("string1", "string2") num = bcryptjs.getRounds("string"); str = bcryptjs.getSalt("string"); + +str = bcryptjs.encodeBase64([1, 2, 3, 4, 5], 5); + +arr = bcryptjs.decodeBase64("string", 5); diff --git a/types/bcryptjs/index.d.ts b/types/bcryptjs/index.d.ts index b19413c92d..f04cd68834 100644 --- a/types/bcryptjs/index.d.ts +++ b/types/bcryptjs/index.d.ts @@ -1,8 +1,10 @@ // Type definitions for bcryptjs v2.4.0 // Project: https://github.com/dcodeIO/bcrypt.js -// Definitions by: Joshua Filby , Rafael Kraut +// Definitions by: Joshua Filby +// Rafael Kraut +// Branislav HolĂ˝ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped - +// TypeScript Version: 2.1 /** @@ -103,3 +105,19 @@ export declare function getRounds(hash: string): number; * @return Extracted salt part */ export declare function getSalt(hash: string): string; + +/** + * Encodes a byte array to base64 with up to len bytes of input, using the custom bcrypt alphabet. + * @function + * @param b Byte array + * @param len Maximum input length + */ +export declare function encodeBase64(b: Readonly>, len: number): string; + +/** + * Decodes a base64 encoded string to up to len bytes of output, using the custom bcrypt alphabet. + * @function + * @param s String to decode + * @param len Maximum output length + */ +export declare function decodeBase64(s: string, len: number): number[];