From c0d605dd77c9c99c688e4ada99220bf61c295533 Mon Sep 17 00:00:00 2001 From: Tim203 Date: Tue, 30 Nov 2021 00:33:53 +0100 Subject: [PATCH] Initial changes --- .../geysermc/floodgate/crypto/AesCipher.java | 2 +- .../floodgate/crypto/FloodgateCipher.java | 19 ++++++------------- .../util/InvalidFormatException.java | 18 ------------------ 3 files changed, 7 insertions(+), 32 deletions(-) diff --git a/common/src/main/java/org/geysermc/floodgate/crypto/AesCipher.java b/common/src/main/java/org/geysermc/floodgate/crypto/AesCipher.java index f602f4be0..e5d89a09f 100644 --- a/common/src/main/java/org/geysermc/floodgate/crypto/AesCipher.java +++ b/common/src/main/java/org/geysermc/floodgate/crypto/AesCipher.java @@ -91,7 +91,7 @@ public final class AesCipher implements FloodgateCipher { if (topping != null) { int mark = buffer.position(); - // we need the first index, the second is for the optional RawSkin + // we need the first index, the second is for the actual data boolean found = false; while (buffer.hasRemaining() && !found) { if (buffer.get() == 0x21) { diff --git a/common/src/main/java/org/geysermc/floodgate/crypto/FloodgateCipher.java b/common/src/main/java/org/geysermc/floodgate/crypto/FloodgateCipher.java index 69c8f9f6d..385559aee 100644 --- a/common/src/main/java/org/geysermc/floodgate/crypto/FloodgateCipher.java +++ b/common/src/main/java/org/geysermc/floodgate/crypto/FloodgateCipher.java @@ -130,25 +130,18 @@ public interface FloodgateCipher { final int identifierLength = IDENTIFIER.length; if (data.length <= HEADER_LENGTH) { - throw new InvalidFormatException("Data length is smaller then header." + - "Needed " + HEADER_LENGTH + ", got " + data.length, - true + throw new InvalidFormatException( + "Data length is smaller then header." + + "Needed " + HEADER_LENGTH + ", got " + data.length ); } for (int i = 0; i < identifierLength; i++) { if (IDENTIFIER[i] != data[i]) { - StringBuilder receivedIdentifier = new StringBuilder(); - for (byte b : IDENTIFIER) { - receivedIdentifier.append(b); - } - + String identifier = new String(IDENTIFIER, StandardCharsets.UTF_8); + String received = new String(data, 0, IDENTIFIER.length, StandardCharsets.UTF_8); throw new InvalidFormatException( - String.format("Expected identifier %s, got %s", - new String(IDENTIFIER, StandardCharsets.UTF_8), - receivedIdentifier.toString() - ), - true + "Expected identifier " + identifier + ", got " + received ); } } diff --git a/common/src/main/java/org/geysermc/floodgate/util/InvalidFormatException.java b/common/src/main/java/org/geysermc/floodgate/util/InvalidFormatException.java index 9ec5b1710..698e4522c 100644 --- a/common/src/main/java/org/geysermc/floodgate/util/InvalidFormatException.java +++ b/common/src/main/java/org/geysermc/floodgate/util/InvalidFormatException.java @@ -26,26 +26,8 @@ package org.geysermc.floodgate.util; -import lombok.Getter; - -@Getter public class InvalidFormatException extends Exception { - private boolean header = false; - - public InvalidFormatException() { - super(); - } - public InvalidFormatException(String message) { super(message); } - - public InvalidFormatException(String message, boolean header) { - super(message); - this.header = header; - } - - public InvalidFormatException(String message, Throwable cause) { - super(message, cause); - } }