mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 21:19:50 +01:00
5a7d4a774d
Refs #45189 PR-URL: https://github.com/nodejs/node/pull/45990 Refs: https://github.com/nodejs/node/issues/45189 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Filip Skokan <panva.ip@gmail.com>
53 lines
1.1 KiB
JavaScript
53 lines
1.1 KiB
JavaScript
'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();
|
|
cipher.update('test', 'utf-8', 'utf-8');
|
|
|
|
assert.throws(
|
|
() => cipher.update('666f6f', 'hex', 'hex'),
|
|
{ message: /Cannot change encoding/ }
|
|
);
|
|
}
|
|
|
|
{
|
|
const cipher = createCipher();
|
|
cipher.update('test', 'utf-8', 'utf-8');
|
|
|
|
assert.throws(
|
|
() => cipher.final('hex'),
|
|
{ message: /Cannot change encoding/ }
|
|
);
|
|
}
|
|
|
|
{
|
|
const cipher = createCipher();
|
|
cipher.update('test', 'utf-8', 'utf-8');
|
|
|
|
assert.throws(
|
|
() => cipher.final('bad2'),
|
|
{ message: /^Unknown encoding: bad2$/, code: 'ERR_UNKNOWN_ENCODING' }
|
|
);
|
|
}
|
|
|
|
{
|
|
const cipher = createCipher();
|
|
|
|
assert.throws(
|
|
() => cipher.update('test', 'utf-8', 'bad3'),
|
|
{ message: /^Unknown encoding: bad3$/, code: 'ERR_UNKNOWN_ENCODING' }
|
|
);
|
|
}
|