diff --git a/core/src/com/riiablo/io/ByteInput.java b/core/src/com/riiablo/io/ByteInput.java index 2bfd41ef..b6cf94b4 100644 --- a/core/src/com/riiablo/io/ByteInput.java +++ b/core/src/com/riiablo/io/ByteInput.java @@ -1,7 +1,6 @@ package com.riiablo.io; import io.netty.buffer.ByteBuf; -import io.netty.buffer.ByteBufUtil; import io.netty.buffer.Unpooled; import io.netty.util.CharsetUtil; import java.nio.charset.Charset; @@ -175,13 +174,13 @@ public class ByteInput { /** * Checks if the subsequent bytes match the specified sequence of bytes. * If they do, they will be consumed by this method call, otherwise an - * {@link InvalidFormat} will be thrown and any bytes read by this method + * {@link SignatureMismatch} will be thrown and any bytes read by this method * will be unread. * - * @throws InvalidFormat if the next bytes do not match the specified + * @throws SignatureMismatch if the next bytes do not match the specified * signature. * - * @see InvalidFormat + * @see SignatureMismatch * @see #skipUntil(byte[]) */ public ByteInput readSignature(byte[] signature) { @@ -191,11 +190,7 @@ public class ByteInput { final byte[] actual = new byte[buffer.readableBytes()]; buffer.readBytes(actual); buffer.resetReaderIndex(); - throw new InvalidFormat( - this, - String.format("Signatures do not match: %s, expected %s", - ByteBufUtil.hexDump(actual), - ByteBufUtil.hexDump(signature))); + throw new SignatureMismatch(this, actual, signature); } final byte[] actual = new byte[signature.length]; @@ -203,11 +198,7 @@ public class ByteInput { final boolean match = Arrays.equals(actual, signature); if (!match) { buffer.resetReaderIndex(); - throw new InvalidFormat( - this, - String.format("Signatures do not match: %s, expected %s", - ByteBufUtil.hexDump(actual), - ByteBufUtil.hexDump(signature))); + throw new SignatureMismatch(this, actual, signature); } incrementBitsRead((long) signature.length * Byte.SIZE); return this; diff --git a/core/src/com/riiablo/io/SignatureMismatch.java b/core/src/com/riiablo/io/SignatureMismatch.java new file mode 100644 index 00000000..bebd3777 --- /dev/null +++ b/core/src/com/riiablo/io/SignatureMismatch.java @@ -0,0 +1,26 @@ +package com.riiablo.io; + +import io.netty.buffer.ByteBufUtil; + +public class SignatureMismatch extends InvalidFormat { + public final byte[] actual; + public final byte[] expected; + + public SignatureMismatch(ByteInput in, byte[] actual, byte[] expected) { + super( + in, + String.format("Signatures do not match: %s, expected %s", + ByteBufUtil.hexDump(actual), + ByteBufUtil.hexDump(expected))); + this.actual = actual; + this.expected = expected; + } + + public byte[] actual() { + return actual; + } + + public byte[] expected() { + return expected; + } +}