mirror of
https://github.com/collinsmith/riiablo.git
synced 2025-01-20 09:17:29 +07:00
Created SignatureMismatch exception to better describe that case
This commit is contained in:
parent
5560eb2b3f
commit
a2d8157987
@ -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;
|
||||
|
26
core/src/com/riiablo/io/SignatureMismatch.java
Normal file
26
core/src/com/riiablo/io/SignatureMismatch.java
Normal file
@ -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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user