From 458307f5edce6effe57bb4f55c262e51e97ed517 Mon Sep 17 00:00:00 2001 From: Andy Wang Date: Tue, 1 Oct 2019 22:53:50 +0100 Subject: [PATCH] Add invalid key length error message --- src/core/operations/BlowfishDecrypt.mjs | 6 +++++- src/core/operations/BlowfishEncrypt.mjs | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/core/operations/BlowfishDecrypt.mjs b/src/core/operations/BlowfishDecrypt.mjs index e51e96a5..1285221c 100644 --- a/src/core/operations/BlowfishDecrypt.mjs +++ b/src/core/operations/BlowfishDecrypt.mjs @@ -70,7 +70,11 @@ class BlowfishDecrypt extends Operation { inputType = args[3], outputType = args[4]; - if (key.length === 0) throw new OperationError("Enter a key"); + if (key.length !== 8) { + throw new OperationError(`Invalid key length: ${key.length} bytes + +Blowfish uses a key length of 8 bytes (64 bits).`); + } input = Utils.convertToByteString(input, inputType); diff --git a/src/core/operations/BlowfishEncrypt.mjs b/src/core/operations/BlowfishEncrypt.mjs index ccb7498a..e7e558cd 100644 --- a/src/core/operations/BlowfishEncrypt.mjs +++ b/src/core/operations/BlowfishEncrypt.mjs @@ -70,7 +70,11 @@ class BlowfishEncrypt extends Operation { inputType = args[3], outputType = args[4]; - if (key.length === 0) throw new OperationError("Enter a key"); + if (key.length !== 8) { + throw new OperationError(`Invalid key length: ${key.length} bytes + +Blowfish uses a key length of 8 bytes (64 bits).`); + } input = Utils.convertToByteString(input, inputType);