Search in sources :

Example 71 with AsciiString

use of io.netty.util.AsciiString in project netty by netty.

the class HpackUtil method equalsConstantTime.

/**
     * Compare two {@link CharSequence} objects without leaking timing information.
     * <p>
     * The {@code int} return type is intentional and is designed to allow cascading of constant time operations:
     * <pre>
     *     String s1 = "foo";
     *     String s2 = "foo";
     *     String s3 = "foo";
     *     String s4 = "goo";
     *     boolean equals = (equalsConstantTime(s1, s2) & equalsConstantTime(s3, s4)) != 0;
     * </pre>
     * @param s1 the first value.
     * @param s2 the second value.
     * @return {@code 0} if not equal. {@code 1} if equal.
     */
static int equalsConstantTime(CharSequence s1, CharSequence s2) {
    if (s1 instanceof AsciiString && s2 instanceof AsciiString) {
        if (s1.length() != s2.length()) {
            return 0;
        }
        AsciiString s1Ascii = (AsciiString) s1;
        AsciiString s2Ascii = (AsciiString) s2;
        return PlatformDependent.equalsConstantTime(s1Ascii.array(), s1Ascii.arrayOffset(), s2Ascii.array(), s2Ascii.arrayOffset(), s1.length());
    }
    return ConstantTimeUtils.equalsConstantTime(s1, s2);
}
Also used : AsciiString(io.netty.util.AsciiString)

Example 72 with AsciiString

use of io.netty.util.AsciiString in project netty by netty.

the class DefaultHttp2HeadersDecoderTest method decodeShouldSucceed.

@Test
public void decodeShouldSucceed() throws Exception {
    ByteBuf buf = encode(b(":method"), b("GET"), b("akey"), b("avalue"), randomBytes(), randomBytes());
    try {
        Http2Headers headers = decoder.decodeHeaders(0, buf);
        assertEquals(3, headers.size());
        assertEquals("GET", headers.method().toString());
        assertEquals("avalue", headers.get(new AsciiString("akey")).toString());
    } finally {
        buf.release();
    }
}
Also used : AsciiString(io.netty.util.AsciiString) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Example 73 with AsciiString

use of io.netty.util.AsciiString in project ratpack by ratpack.

the class CookieBasedSessionId method assignId.

private AsciiString assignId() {
    AsciiString id = sessionIdGenerator.generateSessionId();
    setCookie(id.toString(), cookieConfig.getExpires());
    return id;
}
Also used : AsciiString(io.netty.util.AsciiString)

Aggregations

AsciiString (io.netty.util.AsciiString)73 Test (org.junit.Test)43 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)27 HttpHeaders (io.netty.handler.codec.http.HttpHeaders)26 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)25 ByteBuf (io.netty.buffer.ByteBuf)18 ChannelPromise (io.netty.channel.ChannelPromise)15 DefaultHttp2Headers (io.netty.handler.codec.http2.DefaultHttp2Headers)12 Http2CodecUtil.getEmbeddedHttp2Exception (io.netty.handler.codec.http2.Http2CodecUtil.getEmbeddedHttp2Exception)12 Http2Runnable (io.netty.handler.codec.http2.Http2TestUtil.Http2Runnable)12 FullHttpMessage (io.netty.handler.codec.http.FullHttpMessage)11 Http2Headers (io.netty.handler.codec.http2.Http2Headers)9 Metadata (io.grpc.Metadata)8 ChannelFuture (io.netty.channel.ChannelFuture)4 Status (io.grpc.Status)3 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)3 DefaultFullHttpResponse (io.netty.handler.codec.http.DefaultFullHttpResponse)3 InvocationOnMock (org.mockito.invocation.InvocationOnMock)3 Setup (org.openjdk.jmh.annotations.Setup)3 DefaultHttpRequest (io.netty.handler.codec.http.DefaultHttpRequest)2