/src/suricata7/rust/src/http2/huffman.rs
Line | Count | Source |
1 | | /* Copyright (C) 2020 Open Information Security Foundation |
2 | | * |
3 | | * You can copy, redistribute or modify this Program under the terms of |
4 | | * the GNU General Public License version 2 as published by the Free |
5 | | * Software Foundation. |
6 | | * |
7 | | * This program is distributed in the hope that it will be useful, |
8 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
9 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
10 | | * GNU General Public License for more details. |
11 | | * |
12 | | * You should have received a copy of the GNU General Public License |
13 | | * version 2 along with this program; if not, write to the Free Software |
14 | | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
15 | | * 02110-1301, USA. |
16 | | */ |
17 | | |
18 | | use nom7::bits::streaming::take as take_bits; |
19 | | use nom7::branch::alt; |
20 | | use nom7::combinator::{complete, map_opt}; |
21 | | use nom7::error::{make_error, ErrorKind}; |
22 | | use nom7::{Err, IResult}; |
23 | | |
24 | 49.9M | fn http2_huffman_table_len5(n: u32) -> Option<u8> { |
25 | 49.9M | match n { |
26 | 13.6M | 0 => Some(48), |
27 | 1.37M | 1 => Some(49), |
28 | 1.22M | 2 => Some(50), |
29 | 1.63M | 3 => Some(97), |
30 | 2.20M | 4 => Some(99), |
31 | 1.06M | 5 => Some(101), |
32 | 830k | 6 => Some(105), |
33 | 847k | 7 => Some(111), |
34 | 1.09M | 8 => Some(115), |
35 | 784k | 9 => Some(116), |
36 | 25.1M | _ => None, |
37 | | } |
38 | 49.9M | } |
39 | | |
40 | 50.2M | fn http2_decode_huffman_len5(input: (&[u8], usize)) -> IResult<(&[u8], usize), u8> { |
41 | 50.2M | complete(map_opt(take_bits(5u32), http2_huffman_table_len5))(input) |
42 | 50.2M | } |
43 | | |
44 | 25.1M | fn http2_huffman_table_len6(n: u32) -> Option<u8> { |
45 | 25.1M | match n { |
46 | 384k | 0x14 => Some(32), |
47 | 405k | 0x15 => Some(37), |
48 | 789k | 0x16 => Some(45), |
49 | 635k | 0x17 => Some(46), |
50 | 818k | 0x18 => Some(47), |
51 | 676k | 0x19 => Some(51), |
52 | 676k | 0x1a => Some(52), |
53 | 714k | 0x1b => Some(53), |
54 | 536k | 0x1c => Some(54), |
55 | 530k | 0x1d => Some(55), |
56 | 650k | 0x1e => Some(56), |
57 | 671k | 0x1f => Some(57), |
58 | 1.03M | 0x20 => Some(61), |
59 | 674k | 0x21 => Some(65), |
60 | 341k | 0x22 => Some(95), |
61 | 350k | 0x23 => Some(98), |
62 | 390k | 0x24 => Some(100), |
63 | 472k | 0x25 => Some(102), |
64 | 451k | 0x26 => Some(103), |
65 | 513k | 0x27 => Some(104), |
66 | 538k | 0x28 => Some(108), |
67 | 531k | 0x29 => Some(109), |
68 | 500k | 0x2a => Some(110), |
69 | 419k | 0x2b => Some(112), |
70 | 394k | 0x2c => Some(114), |
71 | 415k | 0x2d => Some(117), |
72 | 10.6M | _ => None, |
73 | | } |
74 | 25.1M | } |
75 | | |
76 | 25.5M | fn http2_decode_huffman_len6(input: (&[u8], usize)) -> IResult<(&[u8], usize), u8> { |
77 | 25.5M | complete(map_opt(take_bits(6u32), http2_huffman_table_len6))(input) |
78 | 25.5M | } |
79 | | |
80 | 10.6M | fn http2_huffman_table_len7(n: u32) -> Option<u8> { |
81 | 10.6M | match n { |
82 | 163k | 0x5c => Some(58), |
83 | 273k | 0x5d => Some(66), |
84 | 251k | 0x5e => Some(67), |
85 | 202k | 0x5f => Some(68), |
86 | 245k | 0x60 => Some(69), |
87 | 363k | 0x61 => Some(70), |
88 | 167k | 0x62 => Some(71), |
89 | 144k | 0x63 => Some(72), |
90 | 158k | 0x64 => Some(73), |
91 | 155k | 0x65 => Some(74), |
92 | 125k | 0x66 => Some(75), |
93 | 150k | 0x67 => Some(76), |
94 | 210k | 0x68 => Some(77), |
95 | 160k | 0x69 => Some(78), |
96 | 166k | 0x6a => Some(79), |
97 | 225k | 0x6b => Some(80), |
98 | 231k | 0x6c => Some(81), |
99 | 308k | 0x6d => Some(82), |
100 | 277k | 0x6e => Some(83), |
101 | 364k | 0x6f => Some(84), |
102 | 364k | 0x70 => Some(85), |
103 | 201k | 0x71 => Some(86), |
104 | 310k | 0x72 => Some(87), |
105 | 245k | 0x73 => Some(89), |
106 | 339k | 0x74 => Some(106), |
107 | 211k | 0x75 => Some(107), |
108 | 284k | 0x76 => Some(113), |
109 | 270k | 0x77 => Some(118), |
110 | 309k | 0x78 => Some(119), |
111 | 286k | 0x79 => Some(120), |
112 | 258k | 0x7a => Some(121), |
113 | 287k | 0x7b => Some(122), |
114 | 2.89M | _ => None, |
115 | | } |
116 | 10.6M | } |
117 | | |
118 | 11.0M | fn http2_decode_huffman_len7(input: (&[u8], usize)) -> IResult<(&[u8], usize), u8> { |
119 | 11.0M | complete(map_opt(take_bits(7u32), http2_huffman_table_len7))(input) |
120 | 11.0M | } |
121 | | |
122 | 2.88M | fn http2_huffman_table_len8(n: u32) -> Option<u8> { |
123 | 2.88M | match n { |
124 | 153k | 0xf8 => Some(38), |
125 | 729k | 0xf9 => Some(42), |
126 | 201k | 0xfa => Some(44), |
127 | 211k | 0xfb => Some(59), |
128 | 177k | 0xfc => Some(88), |
129 | 149k | 0xfd => Some(90), |
130 | 1.26M | _ => None, |
131 | | } |
132 | 2.88M | } |
133 | | |
134 | 3.32M | fn http2_decode_huffman_len8(input: (&[u8], usize)) -> IResult<(&[u8], usize), u8> { |
135 | 3.32M | complete(map_opt(take_bits(8u32), http2_huffman_table_len8))(input) |
136 | 3.32M | } |
137 | | |
138 | 1.26M | fn http2_huffman_table_len10(n: u32) -> Option<u8> { |
139 | 1.26M | match n { |
140 | 45.0k | 0x3f8 => Some(33), |
141 | 29.3k | 0x3f9 => Some(34), |
142 | 29.7k | 0x3fa => Some(40), |
143 | 43.9k | 0x3fb => Some(41), |
144 | 57.7k | 0x3fc => Some(63), |
145 | 1.05M | _ => None, |
146 | | } |
147 | 1.26M | } |
148 | | |
149 | 1.70M | fn http2_decode_huffman_len10(input: (&[u8], usize)) -> IResult<(&[u8], usize), u8> { |
150 | 1.70M | complete(map_opt(take_bits(10u32), http2_huffman_table_len10))(input) |
151 | 1.70M | } |
152 | | |
153 | 1.05M | fn http2_huffman_table_len11(n: u32) -> Option<u8> { |
154 | 1.05M | match n { |
155 | 16.4k | 0x7fa => Some(39), |
156 | 17.9k | 0x7fb => Some(43), |
157 | 29.8k | 0x7fc => Some(124), |
158 | 993k | _ => None, |
159 | | } |
160 | 1.05M | } |
161 | | |
162 | 1.49M | fn http2_decode_huffman_len11(input: (&[u8], usize)) -> IResult<(&[u8], usize), u8> { |
163 | 1.49M | complete(map_opt(take_bits(11u32), http2_huffman_table_len11))(input) |
164 | 1.49M | } |
165 | | |
166 | 992k | fn http2_huffman_table_len12(n: u32) -> Option<u8> { |
167 | 992k | match n { |
168 | 7.07k | 0xffa => Some(35), |
169 | 7.74k | 0xffb => Some(62), |
170 | 977k | _ => None, |
171 | | } |
172 | 992k | } |
173 | | |
174 | 1.43M | fn http2_decode_huffman_len12(input: (&[u8], usize)) -> IResult<(&[u8], usize), u8> { |
175 | 1.43M | complete(map_opt(take_bits(12u32), http2_huffman_table_len12))(input) |
176 | 1.43M | } |
177 | | |
178 | 975k | fn http2_huffman_table_len13(n: u32) -> Option<u8> { |
179 | 975k | match n { |
180 | 5.58k | 0x1ff8 => Some(0), |
181 | 3.36k | 0x1ff9 => Some(36), |
182 | 2.98k | 0x1ffa => Some(64), |
183 | 10.6k | 0x1ffb => Some(91), |
184 | 23.1k | 0x1ffc => Some(93), |
185 | 20.2k | 0x1ffd => Some(126), |
186 | 909k | _ => None, |
187 | | } |
188 | 975k | } |
189 | | |
190 | 1.41M | fn http2_decode_huffman_len13(input: (&[u8], usize)) -> IResult<(&[u8], usize), u8> { |
191 | 1.41M | complete(map_opt(take_bits(13u32), http2_huffman_table_len13))(input) |
192 | 1.41M | } |
193 | | |
194 | 909k | fn http2_huffman_table_len14(n: u32) -> Option<u8> { |
195 | 909k | match n { |
196 | 13.5k | 0x3ffc => Some(94), |
197 | 17.1k | 0x3ffd => Some(125), |
198 | 878k | _ => None, |
199 | | } |
200 | 909k | } |
201 | | |
202 | 1.35M | fn http2_decode_huffman_len14(input: (&[u8], usize)) -> IResult<(&[u8], usize), u8> { |
203 | 1.35M | complete(map_opt(take_bits(14u32), http2_huffman_table_len14))(input) |
204 | 1.35M | } |
205 | | |
206 | 877k | fn http2_huffman_table_len15(n: u32) -> Option<u8> { |
207 | 877k | match n { |
208 | 24.8k | 0x7ffc => Some(60), |
209 | 24.5k | 0x7ffd => Some(96), |
210 | 58.8k | 0x7ffe => Some(123), |
211 | 769k | _ => None, |
212 | | } |
213 | 877k | } |
214 | | |
215 | 1.32M | fn http2_decode_huffman_len15(input: (&[u8], usize)) -> IResult<(&[u8], usize), u8> { |
216 | 1.32M | complete(map_opt(take_bits(15u32), http2_huffman_table_len15))(input) |
217 | 1.32M | } |
218 | | |
219 | 765k | fn http2_huffman_table_len19(n: u32) -> Option<u8> { |
220 | 765k | match n { |
221 | 70.6k | 0x7fff0 => Some(92), |
222 | 5.15k | 0x7fff1 => Some(195), |
223 | 22.9k | 0x7fff2 => Some(208), |
224 | 666k | _ => None, |
225 | | } |
226 | 765k | } |
227 | | |
228 | 1.21M | fn http2_decode_huffman_len19(input: (&[u8], usize)) -> IResult<(&[u8], usize), u8> { |
229 | 1.21M | complete(map_opt(take_bits(19u32), http2_huffman_table_len19))(input) |
230 | 1.21M | } |
231 | | |
232 | 666k | fn http2_huffman_table_len20(n: u32) -> Option<u8> { |
233 | 666k | match n { |
234 | 2.91k | 0xfffe6 => Some(128), |
235 | 1.85k | 0xfffe7 => Some(130), |
236 | 3.01k | 0xfffe8 => Some(131), |
237 | 1.31k | 0xfffe9 => Some(162), |
238 | 3.54k | 0xfffea => Some(184), |
239 | 1.41k | 0xfffeb => Some(194), |
240 | 1.51k | 0xfffec => Some(224), |
241 | 3.38k | 0xfffed => Some(226), |
242 | 647k | _ => None, |
243 | | } |
244 | 666k | } |
245 | | |
246 | 1.11M | fn http2_decode_huffman_len20(input: (&[u8], usize)) -> IResult<(&[u8], usize), u8> { |
247 | 1.11M | complete(map_opt(take_bits(20u32), http2_huffman_table_len20))(input) |
248 | 1.11M | } |
249 | | |
250 | 1.18M | fn http2_huffman_table_len21(n: u32) -> Option<u8> { |
251 | 1.18M | match n { |
252 | 1.78k | 0x1fffdc => Some(153), |
253 | 1.43k | 0x1fffdd => Some(161), |
254 | 7.39k | 0x1fffde => Some(167), |
255 | 4.36k | 0x1fffdf => Some(172), |
256 | 66.7k | 0x1fffe0 => Some(176), |
257 | 1.93k | 0x1fffe1 => Some(177), |
258 | 4.64k | 0x1fffe2 => Some(179), |
259 | 6.91k | 0x1fffe3 => Some(209), |
260 | 932 | 0x1fffe4 => Some(216), |
261 | 2.39k | 0x1fffe5 => Some(217), |
262 | 1.22k | 0x1fffe6 => Some(227), |
263 | 2.15k | 0x1fffe7 => Some(229), |
264 | 3.00k | 0x1fffe8 => Some(230), |
265 | 1.08M | _ => None, |
266 | | } |
267 | 1.18M | } |
268 | | |
269 | 2.08M | fn http2_decode_huffman_len21(input: (&[u8], usize)) -> IResult<(&[u8], usize), u8> { |
270 | 2.08M | complete(map_opt(take_bits(21u32), http2_huffman_table_len21))(input) |
271 | 2.08M | } |
272 | | |
273 | 541k | fn http2_huffman_table_len22(n: u32) -> Option<u8> { |
274 | 541k | match n { |
275 | 1.48k | 0x3fffd2 => Some(129), |
276 | 833 | 0x3fffd3 => Some(132), |
277 | 1.07k | 0x3fffd4 => Some(133), |
278 | 3.39k | 0x3fffd5 => Some(134), |
279 | 1.48k | 0x3fffd6 => Some(136), |
280 | 3.33k | 0x3fffd7 => Some(146), |
281 | 4.79k | 0x3fffd8 => Some(154), |
282 | 958 | 0x3fffd9 => Some(156), |
283 | 518 | 0x3fffda => Some(160), |
284 | 2.06k | 0x3fffdb => Some(163), |
285 | 1.52k | 0x3fffdc => Some(164), |
286 | 1.48k | 0x3fffdd => Some(169), |
287 | 1.07k | 0x3fffde => Some(170), |
288 | 2.43k | 0x3fffdf => Some(173), |
289 | 4.69k | 0x3fffe0 => Some(178), |
290 | 2.45k | 0x3fffe1 => Some(181), |
291 | 484 | 0x3fffe2 => Some(185), |
292 | 5.92k | 0x3fffe3 => Some(186), |
293 | 1.39k | 0x3fffe4 => Some(187), |
294 | 12.3k | 0x3fffe5 => Some(189), |
295 | 5.17k | 0x3fffe6 => Some(190), |
296 | 2.84k | 0x3fffe7 => Some(196), |
297 | 8.19k | 0x3fffe8 => Some(198), |
298 | 1.26k | 0x3fffe9 => Some(228), |
299 | 780 | 0x3fffea => Some(232), |
300 | 937 | 0x3fffeb => Some(233), |
301 | 468k | _ => None, |
302 | | } |
303 | 541k | } |
304 | | |
305 | 989k | fn http2_decode_huffman_len22(input: (&[u8], usize)) -> IResult<(&[u8], usize), u8> { |
306 | 989k | complete(map_opt(take_bits(22u32), http2_huffman_table_len22))(input) |
307 | 989k | } |
308 | | |
309 | 468k | fn http2_huffman_table_len23(n: u32) -> Option<u8> { |
310 | 468k | match n { |
311 | 2.58k | 0x7fffd8 => Some(1), |
312 | 1.26k | 0x7fffd9 => Some(135), |
313 | 875 | 0x7fffda => Some(137), |
314 | 525 | 0x7fffdb => Some(138), |
315 | 1.35k | 0x7fffdc => Some(139), |
316 | 1.08k | 0x7fffdd => Some(140), |
317 | 10.3k | 0x7fffde => Some(141), |
318 | 3.41k | 0x7fffdf => Some(143), |
319 | 6.13k | 0x7fffe0 => Some(147), |
320 | 8.51k | 0x7fffe1 => Some(149), |
321 | 350 | 0x7fffe2 => Some(150), |
322 | 1.48k | 0x7fffe3 => Some(151), |
323 | 2.01k | 0x7fffe4 => Some(152), |
324 | 1.97k | 0x7fffe5 => Some(155), |
325 | 1.63k | 0x7fffe6 => Some(157), |
326 | 1.27k | 0x7fffe7 => Some(158), |
327 | 3.54k | 0x7fffe8 => Some(165), |
328 | 1.49k | 0x7fffe9 => Some(166), |
329 | 1.57k | 0x7fffea => Some(168), |
330 | 1.99k | 0x7fffeb => Some(174), |
331 | 2.35k | 0x7fffec => Some(175), |
332 | 638 | 0x7fffed => Some(180), |
333 | 2.58k | 0x7fffee => Some(182), |
334 | 2.96k | 0x7fffef => Some(183), |
335 | 34.6k | 0x7ffff0 => Some(188), |
336 | 7.79k | 0x7ffff1 => Some(191), |
337 | 3.55k | 0x7ffff2 => Some(197), |
338 | 2.85k | 0x7ffff3 => Some(231), |
339 | 2.76k | 0x7ffff4 => Some(239), |
340 | 354k | _ => None, |
341 | | } |
342 | 468k | } |
343 | | |
344 | 916k | fn http2_decode_huffman_len23(input: (&[u8], usize)) -> IResult<(&[u8], usize), u8> { |
345 | 916k | complete(map_opt(take_bits(23u32), http2_huffman_table_len23))(input) |
346 | 916k | } |
347 | | |
348 | 353k | fn http2_huffman_table_len24(n: u32) -> Option<u8> { |
349 | 353k | match n { |
350 | 969 | 0xffffea => Some(9), |
351 | 1.06k | 0xffffeb => Some(142), |
352 | 3.30k | 0xffffec => Some(144), |
353 | 3.66k | 0xffffed => Some(145), |
354 | 2.87k | 0xffffee => Some(148), |
355 | 63.6k | 0xffffef => Some(159), |
356 | 3.88k | 0xfffff0 => Some(171), |
357 | 2.23k | 0xfffff1 => Some(206), |
358 | 3.87k | 0xfffff2 => Some(215), |
359 | 2.37k | 0xfffff3 => Some(225), |
360 | 1.94k | 0xfffff4 => Some(236), |
361 | 2.07k | 0xfffff5 => Some(237), |
362 | 262k | _ => None, |
363 | | } |
364 | 353k | } |
365 | | |
366 | 802k | fn http2_decode_huffman_len24(input: (&[u8], usize)) -> IResult<(&[u8], usize), u8> { |
367 | 802k | complete(map_opt(take_bits(24u32), http2_huffman_table_len24))(input) |
368 | 802k | } |
369 | | |
370 | 261k | fn http2_huffman_table_len25(n: u32) -> Option<u8> { |
371 | 261k | match n { |
372 | 2.05k | 0x1ffffec => Some(199), |
373 | 7.08k | 0x1ffffed => Some(207), |
374 | 4.39k | 0x1ffffee => Some(234), |
375 | 2.27k | 0x1ffffef => Some(235), |
376 | 245k | _ => None, |
377 | | } |
378 | 261k | } |
379 | | |
380 | 710k | fn http2_decode_huffman_len25(input: (&[u8], usize)) -> IResult<(&[u8], usize), u8> { |
381 | 710k | complete(map_opt(take_bits(25u32), http2_huffman_table_len25))(input) |
382 | 710k | } |
383 | | |
384 | 245k | fn http2_huffman_table_len26(n: u32) -> Option<u8> { |
385 | 245k | match n { |
386 | 3.31k | 0x3ffffe0 => Some(192), |
387 | 9.76k | 0x3ffffe1 => Some(193), |
388 | 619 | 0x3ffffe2 => Some(200), |
389 | 2.64k | 0x3ffffe3 => Some(201), |
390 | 2.87k | 0x3ffffe4 => Some(202), |
391 | 1.98k | 0x3ffffe5 => Some(205), |
392 | 919 | 0x3ffffe6 => Some(210), |
393 | 5.72k | 0x3ffffe7 => Some(213), |
394 | 6.72k | 0x3ffffe8 => Some(218), |
395 | 890 | 0x3ffffe9 => Some(219), |
396 | 1.01k | 0x3ffffea => Some(238), |
397 | 620 | 0x3ffffeb => Some(240), |
398 | 1.92k | 0x3ffffec => Some(242), |
399 | 767 | 0x3ffffed => Some(243), |
400 | 2.64k | 0x3ffffee => Some(255), |
401 | 203k | _ => None, |
402 | | } |
403 | 245k | } |
404 | | |
405 | 694k | fn http2_decode_huffman_len26((i, bit_offset): (&[u8], usize)) -> IResult<(&[u8], usize), u8> { |
406 | 694k | complete(map_opt(take_bits(26u32), http2_huffman_table_len26))((i, bit_offset)) |
407 | 694k | } |
408 | | |
409 | 203k | fn http2_huffman_table_len27(n: u32) -> Option<u8> { |
410 | 203k | match n { |
411 | 648 | 0x7ffffde => Some(203), |
412 | 2.25k | 0x7ffffdf => Some(204), |
413 | 7.72k | 0x7ffffe0 => Some(211), |
414 | 831 | 0x7ffffe1 => Some(212), |
415 | 3.52k | 0x7ffffe2 => Some(214), |
416 | 6.07k | 0x7ffffe3 => Some(221), |
417 | 906 | 0x7ffffe4 => Some(222), |
418 | 460 | 0x7ffffe5 => Some(223), |
419 | 845 | 0x7ffffe6 => Some(241), |
420 | 3.70k | 0x7ffffe7 => Some(244), |
421 | 24.2k | 0x7ffffe8 => Some(245), |
422 | 1.65k | 0x7ffffe9 => Some(246), |
423 | 1.24k | 0x7ffffea => Some(247), |
424 | 1.37k | 0x7ffffeb => Some(248), |
425 | 2.73k | 0x7ffffec => Some(250), |
426 | 628 | 0x7ffffed => Some(251), |
427 | 595 | 0x7ffffee => Some(252), |
428 | 1.26k | 0x7ffffef => Some(253), |
429 | 20.9k | 0x7fffff0 => Some(254), |
430 | 121k | _ => None, |
431 | | } |
432 | 203k | } |
433 | | |
434 | 652k | fn http2_decode_huffman_len27(input: (&[u8], usize)) -> IResult<(&[u8], usize), u8> { |
435 | 652k | complete(map_opt(take_bits(27u32), http2_huffman_table_len27))(input) |
436 | 652k | } |
437 | | |
438 | 121k | fn http2_huffman_table_len28(n: u32) -> Option<u8> { |
439 | 121k | match n { |
440 | 1.20k | 0xfffffe2 => Some(2), |
441 | 8.01k | 0xfffffe3 => Some(3), |
442 | 1.40k | 0xfffffe4 => Some(4), |
443 | 1.89k | 0xfffffe5 => Some(5), |
444 | 1.54k | 0xfffffe6 => Some(6), |
445 | 739 | 0xfffffe7 => Some(7), |
446 | 1.10k | 0xfffffe8 => Some(8), |
447 | 1.43k | 0xfffffe9 => Some(11), |
448 | 1.44k | 0xfffffea => Some(12), |
449 | 1.76k | 0xfffffeb => Some(14), |
450 | 1.09k | 0xfffffec => Some(15), |
451 | 9.23k | 0xfffffed => Some(16), |
452 | 1.06k | 0xfffffee => Some(17), |
453 | 2.01k | 0xfffffef => Some(18), |
454 | 7.07k | 0xffffff0 => Some(19), |
455 | 951 | 0xffffff1 => Some(20), |
456 | 2.01k | 0xffffff2 => Some(21), |
457 | 1.50k | 0xffffff3 => Some(23), |
458 | 4.00k | 0xffffff4 => Some(24), |
459 | 2.86k | 0xffffff5 => Some(25), |
460 | 6.93k | 0xffffff6 => Some(26), |
461 | 10.9k | 0xffffff7 => Some(27), |
462 | 7.32k | 0xffffff8 => Some(28), |
463 | 1.74k | 0xffffff9 => Some(29), |
464 | 1.52k | 0xffffffa => Some(30), |
465 | 2.85k | 0xffffffb => Some(31), |
466 | 3.77k | 0xffffffc => Some(127), |
467 | 1.83k | 0xffffffd => Some(220), |
468 | 8.01k | 0xffffffe => Some(249), |
469 | 24.1k | _ => None, |
470 | | } |
471 | 121k | } |
472 | | |
473 | 570k | fn http2_decode_huffman_len28(input: (&[u8], usize)) -> IResult<(&[u8], usize), u8> { |
474 | 570k | complete(map_opt(take_bits(28u32), http2_huffman_table_len28))(input) |
475 | 570k | } |
476 | | |
477 | 24.0k | fn http2_huffman_table_len30(n: u32) -> Option<u8> { |
478 | 24.0k | match n { |
479 | 2.73k | 0x3ffffffc => Some(10), |
480 | 758 | 0x3ffffffd => Some(13), |
481 | 2.69k | 0x3ffffffe => Some(22), |
482 | | // 0x3fffffff => Some(256), |
483 | 17.8k | _ => None, |
484 | | } |
485 | 24.0k | } |
486 | | |
487 | 473k | fn http2_decode_huffman_len30(input: (&[u8], usize)) -> IResult<(&[u8], usize), u8> { |
488 | 473k | complete(map_opt(take_bits(30u32), http2_huffman_table_len30))(input) |
489 | 473k | } |
490 | | |
491 | | //hack to end many0 even if some bits are remaining |
492 | 467k | fn http2_decode_huffman_end(input: (&[u8], usize)) -> IResult<(&[u8], usize), u8> { |
493 | 467k | return Err(Err::Error(make_error(input, ErrorKind::Eof))); |
494 | 467k | } |
495 | | |
496 | | //we could profile and optimize performance here |
497 | 50.2M | pub fn http2_decode_huffman(input: (&[u8], usize)) -> IResult<(&[u8], usize), u8> { |
498 | | // trait nom::branch::Alt is implemented for lists up to size 20, |
499 | | // so use nested `alt` as a workaround (see nom documentation for `alt`) |
500 | 50.2M | alt(( |
501 | 50.2M | http2_decode_huffman_len5, |
502 | 50.2M | http2_decode_huffman_len6, |
503 | 50.2M | http2_decode_huffman_len7, |
504 | 50.2M | http2_decode_huffman_len8, |
505 | 50.2M | http2_decode_huffman_len10, |
506 | 50.2M | http2_decode_huffman_len11, |
507 | 50.2M | http2_decode_huffman_len12, |
508 | 50.2M | http2_decode_huffman_len13, |
509 | 50.2M | http2_decode_huffman_len14, |
510 | 50.2M | http2_decode_huffman_len15, |
511 | 50.2M | http2_decode_huffman_len19, |
512 | 50.2M | http2_decode_huffman_len20, |
513 | 50.2M | http2_decode_huffman_len21, |
514 | 50.2M | http2_decode_huffman_len21, |
515 | 50.2M | http2_decode_huffman_len22, |
516 | 50.2M | http2_decode_huffman_len23, |
517 | 50.2M | http2_decode_huffman_len24, |
518 | 50.2M | http2_decode_huffman_len25, |
519 | 50.2M | http2_decode_huffman_len26, |
520 | 50.2M | http2_decode_huffman_len27, |
521 | 50.2M | alt(( |
522 | 50.2M | http2_decode_huffman_len28, |
523 | 50.2M | http2_decode_huffman_len30, |
524 | 50.2M | http2_decode_huffman_end, |
525 | 50.2M | )), |
526 | 50.2M | ))(input) |
527 | 50.2M | } |