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