Skip to content

Commit

Permalink
Fix Luhn Operation to handle empty input
Browse files Browse the repository at this point in the history
  • Loading branch information
felixb1515 committed Dec 13, 2024
1 parent a81e47b commit a209bc6
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/main/java/de/usd/cstchef/operations/hashing/Luhn.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ public class Luhn extends Operation {
@Override
protected ByteArray perform(ByteArray input, MessageType messageType) throws Exception {

String exceptionMessage = "Luhn can only be applied to numerical values.";
if(input.length() == 0) throw new IllegalArgumentException(exceptionMessage);

for (int i = 0; i < input.length(); i++){
if ((input.getByte(i) < '0') || (input.getByte(i) > '9')) {
throw new IllegalArgumentException("Luhn can only be applied to numerical values.");
throw new IllegalArgumentException(exceptionMessage);
}
}

Expand Down

0 comments on commit a209bc6

Please sign in to comment.