Skip to content

Commit

Permalink
Adapt to Java 11
Browse files Browse the repository at this point in the history
  • Loading branch information
GoeLin committed Mar 27, 2024
1 parent 3408614 commit d08f693
Showing 1 changed file with 50 additions and 25 deletions.
75 changes: 50 additions & 25 deletions test/jdk/javax/net/ssl/DTLS/DTLSOverDatagram.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ void handshake(SSLEngine engine, DatagramSocket socket,
log(side, "=======handshake(" + loops + ", " + hs + ")=======");

switch (hs) {
case NEED_UNWRAP, NEED_UNWRAP_AGAIN -> {
case NEED_UNWRAP:
case NEED_UNWRAP_AGAIN: {
log(side, "Receive DTLS records, handshake status is " + hs);

ByteBuffer iNet;
Expand Down Expand Up @@ -215,8 +216,8 @@ void handshake(SSLEngine engine, DatagramSocket socket,
log(side, "Handshake status is FINISHED, finish the loop");
endLoops = true;
}
}
case NEED_WRAP -> {
} break;
case NEED_WRAP: {
List<DatagramPacket> packets = new ArrayList<>();
boolean finished = produceHandshakePackets(
engine, peerAddr, side, packets);
Expand All @@ -232,16 +233,16 @@ void handshake(SSLEngine engine, DatagramSocket socket,
+ "finish the loop");
endLoops = true;
}
}
case NEED_TASK -> runDelegatedTasks(engine);
case NOT_HANDSHAKING -> {
} break;
case NEED_TASK: runDelegatedTasks(engine); break;
case NOT_HANDSHAKING: {
log(side,
"Handshake status is NOT_HANDSHAKING, finish the loop");
endLoops = true;
}
case FINISHED -> throw new Exception( "Unexpected status, " +
} break;
case FINISHED: throw new Exception( "Unexpected status, " +
"SSLEngine.getHandshakeStatus() shouldn't return FINISHED");
default -> throw new Exception("Can't reach here, " +
default: throw new Exception("Can't reach here, " +
"handshake status is " + hs);
}
}
Expand Down Expand Up @@ -274,25 +275,25 @@ void verifySSLEngineResultStatus(SSLEngineResult r, String side) throws Exceptio
SSLEngineResult.Status rs = r.getStatus();
SSLEngineResult.HandshakeStatus hs = r.getHandshakeStatus();
switch (rs) {
case OK -> log(side, "SSLEngineResult status OK");
case BUFFER_OVERFLOW -> {
case OK: log(side, "SSLEngineResult status OK"); break;
case BUFFER_OVERFLOW: {
log(side, "BUFFER_OVERFLOW, handshake status is " + hs);
// the client maximum fragment size config does not work?
throw new Exception("Buffer overflow: " +
"incorrect client maximum fragment size");
}
case BUFFER_UNDERFLOW -> {
case BUFFER_UNDERFLOW: {
log(side, "BUFFER_UNDERFLOW, handshake status is " + hs);
// bad packet, or the client maximum fragment size
// config does not work?
if (hs != SSLEngineResult.HandshakeStatus.NOT_HANDSHAKING) {
throw new Exception("Buffer underflow: " +
"incorrect client maximum fragment size");
} // otherwise, ignore this packet
}
case CLOSED -> throw new Exception(
} break;
case CLOSED: throw new Exception(
"SSL engine closed, handshake status is " + hs);
default -> throw new Exception("Can't reach here, result is " + rs);
default: throw new Exception("Can't reach here, result is " + rs);
}
}

Expand Down Expand Up @@ -381,16 +382,18 @@ boolean produceHandshakePackets(SSLEngine engine, SocketAddress socketAddr,
SSLEngineResult.HandshakeStatus nhs = hs;
while (!endInnerLoop) {
switch (nhs) {
case NEED_TASK -> runDelegatedTasks(engine);
case NEED_UNWRAP, NEED_UNWRAP_AGAIN, NOT_HANDSHAKING -> {
case NEED_TASK: runDelegatedTasks(engine); break;
case NEED_UNWRAP:
case NEED_UNWRAP_AGAIN:
case NOT_HANDSHAKING: {
endInnerLoop = true;
endLoops = true;
}
case NEED_WRAP -> endInnerLoop = true;
case FINISHED -> throw new Exception(
} break;
case NEED_WRAP: endInnerLoop = true; break;
case FINISHED: throw new Exception(
"Unexpected status, SSLEngine.getHandshakeStatus() "
+ "should not return FINISHED");
default -> throw new Exception("Can't reach here, handshake status is "
default: throw new Exception("Can't reach here, handshake status is "
+ nhs);
}

Expand Down Expand Up @@ -581,8 +584,19 @@ public final void runTest(DTLSOverDatagram testCase) throws Exception {
}
}

record ServerCallable(DTLSOverDatagram testCase, DatagramSocket socket,
InetSocketAddress clientSocketAddr) implements Callable<String> {
final static class ServerCallable implements Callable<String> {

private final DTLSOverDatagram testCase;
private final DatagramSocket socket;
private final InetSocketAddress clientSocketAddr;

ServerCallable(DTLSOverDatagram testCase, DatagramSocket socket,
InetSocketAddress clientSocketAddr) {

this.testCase = testCase;
this.socket = socket;
this.clientSocketAddr = clientSocketAddr;
}

@Override
public String call() throws Exception {
Expand All @@ -608,8 +622,19 @@ public String call() throws Exception {
}
}

record ClientCallable(DTLSOverDatagram testCase, DatagramSocket socket,
InetSocketAddress serverSocketAddr) implements Callable<String> {
final static class ClientCallable implements Callable<String> {

private final DTLSOverDatagram testCase;
private final DatagramSocket socket;
private final InetSocketAddress serverSocketAddr;

ClientCallable(DTLSOverDatagram testCase, DatagramSocket socket,
InetSocketAddress serverSocketAddr) {

this.testCase = testCase;
this.socket = socket;
this.serverSocketAddr = serverSocketAddr;
}

@Override
public String call() throws Exception {
Expand Down

0 comments on commit d08f693

Please sign in to comment.