From 85f3a510463c0c60f84dd7a156103aab1bfa65f3 Mon Sep 17 00:00:00 2001 From: David Li Date: Sat, 7 Mar 2015 00:58:39 -0500 Subject: [PATCH] add: Definition and test for jsSHA Definition and test files for the jsSHA library at Signed-off-by: David Li --- jssha/jssha-tests.ts | 15 ++++++++++ jssha/jssha.d.ts | 65 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100755 jssha/jssha-tests.ts create mode 100755 jssha/jssha.d.ts diff --git a/jssha/jssha-tests.ts b/jssha/jssha-tests.ts new file mode 100755 index 000000000..8d6eec5a6 --- /dev/null +++ b/jssha/jssha-tests.ts @@ -0,0 +1,15 @@ +/// +/// + +var imported = require("jssha"); + +var shaObj1:jsSHA.jsSHA = new jsSHA("This is a Test", "TEXT", "UTF8"); +var shaObj2 = new imported("This is a Test", "TEXT"); + +var hash1:string = shaObj2.getHash("SHA-512", "HEX"); +var hash2:string = shaObj2.getHash("SHA-512", "HEX", 2); +var hash3:string = shaObj2.getHash("SHA-512", "HEX", 2, {outputUpper: false, b64Pad: "foobar"}); + +var format:jsSHA.OutputFormatOptions = {outputUpper: false, b64Pad: "foobar"}; +var hmac1 = shaObj2.getHMAC("SecretKey", "TEXT", "SHA-512", "HEX"); +var hmac2 = shaObj2.getHMAC("SecretKey", "TEXT", "SHA-512", "HEX", format); diff --git a/jssha/jssha.d.ts b/jssha/jssha.d.ts new file mode 100755 index 000000000..1c75c3862 --- /dev/null +++ b/jssha/jssha.d.ts @@ -0,0 +1,65 @@ +// Type definitions for jsSHA +// Project: https://github.com/Caligatio/jsSHA +// Definitions by: David Li +// Definitions: https://github.com/borisyankov/DefinitelyTyped + + +declare module jsSHA { + export interface OutputFormatOptions { + outputUpper : boolean; + b64Pad : string; + } + + export interface jsSHA { + /** + * jsSHA is the workhorse of the library. Instantiate it with the string to + * be hashed as the parameter + * + * @constructor + * @this {jsSHA} + * @param {string} srcString The string to be hashed + * @param {string} inputFormat The format of srcString, HEX, TEXT, B64, or BYTES + * @param {string=} encoding The text encoding to use to encode the source + * string + */ + new (srcString:string, inputFormat:string, encoding?:string):jsSHA; + + /** + * Returns the desired SHA hash of the string specified at instantiation + * using the specified parameters + * + * @param {string} variant The desired SHA variant (SHA-1, SHA-224, + * SHA-256, SHA-384, or SHA-512) + * @param {string} format The desired output formatting (B64, HEX, or BYTES) + * @param {number=} numRounds The number of rounds of hashing to be + * executed + * @param {{outputUpper : boolean, b64Pad : string}=} outputFormatOpts + * Hash list of output formatting options + * @return {string} The string representation of the hash in the format + * specified + */ + getHash(variant:string, format:string, numRounds?:number, outputFormatOpts?:OutputFormatOptions):string; + + /** + * Returns the desired HMAC of the string specified at instantiation + * using the key and variant parameter + * + * @param {string} key The key used to calculate the HMAC + * @param {string} inputFormat The format of key, HEX, TEXT, B64, or BYTES + * @param {string} variant The desired SHA variant (SHA-1, SHA-224, + * SHA-256, SHA-384, or SHA-512) + * @param {string} outputFormat The desired output formatting + * (B64, HEX, or BYTES) + * @param {{outputUpper : boolean, b64Pad : string}=} outputFormatOpts + * associative array of output formatting options + * @return {string} The string representation of the hash in the format + * specified + */ + getHMAC(key:string, inputFormat:string, variant:string, outputFormat:string, outputFormatOpts?:OutputFormatOptions):string; + } +} + +declare var jsSHA: jsSHA.jsSHA; +declare module 'jssha' { + export = jsSHA; +}