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