I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Commit 4d955f3b authored by dev's avatar dev
Browse files

minor optimization in I2PDatagramDissector(only verfy signature once)

parent a8c26640
No related branches found
No related tags found
No related merge requests found
......@@ -42,6 +42,8 @@ public final class I2PDatagramDissector {
private byte[] rxPayload = new byte[DGRAM_BUFSIZE];
private int rxPayloadLen = 0;
private boolean valid = false;
/**
* Crate a new I2P repliable datagram dissector.
......@@ -89,11 +91,8 @@ public final class I2PDatagramDissector {
* @throws I2PInvalidDatagramException if the signature verification fails
*/
public byte[] getPayload() throws I2PInvalidDatagramException {
if (!dsaEng.verifySignature(rxSign, rxHashBytes,
rxDest.getSigningPublicKey())) {
throw new I2PInvalidDatagramException("Incorrect I2P repliable datagram signature");
}
this.verifySignature();
byte[] retPayload = new byte[rxPayloadLen];
System.arraycopy(rxPayload, 0, retPayload, 0, rxPayloadLen);
......@@ -109,11 +108,8 @@ public final class I2PDatagramDissector {
* @throws I2PInvalidDatagramException if the signature verification fails
*/
public Destination getSender() throws I2PInvalidDatagramException {
if (!dsaEng.verifySignature(rxSign, rxHashBytes,
rxDest.getSigningPublicKey())) {
throw new I2PInvalidDatagramException("Incorrect I2P repliable datagram signature");
}
this.verifySignature();
Destination retDest = new Destination();
try {
retDest.fromByteArray(rxDest.toByteArray());
......@@ -156,4 +152,21 @@ public final class I2PDatagramDissector {
return retDest;
}
/**
* Verify the signature of this datagram (previously loaded with the
* loadI2PDatagram() method)
*/
public void verifySignature() throws I2PInvalidDatagramException {
// first check if it already got validated
if(this.valid)
return;
// now validate
if (!dsaEng.verifySignature(rxSign, rxHashBytes, rxDest.getSigningPublicKey()))
throw new I2PInvalidDatagramException("Incorrect I2P repliable datagram signature");
// set validated
this.valid = true;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment