From 0eeb638c8938737698bb258f09f038145905ad7d Mon Sep 17 00:00:00 2001 From: John Jeffery Date: Sun, 5 Oct 2014 09:27:32 +1000 Subject: [PATCH] Fix bug: crypto.Decipher#update() returns string, not void --- node/node-tests.ts | 14 ++++++++++++++ node/node.d.ts | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/node/node-tests.ts b/node/node-tests.ts index a8475a8dc..c944e168d 100644 --- a/node/node-tests.ts +++ b/node/node-tests.ts @@ -99,6 +99,20 @@ function stream_readable_pipe_test() { var hmacResult: string = crypto.createHmac('md5', 'hello').update('world').digest('hex'); +function crypto_cipher_decipher_string_test() { + var key:Buffer = new Buffer([1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7]); + var clearText:string = "This is the clear text."; + var cipher:crypto.Cipher = crypto.createCipher("aes-128-ecb", key); + var cipherText:string = cipher.update(clearText, "utf8", "hex"); + cipherText += cipher.final("hex"); + + var decipher:crypto.Decipher = crypto.createDecipher("aes-128-ecb", key); + var clearText2:string = decipher.update(cipherText, "hex", "utf8"); + clearText2 += decipher.final("utf8"); + + assert.equal(clearText2, clearText); +} + //////////////////////////////////////////////////// // Make sure .listen() and .close() retuern a Server instance diff --git a/node/node.d.ts b/node/node.d.ts index 7893f6fc6..0293ebae2 100644 --- a/node/node.d.ts +++ b/node/node.d.ts @@ -1083,7 +1083,7 @@ declare module "crypto" { export function createDecipher(algorithm: string, password: any): Decipher; export function createDecipheriv(algorithm: string, key: any, iv: any): Decipher; interface Decipher { - update(data: any, input_encoding?: string, output_encoding?: string): void; + update(data: any, input_encoding?: string, output_encoding?: string): string; final(output_encoding?: string): string; setAutoPadding(auto_padding: boolean): void; }