| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 37085f8 commit c0dd022
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -848,6 +848,9 @@ added: v0.1.94 | |||
| 848 | 848 | If `outputEncoding` is specified, a string is | |
| 849 | 849 | returned. If an `outputEncoding` is not provided, a [`Buffer`][] is returned. | |
| 850 | 850 | ||
| 851 | + If an output encoding was specified in a previous call to | ||
| 852 | + [`cipher.update()`][], `outputEncoding` must use the same encoding. | ||
| 853 | + | ||
| 851 | 854 | Once the `cipher.final()` method has been called, the `Cipheriv` object can no | |
| 852 | 855 | longer be used to encrypt data. Attempts to call `cipher.final()` more than | |
| 853 | 856 | once will result in an error being thrown. | |
@@ -940,6 +943,8 @@ The `outputEncoding` specifies the output format of the enciphered | |||
| 940 | 943 | data. If the `outputEncoding` | |
| 941 | 944 | is specified, a string using the specified encoding is returned. If no | |
| 942 | 945 | `outputEncoding` is provided, a [`Buffer`][] is returned. | |
| 946 | + When `outputEncoding` is specified, it must use the same encoding as previous | ||
| 947 | + calls to `cipher.update()`. | ||
| 943 | 948 | ||
| 944 | 949 | The `cipher.update()` method can be called multiple times with new data until | |
| 945 | 950 | [`cipher.final()`][] is called. Calling `cipher.update()` after | |
@@ -1158,6 +1163,9 @@ added: v0.1.94 | |||
| 1158 | 1163 | If `outputEncoding` is specified, a string is | |
| 1159 | 1164 | returned. If an `outputEncoding` is not provided, a [`Buffer`][] is returned. | |
| 1160 | 1165 | ||
| 1166 | + If an output encoding was specified in a previous call to | ||
| 1167 | + [`decipher.update()`][], `outputEncoding` must use the same encoding. | ||
| 1168 | + | ||
| 1161 | 1169 | Once the `decipher.final()` method has been called, the `Decipheriv` object can | |
| 1162 | 1170 | no longer be used to decrypt data. Attempts to call `decipher.final()` more | |
| 1163 | 1171 | than once will result in an error being thrown. | |
@@ -1294,6 +1302,8 @@ The `outputEncoding` specifies the output format of the enciphered | |||
| 1294 | 1302 | data. If the `outputEncoding` | |
| 1295 | 1303 | is specified, a string using the specified encoding is returned. If no | |
| 1296 | 1304 | `outputEncoding` is provided, a [`Buffer`][] is returned. | |
| 1305 | + When `outputEncoding` is specified, it must use the same encoding as previous | ||
| 1306 | + calls to `decipher.update()`. | ||
| 1297 | 1307 | ||
| 1298 | 1308 | The `decipher.update()` method can be called multiple times with new data until | |
| 1299 | 1309 | [`decipher.final()`][] is called. Calling `decipher.update()` after | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -54,8 +54,6 @@ const { | |||
| 54 | 54 | isArrayBufferView, | |
| 55 | 55 | } = require('internal/util/types'); | |
| 56 | 56 | ||
| 57 | - const assert = require('internal/assert'); | ||
| 58 | - | ||
| 59 | 57 | const LazyTransform = require('internal/streams/lazy_transform'); | |
| 60 | 58 | ||
| 61 | 59 | const { normalizeEncoding } = require('internal/util'); | |
@@ -98,7 +96,11 @@ function getDecoder(decoder, encoding) { | |||
| 98 | 96 | if (normalizedEncoding === undefined) { | |
| 99 | 97 | throw new ERR_UNKNOWN_ENCODING(encoding); | |
| 100 | 98 | } | |
| 101 | - assert.fail('Cannot change encoding'); | ||
| 99 | + throw new ERR_INVALID_ARG_VALUE( | ||
| 100 | + 'outputEncoding', | ||
| 101 | + encoding, | ||
| 102 | + `cannot be changed from '${decoder.encoding}'`, | ||
| 103 | + ); | ||
| 102 | 104 | } | |
| 103 | 105 | return decoder; | |
| 104 | 106 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -12,13 +12,19 @@ const createCipher = () => { | |||
| 12 | 12 | return createCipheriv('aes-256-cbc', randomBytes(32), randomBytes(16)); | |
| 13 | 13 | }; | |
| 14 | 14 | ||
| 15 | + const encodingChangeError = { | ||
| 16 | + code: 'ERR_INVALID_ARG_VALUE', | ||
| 17 | + name: 'TypeError', | ||
| 18 | + message: /cannot be changed from 'utf8'/, | ||
| 19 | + }; | ||
| 20 | + | ||
| 15 | 21 | { | |
| 16 | 22 | const cipher = createCipher(); | |
| 17 | 23 | cipher.update('test', 'utf-8', 'utf-8'); | |
| 18 | 24 | ||
| 19 | 25 | assert.throws( | |
| 20 | 26 | () => cipher.update('666f6f', 'hex', 'hex'), | |
| 21 | - { message: /Cannot change encoding/ } | ||
| 27 | + encodingChangeError | ||
| 22 | 28 | ); | |
| 23 | 29 | } | |
| 24 | 30 | ||
@@ -28,7 +34,7 @@ const createCipher = () => { | |||
| 28 | 34 | ||
| 29 | 35 | assert.throws( | |
| 30 | 36 | () => cipher.final('hex'), | |
| 31 | - { message: /Cannot change encoding/ } | ||
| 37 | + encodingChangeError | ||
| 32 | 38 | ); | |
| 33 | 39 | } | |
| 34 | 40 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments