mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-07 23:37:35 +08:00
[node] [crypto] Added missing crypto update types
* Added DataView as type of crypto update functions
This commit is contained in:
@@ -857,9 +857,39 @@ function simplified_stream_ctor_test() {
|
||||
|
||||
namespace crypto_tests {
|
||||
{
|
||||
// crypto_hash_string_test
|
||||
var hashResult: string = crypto.createHash('md5').update('world').digest('hex');
|
||||
}
|
||||
|
||||
{
|
||||
// crypto_hash_buffer_test
|
||||
var hashResult: string = crypto.createHash('md5')
|
||||
.update(new Buffer('world')).digest('hex');
|
||||
}
|
||||
|
||||
{
|
||||
// crypto_hash_dataview_test
|
||||
var hashResult: string = crypto.createHash('md5')
|
||||
.update(new DataView(new Buffer('world').buffer)).digest('hex');
|
||||
}
|
||||
|
||||
{
|
||||
// crypto_hmac_string_test
|
||||
var hmacResult: string = crypto.createHmac('md5', 'hello').update('world').digest('hex');
|
||||
}
|
||||
|
||||
{
|
||||
// crypto_hmac_buffer_test
|
||||
var hmacResult: string = crypto.createHmac('md5', 'hello')
|
||||
.update(new Buffer('world')).digest('hex');
|
||||
}
|
||||
|
||||
{
|
||||
// crypto_hmac_dataview_test
|
||||
var hmacResult: string = crypto.createHmac('md5', 'hello')
|
||||
.update(new DataView(new Buffer('world').buffer)).digest('hex');
|
||||
}
|
||||
|
||||
{
|
||||
let hmac: crypto.Hmac;
|
||||
(hmac = crypto.createHmac('md5', 'hello')).end('world', 'utf8', () => {
|
||||
@@ -903,6 +933,28 @@ namespace crypto_tests {
|
||||
assert.deepEqual(clearText2, clearText);
|
||||
}
|
||||
|
||||
{
|
||||
// crypto_cipher_decipher_dataview_test
|
||||
let key: Buffer = new Buffer([1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7]);
|
||||
let clearText: DataView = new DataView(
|
||||
new Buffer([1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4]).buffer);
|
||||
let cipher: crypto.Cipher = crypto.createCipher("aes-128-ecb", key);
|
||||
let cipherBuffers: Buffer[] = [];
|
||||
cipherBuffers.push(cipher.update(clearText));
|
||||
cipherBuffers.push(cipher.final());
|
||||
|
||||
let cipherText: DataView = new DataView(Buffer.concat(cipherBuffers).buffer);
|
||||
|
||||
let decipher: crypto.Decipher = crypto.createDecipher("aes-128-ecb", key);
|
||||
let decipherBuffers: Buffer[] = [];
|
||||
decipherBuffers.push(decipher.update(cipherText));
|
||||
decipherBuffers.push(decipher.final());
|
||||
|
||||
let clearText2: Buffer = Buffer.concat(decipherBuffers);
|
||||
|
||||
assert.deepEqual(clearText2, clearText);
|
||||
}
|
||||
|
||||
{
|
||||
let buffer1: Buffer = new Buffer([1, 2, 3, 4, 5]);
|
||||
let buffer2: Buffer = new Buffer([1, 2, 3, 4, 5]);
|
||||
|
||||
Reference in New Issue
Block a user