test: improve coverage for Cipheriv and Decipheriv
PR-URL: https://github.com/nodejs/node/pull/17458 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Jon Moss <me@jonathanmoss.me> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
This commit is contained in:
parent
84b7a86786
commit
6707903fae
@ -78,6 +78,78 @@ function testCipher3(key, iv) {
|
||||
`encryption/decryption with key ${key} and iv ${iv}`);
|
||||
}
|
||||
|
||||
{
|
||||
const Cipheriv = crypto.Cipheriv;
|
||||
const key = '123456789012345678901234';
|
||||
const iv = '12345678';
|
||||
|
||||
const instance = Cipheriv('des-ede3-cbc', key, iv);
|
||||
assert(instance instanceof Cipheriv, 'Cipheriv is expected to return a new ' +
|
||||
'instance when called without `new`');
|
||||
|
||||
common.expectsError(
|
||||
() => crypto.createCipheriv(null),
|
||||
{
|
||||
code: 'ERR_INVALID_ARG_TYPE',
|
||||
type: TypeError,
|
||||
message: 'The "cipher" argument must be of type string'
|
||||
});
|
||||
|
||||
common.expectsError(
|
||||
() => crypto.createCipheriv('des-ede3-cbc', null),
|
||||
{
|
||||
code: 'ERR_INVALID_ARG_TYPE',
|
||||
type: TypeError,
|
||||
message: 'The "key" argument must be one of type string, Buffer, ' +
|
||||
'TypedArray, or DataView'
|
||||
});
|
||||
|
||||
common.expectsError(
|
||||
() => crypto.createCipheriv('des-ede3-cbc', key, null),
|
||||
{
|
||||
code: 'ERR_INVALID_ARG_TYPE',
|
||||
type: TypeError,
|
||||
message: 'The "iv" argument must be one of type string, Buffer, ' +
|
||||
'TypedArray, or DataView'
|
||||
});
|
||||
}
|
||||
|
||||
{
|
||||
const Decipheriv = crypto.Decipheriv;
|
||||
const key = '123456789012345678901234';
|
||||
const iv = '12345678';
|
||||
|
||||
const instance = Decipheriv('des-ede3-cbc', key, iv);
|
||||
assert(instance instanceof Decipheriv, 'Decipheriv expected to return a new' +
|
||||
' instance when called without `new`');
|
||||
|
||||
common.expectsError(
|
||||
() => crypto.createDecipheriv(null),
|
||||
{
|
||||
code: 'ERR_INVALID_ARG_TYPE',
|
||||
type: TypeError,
|
||||
message: 'The "cipher" argument must be of type string'
|
||||
});
|
||||
|
||||
common.expectsError(
|
||||
() => crypto.createDecipheriv('des-ede3-cbc', null),
|
||||
{
|
||||
code: 'ERR_INVALID_ARG_TYPE',
|
||||
type: TypeError,
|
||||
message: 'The "key" argument must be one of type string, Buffer, ' +
|
||||
'TypedArray, or DataView'
|
||||
});
|
||||
|
||||
common.expectsError(
|
||||
() => crypto.createDecipheriv('des-ede3-cbc', key, null),
|
||||
{
|
||||
code: 'ERR_INVALID_ARG_TYPE',
|
||||
type: TypeError,
|
||||
message: 'The "iv" argument must be one of type string, Buffer, ' +
|
||||
'TypedArray, or DataView'
|
||||
});
|
||||
}
|
||||
|
||||
testCipher1('0123456789abcd0123456789', '12345678');
|
||||
testCipher1('0123456789abcd0123456789', Buffer.from('12345678'));
|
||||
testCipher1(Buffer.from('0123456789abcd0123456789'), '12345678');
|
||||
|
Loading…
x
Reference in New Issue
Block a user