drbg: Add missing format specifiers to debug output
[strongswan.git] / src / libstrongswan / asn1 / asn1_parser.h
1 /*
2 * Copyright (C) 2006 Martin Will
3 * Copyright (C) 2000-2017 Andreas Steffen
4 * HSR Hochschule fuer Technik Rapperswil
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * for more details.
15 */
16
17 /**
18 * @defgroup asn1_parser asn1_parser
19 * @{ @ingroup asn1
20 */
21
22 #ifndef ASN1_PARSER_H_
23 #define ASN1_PARSER_H_
24
25 #include <stdarg.h>
26
27 #include <library.h>
28
29 #include "asn1.h"
30
31 /**
32 * Definition of ASN.1 flags
33 */
34 #define ASN1_NONE 0x0000
35 #define ASN1_DEF 0x0001
36 #define ASN1_OPT 0x0002
37 #define ASN1_LOOP 0x0004
38 #define ASN1_CHOICE 0x0008
39 #define ASN1_CH 0x0010
40 #define ASN1_END 0x0020
41 #define ASN1_OBJ 0x0040
42 #define ASN1_BODY 0x0080
43 #define ASN1_RAW 0x0100
44 #define ASN1_EXIT 0x0200
45
46 typedef struct asn1Object_t asn1Object_t;
47
48 /**
49 * Syntax definition of an ASN.1 object
50 */
51 struct asn1Object_t{
52 u_int level;
53 const u_char *name;
54 asn1_t type;
55 uint16_t flags;
56 };
57
58 typedef struct asn1_parser_t asn1_parser_t;
59
60 /**
61 * Public interface of an ASN.1 parser
62 */
63 struct asn1_parser_t {
64
65 /**
66 * Parse the next ASN.1 object in the hierarchy and return it
67 *
68 * @param objectID current line in the object syntax definition
69 * @param object current object
70 * @return - FALSE if end of object syntax definition was reached
71 * or a parsing error occurred
72 * - TRUE otherwise
73 */
74 bool (*iterate)(asn1_parser_t *this, int *objectID, chunk_t *object);
75
76 /**
77 * Get the current parsing level
78 *
79 * @return current level
80 */
81 u_int (*get_level)(asn1_parser_t *this);
82
83 /**
84 * Set the top-most level
85 *
86 * @param level top-most level
87 */
88 void (*set_top_level)(asn1_parser_t *this, u_int level0);
89
90 /**
91 * Set implicit and private flags
92 *
93 * @param implicit top-most type of object is implicit
94 * @param private object data is private (use debug level 4)
95 */
96 void (*set_flags)(asn1_parser_t *this, bool implicit, bool private);
97
98 /**
99 * Show final parsing status
100 *
101 * @return TRUE if parsing was successful, FALSE otherwise
102 */
103 bool (*success)(asn1_parser_t *this);
104
105 /**
106 * Destroy the ASN.1 parser
107 */
108 void (*destroy)(asn1_parser_t *this);
109 };
110
111 /**
112 * Create an ASN.1 parser
113 *
114 * @param objects syntax definition of the ASN.1 object to be parsed
115 * @param blob ASN.1 coded binary blob
116 * @return ASN.1 context
117 */
118 asn1_parser_t* asn1_parser_create(asn1Object_t const *objects, chunk_t blob);
119
120 #endif /** ASN1_PARSER_H_ @}*/