Home / Class/ HpackUtil Class — netty Architecture

HpackUtil Class — netty Architecture

Architecture documentation for the HpackUtil class in HpackUtil.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  d34f021b_b6ee_14c0_486a_f00e42203f5a["HpackUtil"]
  49dbb25b_14ae_f934_f727_a2ea5f2f978d["HpackUtil.java"]
  d34f021b_b6ee_14c0_486a_f00e42203f5a -->|defined in| 49dbb25b_14ae_f934_f727_a2ea5f2f978d
  e8a7a453_077c_1dab_afb0_442edeb528e0["equalsConstantTime()"]
  d34f021b_b6ee_14c0_486a_f00e42203f5a -->|method| e8a7a453_077c_1dab_afb0_442edeb528e0
  564e7747_497b_6b59_a81d_7761ba62e11b["equalsVariableTime()"]
  d34f021b_b6ee_14c0_486a_f00e42203f5a -->|method| 564e7747_497b_6b59_a81d_7761ba62e11b
  6a1e5db8_2313_f9db_1791_567e0ddf7e82["HpackUtil()"]
  d34f021b_b6ee_14c0_486a_f00e42203f5a -->|method| 6a1e5db8_2313_f9db_1791_567e0ddf7e82

Relationship Graph

Source Code

codec-http2/src/main/java/io/netty/handler/codec/http2/HpackUtil.java lines 38–372

final class HpackUtil {
    /**
     * 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);
    }

    /**
     * Compare two {@link CharSequence}s.
     * @param s1 the first value.
     * @param s2 the second value.
     * @return {@code false} if not equal. {@code true} if equal.
     */
    static boolean equalsVariableTime(CharSequence s1, CharSequence s2) {
        return AsciiString.contentEquals(s1, s2);
    }

    // Section 6.2. Literal Header Field Representation
    enum IndexType {
        INCREMENTAL, // Section 6.2.1. Literal Header Field with Incremental Indexing
        NONE,        // Section 6.2.2. Literal Header Field without Indexing
        NEVER        // Section 6.2.3. Literal Header Field never Indexed
    }

    // Appendix B: Huffman Codes
    // https://tools.ietf.org/html/rfc7541#appendix-B
    static final int[] HUFFMAN_CODES = {
            0x1ff8,
            0x7fffd8,
            0xfffffe2,
            0xfffffe3,
            0xfffffe4,
            0xfffffe5,
            0xfffffe6,
            0xfffffe7,
            0xfffffe8,
            0xffffea,
            0x3ffffffc,
            0xfffffe9,
            0xfffffea,
            0x3ffffffd,
            0xfffffeb,
            0xfffffec,
            0xfffffed,
            0xfffffee,
            0xfffffef,
            0xffffff0,
            0xffffff1,
            0xffffff2,
            0x3ffffffe,
            0xffffff3,
            0xffffff4,
            0xffffff5,
            0xffffff6,
            0xffffff7,
            0xffffff8,
            0xffffff9,
            0xffffffa,

Frequently Asked Questions

What is the HpackUtil class?
HpackUtil is a class in the netty codebase, defined in codec-http2/src/main/java/io/netty/handler/codec/http2/HpackUtil.java.
Where is HpackUtil defined?
HpackUtil is defined in codec-http2/src/main/java/io/netty/handler/codec/http2/HpackUtil.java at line 38.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free