File tree Expand file tree Collapse file tree 2 files changed +11
-3
lines changed Expand file tree Collapse file tree 2 files changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,8 @@ const HASH_FUNCTION = "sha512";
1010export const INVALID_DECRYPTION_MESSAGE =
1111 "Could not decrypt data (check that the encryption secret is correct)." ;
1212
13+ export const CORRUPTED_DATA_MESSAGE = "Encrypted data is corrupted." ;
14+
1315export function encrypt ( {
1416 plaintext,
1517 encryptionSecret,
@@ -72,7 +74,7 @@ export function decrypt({
7274 const candidate = decryptedBuffer . toString ( "utf8" ) ;
7375 if ( candidate . substring ( 0 , VALID_PREFIX . length ) !== VALID_PREFIX ) {
7476 throw new DecryptionError ( {
75- message : "Encrypted data is corrupted." ,
77+ message : CORRUPTED_DATA_MESSAGE ,
7678 } ) ;
7779 }
7880 return candidate . substring ( VALID_PREFIX . length , candidate . length ) ;
Original file line number Diff line number Diff line change 11import { DecryptionError } from "common/errors/index.js" ;
22import type RedisModule from "ioredis" ;
33import { z } from "zod" ;
4- import { decrypt , encrypt , INVALID_DECRYPTION_MESSAGE } from "./encryption.js" ;
4+ import {
5+ CORRUPTED_DATA_MESSAGE ,
6+ decrypt ,
7+ encrypt ,
8+ INVALID_DECRYPTION_MESSAGE ,
9+ } from "./encryption.js" ;
510import type pino from "pino" ;
611import { type FastifyBaseLogger } from "fastify" ;
712
@@ -53,7 +58,8 @@ export async function getKey<T extends object>({
5358 } catch ( e ) {
5459 if (
5560 e instanceof DecryptionError &&
56- e . message === INVALID_DECRYPTION_MESSAGE
61+ ( e . message === INVALID_DECRYPTION_MESSAGE ||
62+ e . message === CORRUPTED_DATA_MESSAGE )
5763 ) {
5864 logger . info (
5965 `Invalid decryption, deleting old Redis key and continuing...` ,
You can’t perform that action at this time.
0 commit comments