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

Skip to content
Snippets Groups Projects
Commit a438722e authored by zzz's avatar zzz
Browse files

TunnelId: Add max value check

parent 4e635aa4
No related branches found
No related tags found
No related merge requests found
...@@ -27,7 +27,7 @@ import java.io.OutputStream; ...@@ -27,7 +27,7 @@ import java.io.OutputStream;
public class TunnelId extends DataStructureImpl { public class TunnelId extends DataStructureImpl {
private long _tunnelId; private long _tunnelId;
public static final long MAX_ID_VALUE = (1l<<32l)-2l; public static final long MAX_ID_VALUE = (1L << 32) - 2L;
public TunnelId() { public TunnelId() {
_tunnelId = -1; _tunnelId = -1;
...@@ -35,22 +35,22 @@ public class TunnelId extends DataStructureImpl { ...@@ -35,22 +35,22 @@ public class TunnelId extends DataStructureImpl {
/** /**
* @param id 1 to 0xffffffff * @param id 1 to 0xffffffff
* @throws IllegalArgumentException if less than or equal to zero * @throws IllegalArgumentException if less than or equal to zero or greater than max value
*/ */
public TunnelId(long id) { public TunnelId(long id) {
if (id <= 0) throw new IllegalArgumentException("wtf, tunnelId " + id); setTunnelId(id);
_tunnelId = id;
} }
public long getTunnelId() { return _tunnelId; } public long getTunnelId() { return _tunnelId; }
/** /**
* @param id 1 to 0xffffffff * @param id 1 to 0xffffffff
* @throws IllegalArgumentException if less than or equal to zero * @throws IllegalArgumentException if less than or equal to zero or greater than max value
*/ */
public void setTunnelId(long id) { public void setTunnelId(long id) {
if (id <= 0 || id > MAX_ID_VALUE)
throw new IllegalArgumentException("bad id " + id);
_tunnelId = id; _tunnelId = id;
if (id <= 0) throw new IllegalArgumentException("wtf, tunnelId " + id);
} }
public void readBytes(InputStream in) throws DataFormatException, IOException { public void readBytes(InputStream in) throws DataFormatException, IOException {
......
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