Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable checkstyle checks for all submodules and fix errors #41

Merged
merged 1 commit into from
Dec 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,14 @@ public BinaryHttpParser(int maxFieldSectionSize) {
* 1 {@link io.netty.handler.codec.http.HttpMessage}, 0-n {@link HttpContent}, 1 {@link LastHttpContent}.
* </pre>
*
* It might also use the shortcut of {@link io.netty.handler.codec.http.FullHttpMessage} to represent a full sequence.
* It might also use the shortcut of {@link io.netty.handler.codec.http.FullHttpMessage} to represent a full
* sequence.
*
* @param in the {@link ByteBuf} to parse.
* @param completeBodyReceived {@code true} if we should consider the end of body to be received, {@code false}
* otherwise.
* @return the {@link HttpObject} or {@code null} if this method should be called again later once there are
* @return the {@link HttpObject} or {@code null} if this method should be called again later
* once there are
* more readable bytes in the input {@link ByteBuf}.
*/
public HttpObject parse(ByteBuf in, boolean completeBodyReceived) {
Expand Down Expand Up @@ -173,11 +175,11 @@ public HttpObject parse(ByteBuf in, boolean completeBodyReceived) {
}
boolean informational = response.status().codeClass() == HttpStatusClass.INFORMATIONAL;
if (informational) {
// There will be more responses to follow so just return a FullHttpResponse and NOT change the
// state.
// There will be more responses to follow so just return a FullHttpResponse and NOT change
// the state.
// See https://www.rfc-editor.org/rfc/rfc9292.html#section-3.5.1
return new DefaultFullHttpResponse(response.protocolVersion(), response.status(), Unpooled.EMPTY_BUFFER,
response.headers(), new DefaultHttpHeaders());
return new DefaultFullHttpResponse(response.protocolVersion(), response.status(),
Unpooled.EMPTY_BUFFER, response.headers(), new DefaultHttpHeaders());
} else if (state.knownLength) {
state = State.READ_KNOWN_LENGTH_CONTENT;
} else {
Expand Down Expand Up @@ -326,8 +328,10 @@ private static State readFramingIndicator(ByteBuf in) {
}

/**
* Reads the request head which includes the <a href="https://www.rfc-editor.org/rfc/rfc9292.html#name-request-control-data">control data</a>
* and <a href="https://www.rfc-editor.org/rfc/rfc9292.html#name-header-and-trailer-field-li">headers field section</a>.
* Reads the request head which includes the
* <a href="https://www.rfc-editor.org/rfc/rfc9292.html#name-request-control-data">control data</a>
* and
* <a href="https://www.rfc-editor.org/rfc/rfc9292.html#name-header-and-trailer-field-li">headers field section</a>.
*
* @param in the {@link ByteBuf} to read from.
* @param knownLength {@code true} if the length is known, {@code false} otherwise.
Expand Down Expand Up @@ -426,8 +430,10 @@ private static BinaryHttpRequest readRequestHead(ByteBuf in, boolean knownLength
}

/**
* Reads the response head which includes the <a href="https://www.rfc-editor.org/rfc/rfc9292.html#name-response-control-data">control data</a>
* and <a href="https://www.rfc-editor.org/rfc/rfc9292.html#name-header-and-trailer-field-li">headers field section</a>.
* Reads the response head which includes the
* <a href="https://www.rfc-editor.org/rfc/rfc9292.html#name-response-control-data">control data</a>
* and
* <a href="https://www.rfc-editor.org/rfc/rfc9292.html#name-header-and-trailer-field-li">headers field section</a>.
*
* @param in the {@link ByteBuf} to read from.
* @param knownLength {@code true} if the length is known, {@code false} otherwise.
Expand Down Expand Up @@ -475,7 +481,8 @@ private static BinaryHttpResponse readResponseHead(ByteBuf in, boolean knownLeng
}

/**
* Get the <a href="https://www.rfc-editor.org/rfc/rfc9292.html#name-indeterminate-length-messag">indeterminate length</a>
* Get the
* <a href="https://www.rfc-editor.org/rfc/rfc9292.html#name-indeterminate-length-messag">indeterminate length</a>
* of the "section". This will return {@code -1} if the length was not found.
*
* @param in the {@link ByteBuf} to search for the length.
Expand Down Expand Up @@ -512,7 +519,8 @@ private static int getIndeterminateLength(ByteBuf in) {
* @param maxFieldSectionSize the maximum size of the field-section (in bytes)
* @return {@link BinaryHttpHeaders} or {@code null} if not enough bytes are readable yet.
*/
private static BinaryHttpHeaders readFieldSection(ByteBuf in, boolean trailers, boolean knownLength, int maxFieldSectionSize) {
private static BinaryHttpHeaders readFieldSection(
ByteBuf in, boolean trailers, boolean knownLength, int maxFieldSectionSize) {
if (!in.isReadable()) {
return null;
}
Expand Down Expand Up @@ -575,7 +583,8 @@ private static void checkFieldSectionTooLarge(long fieldSectionSize, int maxFiel
if (fieldSectionSize > maxFieldSectionSize) {
// Guard against buffering too much bytes.
// See https://www.rfc-editor.org/rfc/rfc9292.html#section-8
throw new TooLongFrameException("field-section length exceeds configured maximum: " + fieldSectionSize + " > " + maxFieldSectionSize);
throw new TooLongFrameException("field-section length exceeds configured maximum: "
+ fieldSectionSize + " > " + maxFieldSectionSize);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ private enum State {
* 1 {@link BinaryHttpResponse} | {@link BinaryHttpRequest}, 0-n {@link HttpContent}, 1 {@link LastHttpContent}.
* </pre>
*
* {@link FullBinaryHttpResponse} or {@link FullBinaryHttpRequest} can be used as a shortcut for such a valid sequence.
* {@link FullBinaryHttpResponse} or {@link FullBinaryHttpRequest} can be used as a shortcut for such a valid
* sequence.
*
* @param msg the {@link HttpObject} to serialize
* @param out the {@link ByteBuf} into which to write.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ public DefaultBinaryHttpRequest(HttpVersion httpVersion, HttpMethod method, Stri
* @param scheme the scheme to use.
* @param authority the authority to use.
* @param uri the uri / path to use
* @param validateHeaders {@code true} if header validation should be done when add headers, {@code false} otherwise.
* @param validateHeaders {@code true} if header validation should be done when add headers, {@code false}
* otherwise.
*/
public DefaultBinaryHttpRequest(HttpVersion httpVersion, HttpMethod method, String scheme, String authority,
String uri, boolean validateHeaders) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ public DefaultFullBinaryHttpRequest(HttpVersion httpVersion, HttpMethod method,
* @param authority the authority to use.
* @param uri the uri / path to use
* @param content the payload of the request.
* @param validateHeaders {@code true} if header validation should be done when add headers, {@code false} otherwise.
* @param validateHeaders {@code true} if header validation should be done when add headers, {@code false}
* otherwise.
*/
public DefaultFullBinaryHttpRequest(HttpVersion httpVersion, HttpMethod method, String scheme, String authority,
String uri, ByteBuf content, boolean validateHeaders) {
Expand Down Expand Up @@ -103,7 +104,8 @@ private DefaultFullBinaryHttpRequest(HttpVersion httpVersion, HttpMethod method,
* @param scheme the scheme to use.
* @param authority the authority to use.
* @param uri the uri / path to use
* @param validateHeaders {@code true} if header validation should be done when add headers, {@code false} otherwise.
* @param validateHeaders {@code true} if header validation should be done when add headers, {@code false}
* otherwise.
*/
public DefaultFullBinaryHttpRequest(HttpVersion httpVersion, HttpMethod method, String scheme, String authority,
String uri, boolean validateHeaders) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ public DefaultFullBinaryHttpResponse(HttpVersion version, HttpResponseStatus sta
this(version, status, Unpooled.EMPTY_BUFFER, validateHeaders);
}

public DefaultFullBinaryHttpResponse(HttpVersion version, HttpResponseStatus status, ByteBuf content, boolean validateHeaders) {
this(version, status, content, BinaryHttpHeaders.newHeaders(validateHeaders), BinaryHttpHeaders.newTrailers(validateHeaders));
public DefaultFullBinaryHttpResponse(
HttpVersion version, HttpResponseStatus status, ByteBuf content, boolean validateHeaders) {
this(version, status, content, BinaryHttpHeaders.newHeaders(validateHeaders),
BinaryHttpHeaders.newTrailers(validateHeaders));
}

private DefaultFullBinaryHttpResponse(HttpVersion version, HttpResponseStatus status, ByteBuf content,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ private VarIntCodecUtils() { }

/**
* Returns the number of bytes needed to encode the
* <a href="https://www.rfc-editor.org/rfc/rfc9000.html#name-variable-length-integer-enc">variable length integer</a>.
* <a href="https://www.rfc-editor.org/rfc/rfc9000.html#name-variable-length-integer-enc">
* variable length integer</a>.
*/
public static int numBytesForVariableLengthInteger(long value) {
if (value <= 63) {
Expand All @@ -43,7 +44,8 @@ public static int numBytesForVariableLengthInteger(long value) {

/**
* Returns the number of bytes needed to encode a
* <a href="https://www.rfc-editor.org/rfc/rfc9000.html#name-variable-length-integer-enc">variable length integer</a>,
* <a href="https://www.rfc-editor.org/rfc/rfc9000.html#name-variable-length-integer-enc">
* variable length integer</a>,
* based on the initial encoded byte.
*/
public static int numBytesForVariableLengthIntegerFromByte(byte value) {
Expand All @@ -61,7 +63,8 @@ public static int numBytesForVariableLengthIntegerFromByte(byte value) {
}

/**
* Read the <a href="https://www.rfc-editor.org/rfc/rfc9000.html#name-variable-length-integer-enc">variable length integer</a>
* Read the <a href="https://www.rfc-editor.org/rfc/rfc9000.html#name-variable-length-integer-enc">
* variable length integer</a>
* from the {@link ByteBuf}.
*/
public static long readVariableLengthInteger(ByteBuf in, int len) {
Expand All @@ -71,7 +74,8 @@ public static long readVariableLengthInteger(ByteBuf in, int len) {
}

/**
* Get the <a href="https://www.rfc-editor.org/rfc/rfc9000.html#name-variable-length-integer-enc">variable length integer</a>
* Get the <a href="https://www.rfc-editor.org/rfc/rfc9000.html#name-variable-length-integer-enc">
* variable length integer</a>
* from the {@link ByteBuf}.
*/
public static long getVariableLengthInteger(ByteBuf in, int offset, int len) {
Expand All @@ -90,15 +94,17 @@ public static long getVariableLengthInteger(ByteBuf in, int offset, int len) {
}

/**
* Write the <a href="https://www.rfc-editor.org/rfc/rfc9000.html#name-variable-length-integer-enc">variable length integer</a> into the {@link ByteBuf}.
* Write the <a href="https://www.rfc-editor.org/rfc/rfc9000.html#name-variable-length-integer-enc">
* variable length integer</a> into the {@link ByteBuf}.
*/
public static void writeVariableLengthInteger(ByteBuf out, long value) {
int numBytes = VarIntCodecUtils.numBytesForVariableLengthInteger(value);
writeVariableLengthInteger(out, value, numBytes);
}

/**
* Write the <a href="https://www.rfc-editor.org/rfc/rfc9000.html#name-variable-length-integer-enc">variable length integer</a> into the {@link ByteBuf}.
* Write the <a href="https://www.rfc-editor.org/rfc/rfc9000.html#name-variable-length-integer-enc">
* variable length integer</a> into the {@link ByteBuf}.
*/
private static void writeVariableLengthInteger(ByteBuf out, long value, int numBytes) {
int writerIndex = out.writerIndex();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ final class BinaryHttpDecoder extends ByteToMessageDecoder {
*
* @param maxFieldSectionSize the maximum size of the field-section (in bytes)
*/
public BinaryHttpDecoder(int maxFieldSectionSize) {
BinaryHttpDecoder(int maxFieldSectionSize) {
this.parser = new BinaryHttpParser(maxFieldSectionSize);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,8 @@ void testFullMessageWithContentAndWithoutTrailers(boolean fragmented) throws IOE
assertFalse(reader.finishAndReleaseAll());
}

private static void assertContentWithoutTrailers(EmbeddedChannel reader, byte[] expectedContent) throws IOException {
private static void assertContentWithoutTrailers(EmbeddedChannel reader, byte[] expectedContent)
throws IOException {
try (ByteArrayOutputStream contentWriter = new ByteArrayOutputStream()) {
for (;;) {
HttpContent readContent = reader.readInbound();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@

import static org.junit.jupiter.api.Assertions.assertEquals;

public class BinaryHttpRequestEndToEndTest extends BinaryHttpMessageEndToEndTest<BinaryHttpRequest, FullBinaryHttpRequest> {
public class BinaryHttpRequestEndToEndTest
extends BinaryHttpMessageEndToEndTest<BinaryHttpRequest, FullBinaryHttpRequest> {

@Override
protected BinaryHttpRequest newHttpMessage() {
Expand All @@ -30,7 +31,8 @@ protected BinaryHttpRequest newHttpMessage() {

@Override
protected FullBinaryHttpRequest newFullHttpMessage(ByteBuf content) {
return new DefaultFullBinaryHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "scheme", "netty.io", "/path", content);
return new DefaultFullBinaryHttpRequest(
HttpVersion.HTTP_1_1, HttpMethod.GET, "scheme", "netty.io", "/path", content);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class BinaryHttpResponseEndToEndTest extends BinaryHttpMessageEndToEndTest<BinaryHttpResponse, FullBinaryHttpResponse> {
public class BinaryHttpResponseEndToEndTest
extends BinaryHttpMessageEndToEndTest<BinaryHttpResponse, FullBinaryHttpResponse> {
@Override
protected BinaryHttpResponse newHttpMessage() {
return new DefaultBinaryHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
/**
* BHTTP implementation
*/
package io.netty.incubator.codec.bhttp;
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@ final class BouncyCastleAEADCryptoContext implements AEADContext {
BouncyCastleAEADCryptoContext(AEAD aead) {
this.open = new BouncyCastleCryptoOperation() {
@Override
protected byte[] execute(byte[] arg1, byte[] arg2, int offset2, int length2)
protected byte[] execute(byte[] aad, byte[] in, int inOffset, int inLength)
throws InvalidCipherTextException {
return aead.open(arg1, arg2, offset2, length2);
return aead.open(aad, in, inOffset, inLength);
}
};
this.seal = new BouncyCastleCryptoOperation() {
@Override
protected byte[] execute(byte[] arg1, byte[] arg2, int offset2, int length2)
protected byte[] execute(byte[] aad, byte[] in, int inOffset, int inLength)
throws InvalidCipherTextException {
return aead.seal(arg1, arg2, offset2, length2);
return aead.seal(aad, in, inOffset, inLength);
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,32 @@

abstract class BouncyCastleCryptoOperation {

final void execute(ByteBuf arg1, ByteBuf arg2, ByteBuf out) throws CryptoException {
final int length1 = arg1.readableBytes();
final byte[] array1 = ByteBufUtil.getBytes(arg1, arg1.readerIndex(), arg1.readableBytes(), false);
final byte[] array2;
final int length2 = arg2.readableBytes();
final int offset2;
final void execute(ByteBuf aad, ByteBuf in, ByteBuf out) throws CryptoException {
final int aadLength = aad.readableBytes();
final byte[] aadArray = ByteBufUtil.getBytes(aad, aad.readerIndex(), aad.readableBytes(), false);
final byte[] inArray;
final int inLength = in.readableBytes();
final int inOffset;

if (arg2.hasArray()) {
if (in.hasArray()) {
// This is backed by a bytearray, just use it as input to reduce memory copies.
array2 = arg2.array();
offset2 = arg2.arrayOffset() + arg2.readerIndex();
inArray = in.array();
inOffset = in.arrayOffset() + in.readerIndex();
} else {
array2 = new byte[length2];
arg2.getBytes(arg2.readerIndex(), array2);
offset2 = 0;
inArray = new byte[inLength];
in.getBytes(in.readerIndex(), inArray);
inOffset = 0;
}
try {
byte[] result = execute(array1, array2, offset2, length2);
arg1.skipBytes(length1);
arg2.skipBytes(length2);
byte[] result = execute(aadArray, inArray, inOffset, inLength);
aad.skipBytes(aadLength);
in.skipBytes(inLength);
out.writeBytes(result);
} catch (InvalidCipherTextException e) {
throw new CryptoException(e);
}
}

protected abstract byte[] execute(byte[] arg1, byte[] arg2, int offset2, int length2)
protected abstract byte[] execute(byte[] aad, byte[] in, int inOffset, int inLength)
throws InvalidCipherTextException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ final class BouncyCastleHPKERecipientContext extends BouncyCastleHPKEContext imp
super(context);
open = new BouncyCastleCryptoOperation() {
@Override
protected byte[] execute(byte[] arg1, byte[] arg2, int offset2, int length2) throws InvalidCipherTextException {
return context.open(arg1, arg2, offset2, length2);
protected byte[] execute(byte[] aad, byte[] in, int inOffset, int inLength)
throws InvalidCipherTextException {
return context.open(aad, in, inOffset, inLength);
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
final class BouncyCastleHPKESenderContext extends BouncyCastleHPKEContext implements HPKESenderContext {

private final BouncyCastleCryptoOperation seal;
public BouncyCastleHPKESenderContext(HPKEContextWithEncapsulation context) {
BouncyCastleHPKESenderContext(HPKEContextWithEncapsulation context) {
super(context);
this.seal = new BouncyCastleCryptoOperation() {
@Override
protected byte[] execute(byte[] arg1, byte[] arg2, int offset2, int length2)
protected byte[] execute(byte[] aad, byte[] in, int inOffset, int inLength)
throws InvalidCipherTextException {
return context.seal(arg1, arg2, offset2, length2);
return context.seal(aad, in, inOffset, inLength);
}
};
}
Expand Down
Loading
Loading