| 1 |
|
| #include "scan.h" |
| 2 |
|
| |
| 3 |
|
| int |
| 4 |
157 |
| peek_tag(const char **src, const char *max, U8 *type, U32* tag) { |
| 5 |
157 |
▶ | if (*src >= max) return 0; |
Branch: 1 branch
| Branch | True | False | Total |
| if (*src >= max) return 0; |
0 |
157 |
157 |
|
| 6 |
|
| |
| 7 |
157 |
| *type = **src & ASN1_TYPE_MASK; |
| 8 |
|
| |
| 9 |
157 |
▶ | if ((**src & 0x1f) == 0x1f) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ((**src & 0x1f) == 0x1f) { |
0 |
157 |
157 |
|
| 10 |
0 |
| U32 t = 0; |
| 11 |
|
| for (;;) { |
| 12 |
0 |
| (*src)++; |
| 13 |
0 |
▶ | if (*src >= max) return 0; |
Branch: 1 branch
| Branch | True | False | Total |
| if (*src >= max) return 0; |
0 |
0 |
0 |
|
| 14 |
0 |
▶ | if (t > ((~(U32)0) >> 7)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (t > ((~(U32)0) >> 7)) |
0 |
0 |
0 |
|
| 15 |
0 |
| croak("scan_tag: integer overflow"); |
| 16 |
0 |
| t <<= 7; |
| 17 |
0 |
| t += *(unsigned char *)*src & 0x7F; |
| 18 |
0 |
▶ | if (!(**src & 0x80)) break; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!(**src & 0x80)) break; |
0 |
0 |
0 |
|
| 19 |
|
| } |
| 20 |
0 |
| (*src)++; |
| 21 |
0 |
| *tag = t; |
| 22 |
|
| } else |
| 23 |
157 |
| *tag = *(*src)++ & 0x1f; |
| 24 |
|
| |
| 25 |
157 |
| return 1; |
| 26 |
|
| } |
| 27 |
|
| |
| 28 |
|
| void |
| 29 |
138 |
| scan_tag(const char **src, const char *max, U8 *type, U32* tag) { |
| 30 |
138 |
▶ | if (!peek_tag(src, max, type, tag)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!peek_tag(src, max, type, tag)) |
0 |
138 |
138 |
|
| 31 |
0 |
| croak("scan_tag: packet too short"); |
| 32 |
138 |
| } |
| 33 |
|
| |
| 34 |
|
| int |
| 35 |
0 |
| peek_tag_with_tt(const char **src, const char *max, |
| 36 |
|
| U8 expected_type, U32 expected_tag) { |
| 37 |
|
| U8 type; |
| 38 |
|
| U32 tag; |
| 39 |
0 |
▶ | if (peek_tag(src, max, &type, &tag)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (peek_tag(src, max, &type, &tag)) { |
0 |
0 |
0 |
|
| 40 |
0 |
▶ | if (type != expected_type || |
Branch: 1 branch
| Branch | True | False | Total |
| if (type != expected_type || |
0 |
0 |
0 |
|
| 41 |
0 |
▶ | tag != expected_tag ) |
Branch: 1 branch
| Branch | True | False | Total |
| tag != expected_tag ) |
0 |
0 |
0 |
|
| 42 |
0 |
| croak("peek_tag_with_tt: bad packet"); |
| 43 |
0 |
| return 1; |
| 44 |
|
| } |
| 45 |
0 |
| return 0; |
| 46 |
|
| } |
| 47 |
|
| |
| 48 |
|
| void |
| 49 |
0 |
| scan_tag_with_tt(const char **src, const char *max, |
| 50 |
|
| U8 expected_type, U32 expected_tag) { |
| 51 |
0 |
▶ | if (!peek_tag_with_tt(src, max, expected_type, expected_tag)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!peek_tag_with_tt(src, max, expected_type, expected_tag)) |
0 |
0 |
0 |
|
| 52 |
0 |
| croak("scan_tag_with_tt: bad packet"); |
| 53 |
0 |
| } |