1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32 package io.netty5.handler.codec.http2;
33
34 import io.netty5.util.AsciiString;
35 import io.netty5.util.internal.ConstantTimeUtils;
36 import io.netty5.util.internal.PlatformDependent;
37
38 final class HpackUtil {
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54 static int equalsConstantTime(CharSequence s1, CharSequence s2) {
55 if (s1 instanceof AsciiString && s2 instanceof AsciiString) {
56 if (s1.length() != s2.length()) {
57 return 0;
58 }
59 AsciiString s1Ascii = (AsciiString) s1;
60 AsciiString s2Ascii = (AsciiString) s2;
61 return PlatformDependent.equalsConstantTime(s1Ascii.array(), s1Ascii.arrayOffset(),
62 s2Ascii.array(), s2Ascii.arrayOffset(), s1.length());
63 }
64
65 return ConstantTimeUtils.equalsConstantTime(s1, s2);
66 }
67
68
69
70
71
72
73
74 static boolean equalsVariableTime(CharSequence s1, CharSequence s2) {
75 return AsciiString.contentEquals(s1, s2);
76 }
77
78
79 enum IndexType {
80 INCREMENTAL,
81 NONE,
82 NEVER
83 }
84
85
86
87 static final int[] HUFFMAN_CODES = {
88 0x1ff8,
89 0x7fffd8,
90 0xfffffe2,
91 0xfffffe3,
92 0xfffffe4,
93 0xfffffe5,
94 0xfffffe6,
95 0xfffffe7,
96 0xfffffe8,
97 0xffffea,
98 0x3ffffffc,
99 0xfffffe9,
100 0xfffffea,
101 0x3ffffffd,
102 0xfffffeb,
103 0xfffffec,
104 0xfffffed,
105 0xfffffee,
106 0xfffffef,
107 0xffffff0,
108 0xffffff1,
109 0xffffff2,
110 0x3ffffffe,
111 0xffffff3,
112 0xffffff4,
113 0xffffff5,
114 0xffffff6,
115 0xffffff7,
116 0xffffff8,
117 0xffffff9,
118 0xffffffa,
119 0xffffffb,
120 0x14,
121 0x3f8,
122 0x3f9,
123 0xffa,
124 0x1ff9,
125 0x15,
126 0xf8,
127 0x7fa,
128 0x3fa,
129 0x3fb,
130 0xf9,
131 0x7fb,
132 0xfa,
133 0x16,
134 0x17,
135 0x18,
136 0x0,
137 0x1,
138 0x2,
139 0x19,
140 0x1a,
141 0x1b,
142 0x1c,
143 0x1d,
144 0x1e,
145 0x1f,
146 0x5c,
147 0xfb,
148 0x7ffc,
149 0x20,
150 0xffb,
151 0x3fc,
152 0x1ffa,
153 0x21,
154 0x5d,
155 0x5e,
156 0x5f,
157 0x60,
158 0x61,
159 0x62,
160 0x63,
161 0x64,
162 0x65,
163 0x66,
164 0x67,
165 0x68,
166 0x69,
167 0x6a,
168 0x6b,
169 0x6c,
170 0x6d,
171 0x6e,
172 0x6f,
173 0x70,
174 0x71,
175 0x72,
176 0xfc,
177 0x73,
178 0xfd,
179 0x1ffb,
180 0x7fff0,
181 0x1ffc,
182 0x3ffc,
183 0x22,
184 0x7ffd,
185 0x3,
186 0x23,
187 0x4,
188 0x24,
189 0x5,
190 0x25,
191 0x26,
192 0x27,
193 0x6,
194 0x74,
195 0x75,
196 0x28,
197 0x29,
198 0x2a,
199 0x7,
200 0x2b,
201 0x76,
202 0x2c,
203 0x8,
204 0x9,
205 0x2d,
206 0x77,
207 0x78,
208 0x79,
209 0x7a,
210 0x7b,
211 0x7ffe,
212 0x7fc,
213 0x3ffd,
214 0x1ffd,
215 0xffffffc,
216 0xfffe6,
217 0x3fffd2,
218 0xfffe7,
219 0xfffe8,
220 0x3fffd3,
221 0x3fffd4,
222 0x3fffd5,
223 0x7fffd9,
224 0x3fffd6,
225 0x7fffda,
226 0x7fffdb,
227 0x7fffdc,
228 0x7fffdd,
229 0x7fffde,
230 0xffffeb,
231 0x7fffdf,
232 0xffffec,
233 0xffffed,
234 0x3fffd7,
235 0x7fffe0,
236 0xffffee,
237 0x7fffe1,
238 0x7fffe2,
239 0x7fffe3,
240 0x7fffe4,
241 0x1fffdc,
242 0x3fffd8,
243 0x7fffe5,
244 0x3fffd9,
245 0x7fffe6,
246 0x7fffe7,
247 0xffffef,
248 0x3fffda,
249 0x1fffdd,
250 0xfffe9,
251 0x3fffdb,
252 0x3fffdc,
253 0x7fffe8,
254 0x7fffe9,
255 0x1fffde,
256 0x7fffea,
257 0x3fffdd,
258 0x3fffde,
259 0xfffff0,
260 0x1fffdf,
261 0x3fffdf,
262 0x7fffeb,
263 0x7fffec,
264 0x1fffe0,
265 0x1fffe1,
266 0x3fffe0,
267 0x1fffe2,
268 0x7fffed,
269 0x3fffe1,
270 0x7fffee,
271 0x7fffef,
272 0xfffea,
273 0x3fffe2,
274 0x3fffe3,
275 0x3fffe4,
276 0x7ffff0,
277 0x3fffe5,
278 0x3fffe6,
279 0x7ffff1,
280 0x3ffffe0,
281 0x3ffffe1,
282 0xfffeb,
283 0x7fff1,
284 0x3fffe7,
285 0x7ffff2,
286 0x3fffe8,
287 0x1ffffec,
288 0x3ffffe2,
289 0x3ffffe3,
290 0x3ffffe4,
291 0x7ffffde,
292 0x7ffffdf,
293 0x3ffffe5,
294 0xfffff1,
295 0x1ffffed,
296 0x7fff2,
297 0x1fffe3,
298 0x3ffffe6,
299 0x7ffffe0,
300 0x7ffffe1,
301 0x3ffffe7,
302 0x7ffffe2,
303 0xfffff2,
304 0x1fffe4,
305 0x1fffe5,
306 0x3ffffe8,
307 0x3ffffe9,
308 0xffffffd,
309 0x7ffffe3,
310 0x7ffffe4,
311 0x7ffffe5,
312 0xfffec,
313 0xfffff3,
314 0xfffed,
315 0x1fffe6,
316 0x3fffe9,
317 0x1fffe7,
318 0x1fffe8,
319 0x7ffff3,
320 0x3fffea,
321 0x3fffeb,
322 0x1ffffee,
323 0x1ffffef,
324 0xfffff4,
325 0xfffff5,
326 0x3ffffea,
327 0x7ffff4,
328 0x3ffffeb,
329 0x7ffffe6,
330 0x3ffffec,
331 0x3ffffed,
332 0x7ffffe7,
333 0x7ffffe8,
334 0x7ffffe9,
335 0x7ffffea,
336 0x7ffffeb,
337 0xffffffe,
338 0x7ffffec,
339 0x7ffffed,
340 0x7ffffee,
341 0x7ffffef,
342 0x7fffff0,
343 0x3ffffee,
344 0x3fffffff
345 };
346
347 static final byte[] HUFFMAN_CODE_LENGTHS = {
348 13, 23, 28, 28, 28, 28, 28, 28, 28, 24, 30, 28, 28, 30, 28, 28,
349 28, 28, 28, 28, 28, 28, 30, 28, 28, 28, 28, 28, 28, 28, 28, 28,
350 6, 10, 10, 12, 13, 6, 8, 11, 10, 10, 8, 11, 8, 6, 6, 6,
351 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 7, 8, 15, 6, 12, 10,
352 13, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
353 7, 7, 7, 7, 7, 7, 7, 7, 8, 7, 8, 13, 19, 13, 14, 6,
354 15, 5, 6, 5, 6, 5, 6, 6, 6, 5, 7, 7, 6, 6, 6, 5,
355 6, 7, 6, 5, 5, 6, 7, 7, 7, 7, 7, 15, 11, 14, 13, 28,
356 20, 22, 20, 20, 22, 22, 22, 23, 22, 23, 23, 23, 23, 23, 24, 23,
357 24, 24, 22, 23, 24, 23, 23, 23, 23, 21, 22, 23, 22, 23, 23, 24,
358 22, 21, 20, 22, 22, 23, 23, 21, 23, 22, 22, 24, 21, 22, 23, 23,
359 21, 21, 22, 21, 23, 22, 23, 23, 20, 22, 22, 22, 23, 22, 22, 23,
360 26, 26, 20, 19, 22, 23, 22, 25, 26, 26, 26, 27, 27, 26, 24, 25,
361 19, 21, 26, 27, 27, 26, 27, 24, 21, 21, 26, 26, 28, 27, 27, 27,
362 20, 24, 20, 21, 22, 21, 21, 23, 22, 22, 25, 25, 24, 24, 26, 23,
363 26, 27, 26, 26, 27, 27, 27, 27, 27, 28, 27, 27, 27, 27, 27, 26,
364 30
365 };
366
367 private HpackUtil() {
368
369 }
370 }