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);
}
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();
}
}
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;
}
Aggregations