-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
Enhance Cipher, Decipher coverage #17449
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
Changes from 9 commits
3495998
24553fa
569099c
bb5c70d
ab7a803
8c60d1d
435bd16
4ebbe67
f15c054
b503bd5
9a809ff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -70,6 +70,81 @@ testCipher1(Buffer.from('MySecretKey123')); | |
| testCipher2('0123456789abcdef'); | ||
| testCipher2(Buffer.from('0123456789abcdef')); | ||
|
|
||
| { | ||
| const Cipher = crypto.Cipher; | ||
| const instance = crypto.Cipher('aes-256-cbc', 'secret'); | ||
| assert(instance instanceof Cipher, 'Cipher is expected to return a new ' + | ||
| 'instance when called without `new`'); | ||
|
|
||
| common.expectsError( | ||
| () => new Cipher(null), | ||
| { | ||
| code: 'ERR_INVALID_ARG_TYPE', | ||
| type: TypeError, | ||
| message: 'The "cipher" argument must be of type string' | ||
| }); | ||
|
|
||
| common.expectsError( | ||
| () => new Cipher('aes-256-cbc', null), | ||
| { | ||
| code: 'ERR_INVALID_ARG_TYPE', | ||
| type: TypeError, | ||
| message: 'The "password" argument must be one of type string, Buffer, ' + | ||
| 'TypedArray, or DataView' | ||
| }); | ||
|
|
||
| common.expectsError( | ||
| () => new Cipher('aes-256-cbc', 'secret').update(null), | ||
| { | ||
| code: 'ERR_INVALID_ARG_TYPE', | ||
| type: TypeError, | ||
| message: 'The "data" argument must be one of type string, Buffer, ' + | ||
| 'TypedArray, or DataView' | ||
| }); | ||
|
|
||
| common.expectsError( | ||
| () => new Cipher('aes-256-cbc', 'secret').setAuthTag(null), | ||
| { | ||
| code: 'ERR_INVALID_ARG_TYPE', | ||
| type: TypeError, | ||
| message: 'The "buffer" argument must be one of type Buffer, ' + | ||
| 'TypedArray, or DataView' | ||
| }); | ||
|
|
||
| common.expectsError( | ||
| () => new Cipher('aes-256-cbc', 'secret').setAAD(null), | ||
| { | ||
| code: 'ERR_INVALID_ARG_TYPE', | ||
| type: TypeError, | ||
| message: 'The "buffer" argument must be one of type Buffer, ' + | ||
| 'TypedArray, or DataView' | ||
| }); | ||
| } | ||
|
|
||
| { | ||
| const Decipher = crypto.Decipher; | ||
| const instance = crypto.Decipher('aes-256-cbc', 'secret'); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| assert(instance instanceof Decipher, 'Decipher is expected to return a new ' + | ||
| 'instance when called without `new`'); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: indent once more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I made a silly mistake. |
||
|
|
||
| common.expectsError( | ||
| () => new Decipher(null), | ||
| { | ||
| code: 'ERR_INVALID_ARG_TYPE', | ||
| type: TypeError, | ||
| message: 'The "cipher" argument must be of type string' | ||
| }); | ||
|
|
||
| common.expectsError( | ||
| () => new Decipher('aes-256-cbc', null), | ||
| { | ||
| code: 'ERR_INVALID_ARG_TYPE', | ||
| type: TypeError, | ||
| message: 'The "password" argument must be one of type string, Buffer, ' + | ||
| 'TypedArray, or DataView' | ||
| }); | ||
| } | ||
|
|
||
| // Base64 padding regression test, see #4837. | ||
| { | ||
| const c = crypto.createCipher('aes-256-cbc', 'secret'); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
createCipherThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same adobe #17458 (comment)