]> git.ipfire.org Git - thirdparty/strongswan.git/blob - src/libstrongswan/asn1/asn1_parser.h
Update copyright headers after acquisition by secunet
[thirdparty/strongswan.git] / src / libstrongswan / asn1 / asn1_parser.h
1 /*
2 * Copyright (C) 2006 Martin Will
3 * Copyright (C) 2000-2017 Andreas Steffen
4 *
5 * Copyright (C) secunet Security Networks AG
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
18 /**
19 * @defgroup asn1_parser asn1_parser
20 * @{ @ingroup asn1
21 */
22
23 #ifndef ASN1_PARSER_H_
24 #define ASN1_PARSER_H_
25
26 #include <stdarg.h>
27
28 #include <library.h>
29
30 #include "asn1.h"
31
32 /**
33 * Definition of ASN.1 flags
34 */
35 #define ASN1_NONE 0x0000
36 #define ASN1_DEF 0x0001
37 #define ASN1_OPT 0x0002
38 #define ASN1_LOOP 0x0004
39 #define ASN1_CHOICE 0x0008
40 #define ASN1_CH 0x0010
41 #define ASN1_END 0x0020
42 #define ASN1_OBJ 0x0040
43 #define ASN1_BODY 0x0080
44 #define ASN1_RAW 0x0100
45 #define ASN1_EXIT 0x0200
46
47 typedef struct asn1Object_t asn1Object_t;
48
49 /**
50 * Syntax definition of an ASN.1 object
51 */
52 struct asn1Object_t{
53 u_int level;
54 const u_char *name;
55 asn1_t type;
56 uint16_t flags;
57 };
58
59 typedef struct asn1_parser_t asn1_parser_t;
60
61 /**
62 * Public interface of an ASN.1 parser
63 */
64 struct asn1_parser_t {
65
66 /**
67 * Parse the next ASN.1 object in the hierarchy and return it
68 *
69 * @param objectID current line in the object syntax definition
70 * @param object current object
71 * @return - FALSE if end of object syntax definition was reached
72 * or a parsing error occurred
73 * - TRUE otherwise
74 */
75 bool (*iterate)(asn1_parser_t *this, int *objectID, chunk_t *object);
76
77 /**
78 * Get the current parsing level
79 *
80 * @return current level
81 */
82 u_int (*get_level)(asn1_parser_t *this);
83
84 /**
85 * Set the top-most level
86 *
87 * @param level top-most level
88 */
89 void (*set_top_level)(asn1_parser_t *this, u_int level0);
90
91 /**
92 * Set implicit and private flags
93 *
94 * @param implicit top-most type of object is implicit
95 * @param private object data is private (use debug level 4)
96 */
97 void (*set_flags)(asn1_parser_t *this, bool implicit, bool private);
98
99 /**
100 * Show final parsing status
101 *
102 * @return TRUE if parsing was successful, FALSE otherwise
103 */
104 bool (*success)(asn1_parser_t *this);
105
106 /**
107 * Destroy the ASN.1 parser
108 */
109 void (*destroy)(asn1_parser_t *this);
110 };
111
112 /**
113 * Create an ASN.1 parser
114 *
115 * @param objects syntax definition of the ASN.1 object to be parsed
116 * @param blob ASN.1 coded binary blob
117 * @return ASN.1 context
118 */
119 asn1_parser_t* asn1_parser_create(asn1Object_t const *objects, chunk_t blob);
120
121 #endif /** ASN1_PARSER_H_ @}*/