/src/libcbor/src/cbor/streaming.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (c) 2014-2020 Pavel Kalvoda <me@pavelkalvoda.com> |
3 | | * |
4 | | * libcbor is free software; you can redistribute it and/or modify |
5 | | * it under the terms of the MIT license. See LICENSE for details. |
6 | | */ |
7 | | |
8 | | #include "streaming.h" |
9 | | #include "internal/loaders.h" |
10 | | |
11 | | static bool claim_bytes(size_t required, size_t provided, |
12 | 5.60M | struct cbor_decoder_result *result) { |
13 | 5.60M | if (required > (provided - result->read)) { |
14 | 858 | result->required = required + result->read; |
15 | 858 | result->read = 0; |
16 | 858 | result->status = CBOR_DECODER_NEDATA; |
17 | 858 | return false; |
18 | 5.60M | } else { |
19 | 5.60M | result->read += required; |
20 | 5.60M | result->required = 0; |
21 | 5.60M | return true; |
22 | 5.60M | } |
23 | 5.60M | } |
24 | | |
25 | | // Use implicit capture as an exception to avoid the super long parameter list |
26 | | #define CLAIM_BYTES_AND_INVOKE(callback_name, length, source_extra_offset) \ |
27 | 456k | do { \ |
28 | 456k | if (claim_bytes(length, source_size, &result)) { \ |
29 | 455k | callbacks->callback_name(context, source + 1 + source_extra_offset, \ |
30 | 455k | length); \ |
31 | 455k | } \ |
32 | 456k | } while (0) |
33 | | |
34 | | #define READ_CLAIM_INVOKE(callback_name, length_reader, length_bytes) \ |
35 | 12.4k | do { \ |
36 | 12.4k | if (claim_bytes(length_bytes, source_size, &result)) { \ |
37 | 12.4k | uint64_t length = length_reader(source + 1); \ |
38 | 12.4k | CLAIM_BYTES_AND_INVOKE(callback_name, length, length_bytes); \ |
39 | 12.4k | } \ |
40 | 12.4k | return result; \ |
41 | 12.4k | } while (0) |
42 | | |
43 | | struct cbor_decoder_result cbor_stream_decode( |
44 | | cbor_data source, size_t source_size, |
45 | 5.03M | const struct cbor_callbacks *callbacks, void *context) { |
46 | | // Attempt to claim the initial MTB byte |
47 | 5.03M | struct cbor_decoder_result result = {.status = CBOR_DECODER_FINISHED}; |
48 | 5.03M | if (!claim_bytes(1, source_size, &result)) { |
49 | 0 | return result; |
50 | 0 | } |
51 | | |
52 | 5.03M | switch (*source) { |
53 | 655k | case 0x00: /* Fallthrough */ |
54 | 689k | case 0x01: /* Fallthrough */ |
55 | 696k | case 0x02: /* Fallthrough */ |
56 | 699k | case 0x03: /* Fallthrough */ |
57 | 719k | case 0x04: /* Fallthrough */ |
58 | 725k | case 0x05: /* Fallthrough */ |
59 | 786k | case 0x06: /* Fallthrough */ |
60 | 794k | case 0x07: /* Fallthrough */ |
61 | 826k | case 0x08: /* Fallthrough */ |
62 | 832k | case 0x09: /* Fallthrough */ |
63 | 836k | case 0x0A: /* Fallthrough */ |
64 | 852k | case 0x0B: /* Fallthrough */ |
65 | 853k | case 0x0C: /* Fallthrough */ |
66 | 858k | case 0x0D: /* Fallthrough */ |
67 | 864k | case 0x0E: /* Fallthrough */ |
68 | 868k | case 0x0F: /* Fallthrough */ |
69 | 875k | case 0x10: /* Fallthrough */ |
70 | 888k | case 0x11: /* Fallthrough */ |
71 | 898k | case 0x12: /* Fallthrough */ |
72 | 900k | case 0x13: /* Fallthrough */ |
73 | 1.00M | case 0x14: /* Fallthrough */ |
74 | 1.02M | case 0x15: /* Fallthrough */ |
75 | 1.03M | case 0x16: /* Fallthrough */ |
76 | 1.03M | case 0x17: |
77 | | /* Embedded one byte unsigned integer */ |
78 | 1.03M | { |
79 | 1.03M | callbacks->uint8(context, _cbor_load_uint8(source)); |
80 | 1.03M | return result; |
81 | 1.03M | } |
82 | 53.4k | case 0x18: |
83 | | /* One byte unsigned integer */ |
84 | 53.4k | { |
85 | 53.4k | if (claim_bytes(1, source_size, &result)) { |
86 | 53.4k | callbacks->uint8(context, _cbor_load_uint8(source + 1)); |
87 | 53.4k | } |
88 | 53.4k | return result; |
89 | 1.03M | } |
90 | 3.70k | case 0x19: |
91 | | /* Two bytes unsigned integer */ |
92 | 3.70k | { |
93 | 3.70k | if (claim_bytes(2, source_size, &result)) { |
94 | 3.70k | callbacks->uint16(context, _cbor_load_uint16(source + 1)); |
95 | 3.70k | } |
96 | 3.70k | return result; |
97 | 1.03M | } |
98 | 1.76k | case 0x1A: |
99 | | /* Four bytes unsigned integer */ |
100 | 1.76k | { |
101 | 1.76k | if (claim_bytes(4, source_size, &result)) { |
102 | 1.76k | callbacks->uint32(context, _cbor_load_uint32(source + 1)); |
103 | 1.76k | } |
104 | 1.76k | return result; |
105 | 1.03M | } |
106 | 901 | case 0x1B: |
107 | | /* Eight bytes unsigned integer */ |
108 | 901 | { |
109 | 901 | if (claim_bytes(8, source_size, &result)) { |
110 | 900 | callbacks->uint64(context, _cbor_load_uint64(source + 1)); |
111 | 900 | } |
112 | 901 | return result; |
113 | 1.03M | } |
114 | 1 | case 0x1C: /* Fallthrough */ |
115 | 3 | case 0x1D: /* Fallthrough */ |
116 | 5 | case 0x1E: /* Fallthrough */ |
117 | 8 | case 0x1F: |
118 | | /* Reserved */ |
119 | 8 | { return (struct cbor_decoder_result){.status = CBOR_DECODER_ERROR}; } |
120 | 859 | case 0x20: /* Fallthrough */ |
121 | 1.37k | case 0x21: /* Fallthrough */ |
122 | 1.95k | case 0x22: /* Fallthrough */ |
123 | 6.11k | case 0x23: /* Fallthrough */ |
124 | 6.42k | case 0x24: /* Fallthrough */ |
125 | 9.18k | case 0x25: /* Fallthrough */ |
126 | 9.68k | case 0x26: /* Fallthrough */ |
127 | 27.2k | case 0x27: /* Fallthrough */ |
128 | 27.7k | case 0x28: /* Fallthrough */ |
129 | 28.0k | case 0x29: /* Fallthrough */ |
130 | 28.9k | case 0x2A: /* Fallthrough */ |
131 | 29.8k | case 0x2B: /* Fallthrough */ |
132 | 31.0k | case 0x2C: /* Fallthrough */ |
133 | 33.7k | case 0x2D: /* Fallthrough */ |
134 | 44.7k | case 0x2E: /* Fallthrough */ |
135 | 46.7k | case 0x2F: /* Fallthrough */ |
136 | 99.1k | case 0x30: /* Fallthrough */ |
137 | 102k | case 0x31: /* Fallthrough */ |
138 | 107k | case 0x32: /* Fallthrough */ |
139 | 108k | case 0x33: /* Fallthrough */ |
140 | 111k | case 0x34: /* Fallthrough */ |
141 | 113k | case 0x35: /* Fallthrough */ |
142 | 114k | case 0x36: /* Fallthrough */ |
143 | 116k | case 0x37: |
144 | | /* Embedded one byte negative integer */ |
145 | 116k | { |
146 | 116k | callbacks->negint8(context, |
147 | 116k | _cbor_load_uint8(source) - 0x20); /* 0x20 offset */ |
148 | 116k | return result; |
149 | 114k | } |
150 | 4.50k | case 0x38: |
151 | | /* One byte negative integer */ |
152 | 4.50k | { |
153 | 4.50k | if (claim_bytes(1, source_size, &result)) { |
154 | 4.50k | callbacks->negint8(context, _cbor_load_uint8(source + 1)); |
155 | 4.50k | } |
156 | 4.50k | return result; |
157 | 114k | } |
158 | 16.5k | case 0x39: |
159 | | /* Two bytes negative integer */ |
160 | 16.5k | { |
161 | 16.5k | if (claim_bytes(2, source_size, &result)) { |
162 | 16.5k | callbacks->negint16(context, _cbor_load_uint16(source + 1)); |
163 | 16.5k | } |
164 | 16.5k | return result; |
165 | 114k | } |
166 | 1.20k | case 0x3A: |
167 | | /* Four bytes negative integer */ |
168 | 1.20k | { |
169 | 1.20k | if (claim_bytes(4, source_size, &result)) { |
170 | 1.20k | callbacks->negint32(context, _cbor_load_uint32(source + 1)); |
171 | 1.20k | } |
172 | 1.20k | return result; |
173 | 114k | } |
174 | 11.0k | case 0x3B: |
175 | | /* Eight bytes negative integer */ |
176 | 11.0k | { |
177 | 11.0k | if (claim_bytes(8, source_size, &result)) { |
178 | 11.0k | callbacks->negint64(context, _cbor_load_uint64(source + 1)); |
179 | 11.0k | } |
180 | 11.0k | return result; |
181 | 114k | } |
182 | 7 | case 0x3C: /* Fallthrough */ |
183 | 12 | case 0x3D: /* Fallthrough */ |
184 | 16 | case 0x3E: /* Fallthrough */ |
185 | 21 | case 0x3F: |
186 | | /* Reserved */ |
187 | 21 | { return (struct cbor_decoder_result){.status = CBOR_DECODER_ERROR}; } |
188 | 42.1k | case 0x40: /* Fallthrough */ |
189 | 43.0k | case 0x41: /* Fallthrough */ |
190 | 43.9k | case 0x42: /* Fallthrough */ |
191 | 124k | case 0x43: /* Fallthrough */ |
192 | 124k | case 0x44: /* Fallthrough */ |
193 | 125k | case 0x45: /* Fallthrough */ |
194 | 126k | case 0x46: /* Fallthrough */ |
195 | 126k | case 0x47: /* Fallthrough */ |
196 | 130k | case 0x48: /* Fallthrough */ |
197 | 131k | case 0x49: /* Fallthrough */ |
198 | 131k | case 0x4A: /* Fallthrough */ |
199 | 131k | case 0x4B: /* Fallthrough */ |
200 | 132k | case 0x4C: /* Fallthrough */ |
201 | 132k | case 0x4D: /* Fallthrough */ |
202 | 133k | case 0x4E: /* Fallthrough */ |
203 | 133k | case 0x4F: /* Fallthrough */ |
204 | 135k | case 0x50: /* Fallthrough */ |
205 | 136k | case 0x51: /* Fallthrough */ |
206 | 136k | case 0x52: /* Fallthrough */ |
207 | 145k | case 0x53: /* Fallthrough */ |
208 | 180k | case 0x54: /* Fallthrough */ |
209 | 180k | case 0x55: /* Fallthrough */ |
210 | 181k | case 0x56: /* Fallthrough */ |
211 | 181k | case 0x57: |
212 | | /* Embedded length byte string */ |
213 | 181k | { |
214 | 181k | uint64_t length = _cbor_load_uint8(source) - 0x40; /* 0x40 offset */ |
215 | 181k | CLAIM_BYTES_AND_INVOKE(byte_string, length, 0); |
216 | 181k | return result; |
217 | 181k | } |
218 | 3.27k | case 0x58: |
219 | | /* One byte length byte string */ |
220 | 3.27k | READ_CLAIM_INVOKE(byte_string, _cbor_load_uint8, 1); |
221 | 380 | case 0x59: |
222 | | /* Two bytes length byte string */ |
223 | 380 | READ_CLAIM_INVOKE(byte_string, _cbor_load_uint16, 2); |
224 | 391 | case 0x5A: |
225 | | /* Four bytes length byte string */ |
226 | 391 | READ_CLAIM_INVOKE(byte_string, _cbor_load_uint32, 4); |
227 | 367 | case 0x5B: |
228 | | /* Eight bytes length byte string */ |
229 | 367 | READ_CLAIM_INVOKE(byte_string, _cbor_load_uint64, 8); |
230 | 1 | case 0x5C: /* Fallthrough */ |
231 | 4 | case 0x5D: /* Fallthrough */ |
232 | 6 | case 0x5E: |
233 | | /* Reserved */ |
234 | 6 | { return (struct cbor_decoder_result){.status = CBOR_DECODER_ERROR}; } |
235 | 1.15k | case 0x5F: |
236 | | /* Indefinite byte string */ |
237 | 1.15k | { |
238 | 1.15k | callbacks->byte_string_start(context); |
239 | 1.15k | return result; |
240 | 4 | } |
241 | 75.3k | case 0x60: /* Fallthrough */ |
242 | 84.1k | case 0x61: /* Fallthrough */ |
243 | 84.4k | case 0x62: /* Fallthrough */ |
244 | 87.7k | case 0x63: /* Fallthrough */ |
245 | 90.4k | case 0x64: /* Fallthrough */ |
246 | 93.3k | case 0x65: /* Fallthrough */ |
247 | 95.0k | case 0x66: /* Fallthrough */ |
248 | 96.8k | case 0x67: /* Fallthrough */ |
249 | 99.8k | case 0x68: /* Fallthrough */ |
250 | 110k | case 0x69: /* Fallthrough */ |
251 | 110k | case 0x6A: /* Fallthrough */ |
252 | 111k | case 0x6B: /* Fallthrough */ |
253 | 112k | case 0x6C: /* Fallthrough */ |
254 | 113k | case 0x6D: /* Fallthrough */ |
255 | 113k | case 0x6E: /* Fallthrough */ |
256 | 114k | case 0x6F: /* Fallthrough */ |
257 | 115k | case 0x70: /* Fallthrough */ |
258 | 116k | case 0x71: /* Fallthrough */ |
259 | 117k | case 0x72: /* Fallthrough */ |
260 | 118k | case 0x73: /* Fallthrough */ |
261 | 260k | case 0x74: /* Fallthrough */ |
262 | 261k | case 0x75: /* Fallthrough */ |
263 | 262k | case 0x76: /* Fallthrough */ |
264 | 262k | case 0x77: |
265 | | /* Embedded one byte length string */ |
266 | 262k | { |
267 | 262k | uint64_t length = _cbor_load_uint8(source) - 0x60; /* 0x60 offset */ |
268 | 262k | CLAIM_BYTES_AND_INVOKE(string, length, 0); |
269 | 262k | return result; |
270 | 262k | } |
271 | 3.70k | case 0x78: |
272 | | /* One byte length string */ |
273 | 3.70k | READ_CLAIM_INVOKE(string, _cbor_load_uint8, 1); |
274 | 1.67k | case 0x79: |
275 | | /* Two bytes length string */ |
276 | 1.67k | READ_CLAIM_INVOKE(string, _cbor_load_uint16, 2); |
277 | 436 | case 0x7A: |
278 | | /* Four bytes length string */ |
279 | 436 | READ_CLAIM_INVOKE(string, _cbor_load_uint32, 4); |
280 | 2.26k | case 0x7B: |
281 | | /* Eight bytes length string */ |
282 | 2.26k | READ_CLAIM_INVOKE(string, _cbor_load_uint64, 8); |
283 | 6 | case 0x7C: /* Fallthrough */ |
284 | 7 | case 0x7D: /* Fallthrough */ |
285 | 14 | case 0x7E: |
286 | | /* Reserved */ |
287 | 14 | { return (struct cbor_decoder_result){.status = CBOR_DECODER_ERROR}; } |
288 | 2.84k | case 0x7F: |
289 | | /* Indefinite length string */ |
290 | 2.84k | { |
291 | 2.84k | callbacks->string_start(context); |
292 | 2.84k | return result; |
293 | 7 | } |
294 | 1.20k | case 0x80: /* Fallthrough */ |
295 | 4.24k | case 0x81: /* Fallthrough */ |
296 | 7.79k | case 0x82: /* Fallthrough */ |
297 | 8.01k | case 0x83: /* Fallthrough */ |
298 | 8.25k | case 0x84: /* Fallthrough */ |
299 | 9.00k | case 0x85: /* Fallthrough */ |
300 | 13.7k | case 0x86: /* Fallthrough */ |
301 | 15.0k | case 0x87: /* Fallthrough */ |
302 | 18.0k | case 0x88: /* Fallthrough */ |
303 | 18.5k | case 0x89: /* Fallthrough */ |
304 | 19.1k | case 0x8A: /* Fallthrough */ |
305 | 19.9k | case 0x8B: /* Fallthrough */ |
306 | 20.3k | case 0x8C: /* Fallthrough */ |
307 | 21.4k | case 0x8D: /* Fallthrough */ |
308 | 22.9k | case 0x8E: /* Fallthrough */ |
309 | 23.6k | case 0x8F: /* Fallthrough */ |
310 | 24.5k | case 0x90: /* Fallthrough */ |
311 | 25.0k | case 0x91: /* Fallthrough */ |
312 | 26.0k | case 0x92: /* Fallthrough */ |
313 | 27.9k | case 0x93: /* Fallthrough */ |
314 | 28.2k | case 0x94: /* Fallthrough */ |
315 | 28.6k | case 0x95: /* Fallthrough */ |
316 | 30.7k | case 0x96: /* Fallthrough */ |
317 | 31.2k | case 0x97: |
318 | | /* Embedded one byte length array */ |
319 | 31.2k | { |
320 | 31.2k | callbacks->array_start( |
321 | 31.2k | context, _cbor_load_uint8(source) - 0x80); /* 0x40 offset */ |
322 | 31.2k | return result; |
323 | 30.7k | } |
324 | 1.93k | case 0x98: |
325 | | /* One byte length array */ |
326 | 1.93k | { |
327 | 1.93k | if (claim_bytes(1, source_size, &result)) { |
328 | 1.92k | callbacks->array_start(context, _cbor_load_uint8(source + 1)); |
329 | 1.92k | } |
330 | 1.93k | return result; |
331 | 30.7k | } |
332 | 229 | case 0x99: |
333 | | /* Two bytes length array */ |
334 | 229 | { |
335 | 229 | if (claim_bytes(2, source_size, &result)) { |
336 | 225 | callbacks->array_start(context, _cbor_load_uint16(source + 1)); |
337 | 225 | } |
338 | 229 | return result; |
339 | 30.7k | } |
340 | 266 | case 0x9A: |
341 | | /* Four bytes length array */ |
342 | 266 | { |
343 | 266 | if (claim_bytes(4, source_size, &result)) { |
344 | 261 | callbacks->array_start(context, _cbor_load_uint32(source + 1)); |
345 | 261 | } |
346 | 266 | return result; |
347 | 30.7k | } |
348 | 284 | case 0x9B: |
349 | | /* Eight bytes length array */ |
350 | 284 | { |
351 | 284 | if (claim_bytes(8, source_size, &result)) { |
352 | 280 | callbacks->array_start(context, _cbor_load_uint64(source + 1)); |
353 | 280 | } |
354 | 284 | return result; |
355 | 30.7k | } |
356 | 1 | case 0x9C: /* Fallthrough */ |
357 | 2 | case 0x9D: /* Fallthrough */ |
358 | 4 | case 0x9E: |
359 | | /* Reserved */ |
360 | 4 | { return (struct cbor_decoder_result){.status = CBOR_DECODER_ERROR}; } |
361 | 16.4k | case 0x9F: |
362 | | /* Indefinite length array */ |
363 | 16.4k | { |
364 | 16.4k | callbacks->indef_array_start(context); |
365 | 16.4k | return result; |
366 | 2 | } |
367 | 3.05M | case 0xA0: /* Fallthrough */ |
368 | 3.08M | case 0xA1: /* Fallthrough */ |
369 | 3.09M | case 0xA2: /* Fallthrough */ |
370 | 3.09M | case 0xA3: /* Fallthrough */ |
371 | 3.09M | case 0xA4: /* Fallthrough */ |
372 | 3.09M | case 0xA5: /* Fallthrough */ |
373 | 3.09M | case 0xA6: /* Fallthrough */ |
374 | 3.09M | case 0xA7: /* Fallthrough */ |
375 | 3.09M | case 0xA8: /* Fallthrough */ |
376 | 3.09M | case 0xA9: /* Fallthrough */ |
377 | 3.09M | case 0xAA: /* Fallthrough */ |
378 | 3.10M | case 0xAB: /* Fallthrough */ |
379 | 3.10M | case 0xAC: /* Fallthrough */ |
380 | 3.10M | case 0xAD: /* Fallthrough */ |
381 | 3.10M | case 0xAE: /* Fallthrough */ |
382 | 3.11M | case 0xAF: /* Fallthrough */ |
383 | 3.11M | case 0xB0: /* Fallthrough */ |
384 | 3.11M | case 0xB1: /* Fallthrough */ |
385 | 3.11M | case 0xB2: /* Fallthrough */ |
386 | 3.11M | case 0xB3: /* Fallthrough */ |
387 | 3.11M | case 0xB4: /* Fallthrough */ |
388 | 3.11M | case 0xB5: /* Fallthrough */ |
389 | 3.11M | case 0xB6: /* Fallthrough */ |
390 | 3.11M | case 0xB7: |
391 | | /* Embedded one byte length map */ |
392 | 3.11M | { |
393 | 3.11M | callbacks->map_start(context, |
394 | 3.11M | _cbor_load_uint8(source) - 0xA0); /* 0xA0 offset */ |
395 | 3.11M | return result; |
396 | 3.11M | } |
397 | 598 | case 0xB8: |
398 | | /* One byte length map */ |
399 | 598 | { |
400 | 598 | if (claim_bytes(1, source_size, &result)) { |
401 | 596 | callbacks->map_start(context, _cbor_load_uint8(source + 1)); |
402 | 596 | } |
403 | 598 | return result; |
404 | 3.11M | } |
405 | 447 | case 0xB9: |
406 | | /* Two bytes length map */ |
407 | 447 | { |
408 | 447 | if (claim_bytes(2, source_size, &result)) { |
409 | 444 | callbacks->map_start(context, _cbor_load_uint16(source + 1)); |
410 | 444 | } |
411 | 447 | return result; |
412 | 3.11M | } |
413 | 293 | case 0xBA: |
414 | | /* Four bytes length map */ |
415 | 293 | { |
416 | 293 | if (claim_bytes(4, source_size, &result)) { |
417 | 286 | callbacks->map_start(context, _cbor_load_uint32(source + 1)); |
418 | 286 | } |
419 | 293 | return result; |
420 | 3.11M | } |
421 | 327 | case 0xBB: |
422 | | /* Eight bytes length map */ |
423 | 327 | { |
424 | 327 | if (claim_bytes(8, source_size, &result)) { |
425 | 323 | callbacks->map_start(context, _cbor_load_uint64(source + 1)); |
426 | 323 | } |
427 | 327 | return result; |
428 | 3.11M | } |
429 | 3 | case 0xBC: /* Fallthrough */ |
430 | 6 | case 0xBD: /* Fallthrough */ |
431 | 11 | case 0xBE: |
432 | | /* Reserved */ |
433 | 11 | { return (struct cbor_decoder_result){.status = CBOR_DECODER_ERROR}; } |
434 | 23.8k | case 0xBF: |
435 | | /* Indefinite length map */ |
436 | 23.8k | { |
437 | 23.8k | callbacks->indef_map_start(context); |
438 | 23.8k | return result; |
439 | 6 | } |
440 | | /* See https://www.iana.org/assignments/cbor-tags/cbor-tags.xhtml for tag |
441 | | * assignment. All well-formed tags are processed regardless of validity |
442 | | * since maintaining the known mapping would be impractical. |
443 | | * |
444 | | * Moreover, even tags in the reserved "standard" range are not assigned |
445 | | * but may get assigned in the future (see e.g. |
446 | | * https://github.com/PJK/libcbor/issues/307), so processing all tags |
447 | | * improves forward compatibility. |
448 | | */ |
449 | 418 | case 0xC0: /* Fallthrough */ |
450 | 3.88k | case 0xC1: /* Fallthrough */ |
451 | 4.40k | case 0xC2: /* Fallthrough */ |
452 | 4.64k | case 0xC3: /* Fallthrough */ |
453 | 4.92k | case 0xC4: /* Fallthrough */ |
454 | 5.33k | case 0xC5: /* Fallthrough */ |
455 | 6.25k | case 0xC6: /* Fallthrough */ |
456 | 6.90k | case 0xC7: /* Fallthrough */ |
457 | 13.7k | case 0xC8: /* Fallthrough */ |
458 | 14.6k | case 0xC9: /* Fallthrough */ |
459 | 15.2k | case 0xCA: /* Fallthrough */ |
460 | 16.5k | case 0xCB: /* Fallthrough */ |
461 | 18.2k | case 0xCC: /* Fallthrough */ |
462 | 22.8k | case 0xCD: /* Fallthrough */ |
463 | 23.3k | case 0xCE: /* Fallthrough */ |
464 | 32.5k | case 0xCF: /* Fallthrough */ |
465 | 33.7k | case 0xD0: /* Fallthrough */ |
466 | 34.5k | case 0xD1: /* Fallthrough */ |
467 | 35.0k | case 0xD2: /* Fallthrough */ |
468 | 49.3k | case 0xD3: /* Fallthrough */ |
469 | 49.8k | case 0xD4: /* Fallthrough */ |
470 | 59.4k | case 0xD5: /* Fallthrough */ |
471 | 60.3k | case 0xD6: /* Fallthrough */ |
472 | 60.6k | case 0xD7: /* Fallthrough */ |
473 | 60.6k | { |
474 | 60.6k | callbacks->tag(context, (uint64_t)(_cbor_load_uint8(source) - |
475 | 60.6k | 0xC0)); /* 0xC0 offset */ |
476 | 60.6k | return result; |
477 | 60.3k | } |
478 | 2.24k | case 0xD8: /* 1B tag */ |
479 | 2.24k | { |
480 | 2.24k | if (claim_bytes(1, source_size, &result)) { |
481 | 2.24k | callbacks->tag(context, _cbor_load_uint8(source + 1)); |
482 | 2.24k | } |
483 | 2.24k | return result; |
484 | 60.3k | } |
485 | 538 | case 0xD9: /* 2B tag */ |
486 | 538 | { |
487 | 538 | if (claim_bytes(2, source_size, &result)) { |
488 | 533 | callbacks->tag(context, _cbor_load_uint16(source + 1)); |
489 | 533 | } |
490 | 538 | return result; |
491 | 60.3k | } |
492 | 1.49k | case 0xDA: /* 4B tag */ |
493 | 1.49k | { |
494 | 1.49k | if (claim_bytes(4, source_size, &result)) { |
495 | 1.49k | callbacks->tag(context, _cbor_load_uint32(source + 1)); |
496 | 1.49k | } |
497 | 1.49k | return result; |
498 | 60.3k | } |
499 | 436 | case 0xDB: /* 8B tag */ |
500 | 436 | { |
501 | 436 | if (claim_bytes(8, source_size, &result)) { |
502 | 434 | callbacks->tag(context, _cbor_load_uint64(source + 1)); |
503 | 434 | } |
504 | 436 | return result; |
505 | 60.3k | } |
506 | 1 | case 0xDC: /* Fallthrough */ |
507 | 3 | case 0xDD: /* Fallthrough */ |
508 | 4 | case 0xDE: /* Fallthrough */ |
509 | 10 | case 0xDF: /* Reserved */ |
510 | 10 | { |
511 | 10 | return (struct cbor_decoder_result){.status = CBOR_DECODER_ERROR}; |
512 | 4 | } |
513 | 1 | case 0xE0: /* Fallthrough */ |
514 | 4 | case 0xE1: /* Fallthrough */ |
515 | 8 | case 0xE2: /* Fallthrough */ |
516 | 11 | case 0xE3: /* Fallthrough */ |
517 | 14 | case 0xE4: /* Fallthrough */ |
518 | 15 | case 0xE5: /* Fallthrough */ |
519 | 31 | case 0xE6: /* Fallthrough */ |
520 | 35 | case 0xE7: /* Fallthrough */ |
521 | 37 | case 0xE8: /* Fallthrough */ |
522 | 38 | case 0xE9: /* Fallthrough */ |
523 | 40 | case 0xEA: /* Fallthrough */ |
524 | 45 | case 0xEB: /* Fallthrough */ |
525 | 47 | case 0xEC: /* Fallthrough */ |
526 | 49 | case 0xED: /* Fallthrough */ |
527 | 58 | case 0xEE: /* Fallthrough */ |
528 | 62 | case 0xEF: /* Fallthrough */ |
529 | 64 | case 0xF0: /* Fallthrough */ |
530 | 68 | case 0xF1: /* Fallthrough */ |
531 | 69 | case 0xF2: /* Fallthrough */ |
532 | 80 | case 0xF3: /* Simple value - unassigned */ |
533 | 80 | { |
534 | 80 | return (struct cbor_decoder_result){.status = CBOR_DECODER_ERROR}; |
535 | 69 | } |
536 | 1.18k | case 0xF4: |
537 | | /* False */ |
538 | 1.18k | { |
539 | 1.18k | callbacks->boolean(context, false); |
540 | 1.18k | return result; |
541 | 69 | } |
542 | 2.36k | case 0xF5: |
543 | | /* True */ |
544 | 2.36k | { |
545 | 2.36k | callbacks->boolean(context, true); |
546 | 2.36k | return result; |
547 | 69 | } |
548 | 444 | case 0xF6: |
549 | | /* Null */ |
550 | 444 | { |
551 | 444 | callbacks->null(context); |
552 | 444 | return result; |
553 | 69 | } |
554 | 18.1k | case 0xF7: |
555 | | /* Undefined */ |
556 | 18.1k | { |
557 | 18.1k | callbacks->undefined(context); |
558 | 18.1k | return result; |
559 | 69 | } |
560 | 2 | case 0xF8: |
561 | | /* 1B simple value, unassigned */ |
562 | 2 | { return (struct cbor_decoder_result){.status = CBOR_DECODER_ERROR}; } |
563 | 1.01k | case 0xF9: |
564 | | /* 2B float */ |
565 | 1.01k | { |
566 | 1.01k | if (claim_bytes(2, source_size, &result)) { |
567 | 1.01k | callbacks->float2(context, _cbor_load_half(source + 1)); |
568 | 1.01k | } |
569 | 1.01k | return result; |
570 | 69 | } |
571 | 1.71k | case 0xFA: |
572 | | /* 4B float */ |
573 | 1.71k | { |
574 | 1.71k | if (claim_bytes(4, source_size, &result)) { |
575 | 1.71k | callbacks->float4(context, _cbor_load_float(source + 1)); |
576 | 1.71k | } |
577 | 1.71k | return result; |
578 | 69 | } |
579 | 619 | case 0xFB: |
580 | | /* 8B float */ |
581 | 619 | { |
582 | 619 | if (claim_bytes(8, source_size, &result)) { |
583 | 612 | callbacks->float8(context, _cbor_load_double(source + 1)); |
584 | 612 | } |
585 | 619 | return result; |
586 | 69 | } |
587 | 2 | case 0xFC: /* Fallthrough */ |
588 | 5 | case 0xFD: /* Fallthrough */ |
589 | 11 | case 0xFE: |
590 | | /* Reserved */ |
591 | 11 | { return (struct cbor_decoder_result){.status = CBOR_DECODER_ERROR}; } |
592 | 37.1k | case 0xFF: |
593 | | /* Break */ |
594 | 37.1k | callbacks->indef_break(context); |
595 | | // Never happens, the switch statement is exhaustive on the 1B range; make |
596 | | // compiler happy |
597 | 37.1k | default: |
598 | 37.1k | return result; |
599 | 5.03M | } |
600 | 5.03M | } |