-
Notifications
You must be signed in to change notification settings - Fork 30.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cipher: add cipher update/final methods encoding validation
Adds encoding validation to update and final cipher methods. #45189
- Loading branch information
1 parent
34af1f6
commit d1c165e
Showing
6 changed files
with
79 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
if (!common.hasCrypto) | ||
common.skip('missing crypto'); | ||
|
||
// This test checks if error is thrown in case of wrong encoding provided into cipher. | ||
|
||
const assert = require('assert'); | ||
const { createCipheriv, randomBytes } = require('crypto'); | ||
|
||
const createCipher = () => { | ||
return createCipheriv('aes-256-cbc', randomBytes(32), randomBytes(16)); | ||
}; | ||
|
||
{ | ||
const cipher = createCipher(); | ||
|
||
assert.throws( | ||
() => cipher.update('test', 'bad1', 'hex'), | ||
{ message: /^Unknown encoding bad1$/ } | ||
); | ||
} | ||
|
||
{ | ||
const cipher = createCipher(); | ||
cipher.update('test', 'utf-8', 'utf-8'); | ||
|
||
assert.throws( | ||
() => cipher.final('bad2'), | ||
{ message: /^Unknown encoding bad2$/ } | ||
); | ||
} | ||
|
||
{ | ||
const cipher = createCipher(); | ||
|
||
assert.throws( | ||
() => cipher.update('test', 'utf-8', 'bad3'), | ||
{ message: /^Unknown encoding bad3$/ } | ||
); | ||
} |