Skip to content

Commit ff13f80

Browse files
committed
Release 1.1.0
1 parent 8af9f8d commit ff13f80

10 files changed

Lines changed: 21 additions & 23 deletions

File tree

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ plugins {
55
}
66

77
group = 'io.github.hirsivaja'
8-
version = '1.0.5'
8+
version = '1.1.0'
99

1010
repositories {
1111
mavenCentral()

src/main/java/com/github/hirsivaja/ip/IpPayload.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,10 @@ static IpPayload decode(ByteBuffer in) {
4545
in.mark();
4646
byte version = (byte) (in.get() >>> Ipv4Header.VERSION_SHIFT);
4747
in.reset();
48-
if(version == Ipv4Header.VERSION) {
49-
return Ipv4Payload.decode(in);
50-
} else if (version == Ipv6Header.VERSION) {
51-
return Ipv6Payload.decode(in);
52-
} else {
53-
throw new IllegalArgumentException("Not an IP payload");
54-
}
48+
return switch (version) {
49+
case Ipv4Header.VERSION -> Ipv4Payload.decode(in);
50+
case Ipv6Header.VERSION -> Ipv6Payload.decode(in);
51+
default -> throw new IllegalArgumentException("Not an IP payload");
52+
};
5553
}
5654
}

src/main/java/com/github/hirsivaja/ip/IpProtocol.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
public sealed interface IpProtocol permits IpProtocol.GenericIpProtocol, IpProtocol.Type {
44
byte type();
55

6-
public static IpProtocol fromType(byte type) {
6+
static IpProtocol fromType(byte type) {
77
for (Type identifier : Type.values()) {
88
if (identifier.type() == type) {
99
return identifier;
@@ -12,9 +12,9 @@ public static IpProtocol fromType(byte type) {
1212
return new GenericIpProtocol(type);
1313
}
1414

15-
public record GenericIpProtocol(byte type) implements IpProtocol {}
15+
record GenericIpProtocol(byte type) implements IpProtocol {}
1616

17-
public enum Type implements IpProtocol {
17+
enum Type implements IpProtocol {
1818
HOP_BY_HOP((byte) 0x00),
1919
ICMP((byte) 0x01),
2020
IGMP((byte) 0x02),
@@ -29,15 +29,15 @@ public enum Type implements IpProtocol {
2929
NO_NEXT((byte) 0x3B),
3030
DESTINATION((byte) 0x3C);
3131

32-
private final byte type;
32+
private final byte typeValue;
3333

3434
Type(byte type) {
35-
this.type = type;
35+
this.typeValue = type;
3636
}
3737

3838
@Override
3939
public byte type() {
40-
return type;
40+
return typeValue;
4141
}
4242
}
4343
}

src/main/java/com/github/hirsivaja/ip/ipv4/Ipv4Payload.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ static boolean isIpv4Payload(ByteBuffer in){
3838
return isIpv4;
3939
}
4040

41-
public record GenericIpv4Payload(Ipv4Header header, ByteArray payload) implements Ipv4Payload {
41+
record GenericIpv4Payload(Ipv4Header header, ByteArray payload) implements Ipv4Payload {
4242

4343
@Override
4444
public void encode(ByteBuffer out) {

src/main/java/com/github/hirsivaja/ip/ipv6/Ipv6Header.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public IpProtocol lastNextHeader() {
9696
if(extensionHeaders.isEmpty()){
9797
return nextHeader;
9898
} else {
99-
return extensionHeaders.get(extensionHeaders.size() - 1).nextHeader();
99+
return extensionHeaders.getLast().nextHeader();
100100
}
101101
}
102102

src/main/java/com/github/hirsivaja/ip/ipv6/Ipv6Payload.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ static boolean isIpv6Payload(ByteBuffer in) {
5656
return false;
5757
}
5858

59-
public record GenericIpv6Payload(Ipv6Header header, ByteArray payload) implements Ipv6Payload {
59+
record GenericIpv6Payload(Ipv6Header header, ByteArray payload) implements Ipv6Payload {
6060

6161
@Override
6262
public void encode(ByteBuffer out) {

src/main/java/com/github/hirsivaja/ip/tcp/TcpMessagePayload.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public TcpMessagePayload(IpHeader header, TcpHeader tcpHeader, ByteArray payload
2323
short checksum = tcpHeader.checksum() == 0 ?
2424
IpUtils.calculateInternetChecksum(generateChecksumData(header, tcpHeader, payload.array())) :
2525
tcpHeader.checksum();
26-
this.tcpHeader = new TcpHeader((short) tcpHeader.srcPort(), (short) tcpHeader.dstPort(), tcpHeader.sequenceNumber(),
26+
this.tcpHeader = new TcpHeader(tcpHeader.srcPort(), tcpHeader.dstPort(), tcpHeader.sequenceNumber(),
2727
tcpHeader.ackNumber(), tcpHeader.flags(), tcpHeader.windowSize(), checksum,
2828
tcpHeader.urgentPointer(), tcpHeader.rawOptions());
2929
this.payload = payload;

src/main/java/com/github/hirsivaja/ip/udp/UdpMessagePayload.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@ public UdpMessagePayload(IpHeader header, UdpHeader udpHeader, ByteArray payload
2323
short checksum = udpHeader.checksum() == 0 ?
2424
IpUtils.calculateInternetChecksum(generateChecksumData(header, udpHeader, payload.array())) :
2525
udpHeader.checksum();
26-
this.udpHeader = new UdpHeader((short) udpHeader.srcPort(), (short) udpHeader.dstPort(),
26+
this.udpHeader = new UdpHeader(udpHeader.srcPort(), udpHeader.dstPort(),
2727
(short) udpHeader.dataLength(), checksum);
2828
this.payload = payload;
2929
}
3030

3131
@Override
3232
public void encode(ByteBuffer out) {
3333
header.encode(out);
34-
out.putShort((short) udpHeader.srcPort());
35-
out.putShort((short) udpHeader.dstPort());
34+
out.putShort(udpHeader.srcPort());
35+
out.putShort(udpHeader.dstPort());
3636
out.putShort((short) (payload.length() + UdpHeader.UDP_HEADER_LEN));
3737
out.putShort(udpHeader.checksum());
3838
out.put(payload.array());

src/main/java/module-info.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
module Jipcs {
1+
module com.github.hirsivaja.jipcs {
22
requires java.logging;
33
}

src/test/java/com/github/hirsivaja/ip/ipv6/extension/ExtensionHeaderTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public void authenticationTest() {
2828
IpPayload payload = Ipv6Payload.decode(ByteBuffer.wrap(ipv6Bytes));
2929

3030
Assert.assertEquals(2, ((Ipv6Header) payload.header()).extensionHeaders().size());
31-
AuthenticationHeaderExtension ah = (AuthenticationHeaderExtension) ((Ipv6Header) payload.header()).extensionHeaders().get(0);
31+
AuthenticationHeaderExtension ah = (AuthenticationHeaderExtension) ((Ipv6Header) payload.header()).extensionHeaders().getFirst();
3232
Assert.assertEquals(0x12345678, ah.authenticationHeader().spi());
3333
Assert.assertEquals(0x87654321, ah.authenticationHeader().seqNumber());
3434
Assert.assertArrayEquals(IpUtils.parseHexBinary("55555555"), ah.authenticationHeader().icv().array());

0 commit comments

Comments
 (0)