Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance Cipheriv, Decipheriv coverage #17458

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions test/parallel/test-crypto-cipheriv-decipheriv.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

createCipheriv

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line cannot use createCipheriv because createCipheriv calls constructor with new keyword always.
I want to test call constructor without new keyword.

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');
Expand Down