Skip to content

Commit 946a326

Browse files
committed
check all
1 parent c1b80e2 commit 946a326

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/api/functions/encryption.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ const HASH_FUNCTION = "sha512";
1010
export 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+
1315
export 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);

src/api/functions/redisCache.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import { DecryptionError } from "common/errors/index.js";
22
import type RedisModule from "ioredis";
33
import { 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";
510
import type pino from "pino";
611
import { 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...`,

0 commit comments

Comments
 (0)