* Performs encode or decode on given content. * @protected * @param {Chain} content * @param {boolean} isEncode True for encoding, false for decoding * @return {number[]|string|Uint8Array|Chain|Promise} Resulting content
(content, isEncode)
| 173 | * @return {number[]|string|Uint8Array|Chain|Promise} Resulting content |
| 174 | */ |
| 175 | async performTranslate (content, isEncode) { |
| 176 | const message = content.getBytes() |
| 177 | const { algorithm, mode, key, padding, iv } = this.getSettingValues() |
| 178 | |
| 179 | try { |
| 180 | // Try to encrypt or decrypt |
| 181 | return await this.createCipher( |
| 182 | algorithm, mode, key, iv, padding, isEncode, message) |
| 183 | } catch (err) { |
| 184 | // Catch invalid input errors |
| 185 | if (!isEncode) { |
| 186 | throw new InvalidInputError( |
| 187 | `${algorithm} decryption failed, ` + |
| 188 | 'this may be due to malformed content') |
| 189 | } else { |
| 190 | throw new InvalidInputError(`${algorithm} encryption failed`) |
| 191 | } |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | /** |
| 196 | * Creates message cipher using given algorithm. |
nothing calls this directly
no test coverage detected