Imported Upstream version 4.14
[platform/upstream/libtasn1.git] / lib / parser_aux.h
1 /*
2  * Copyright (C) 2000-2014 Free Software Foundation, Inc.
3  *
4  * This file is part of LIBTASN1.
5  *
6  * The LIBTASN1 library is free software; you can redistribute it
7  * and/or modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  * 02110-1301, USA
20  */
21
22 #ifndef _PARSER_AUX_H
23 #define _PARSER_AUX_H
24
25 /***********************************************/
26 /* Type: list_type                             */
27 /* Description: type used in the list during   */
28 /* the structure creation.                     */
29 /***********************************************/
30 typedef struct list_struct
31 {
32   asn1_node node;
33   struct list_struct *next;
34 } list_type;
35
36 /***************************************/
37 /*  Functions used by ASN.1 parser     */
38 /***************************************/
39 asn1_node _asn1_add_static_node (list_type **e_list, unsigned int type);
40
41 void _asn1_delete_list (list_type *e_list);
42
43 void _asn1_delete_list_and_nodes (list_type *e_list);
44
45
46 asn1_node
47 _asn1_set_value (asn1_node node, const void *value, unsigned int len);
48
49 asn1_node _asn1_set_value_m (asn1_node node, void *value, unsigned int len);
50
51 asn1_node
52 _asn1_set_value_lv (asn1_node node, const void *value, unsigned int len);
53
54 asn1_node
55 _asn1_append_value (asn1_node node, const void *value, unsigned int len);
56
57 asn1_node _asn1_set_name (asn1_node node, const char *name);
58
59 asn1_node _asn1_cpy_name (asn1_node dst, asn1_node_const src);
60
61 asn1_node _asn1_set_right (asn1_node node, asn1_node right);
62
63 asn1_node _asn1_get_last_right (asn1_node_const node);
64
65 void _asn1_remove_node (asn1_node node, unsigned int flags);
66
67 /* Max 64-bit integer length is 20 chars + 1 for sign + 1 for null termination */
68 #define LTOSTR_MAX_SIZE 22
69 char *_asn1_ltostr (int64_t v, char str[LTOSTR_MAX_SIZE]);
70
71 asn1_node _asn1_find_up (asn1_node_const node);
72
73 int _asn1_change_integer_value (asn1_node node);
74
75 #define EXPAND_OBJECT_ID_MAX_RECURSION 16
76 int _asn1_expand_object_id (list_type *list, asn1_node node);
77
78 int _asn1_type_set_config (asn1_node node);
79
80 int _asn1_check_identifier (asn1_node_const node);
81
82 int _asn1_set_default_tag (asn1_node node);
83
84 /******************************************************************/
85 /* Function : _asn1_get_right                                     */
86 /* Description: returns the element pointed by the RIGHT field of */
87 /*              a NODE_ASN element.                               */
88 /* Parameters:                                                    */
89 /*   node: NODE_ASN element pointer.                              */
90 /* Return: field RIGHT of NODE.                                   */
91 /******************************************************************/
92 inline static asn1_node
93 _asn1_get_right (asn1_node_const node)
94 {
95   if (node == NULL)
96     return NULL;
97   return node->right;
98 }
99
100 /******************************************************************/
101 /* Function : _asn1_set_down                                      */
102 /* Description: sets the field DOWN in a NODE_ASN element.        */
103 /* Parameters:                                                    */
104 /*   node: element pointer.                                       */
105 /*   down: pointer to a NODE_ASN element that you want be pointed */
106 /*          by NODE.                                              */
107 /* Return: pointer to *NODE.                                      */
108 /******************************************************************/
109 inline static asn1_node
110 _asn1_set_down (asn1_node node, asn1_node down)
111 {
112   if (node == NULL)
113     return node;
114   node->down = down;
115   if (down)
116     down->left = node;
117   return node;
118 }
119
120 /******************************************************************/
121 /* Function : _asn1_get_down                                      */
122 /* Description: returns the element pointed by the DOWN field of  */
123 /*              a NODE_ASN element.                               */
124 /* Parameters:                                                    */
125 /*   node: NODE_ASN element pointer.                              */
126 /* Return: field DOWN of NODE.                                    */
127 /******************************************************************/
128 inline static asn1_node
129 _asn1_get_down (asn1_node_const node)
130 {
131   if (node == NULL)
132     return NULL;
133   return node->down;
134 }
135
136 /******************************************************************/
137 /* Function : _asn1_get_name                                      */
138 /* Description: returns the name of a NODE_ASN element.           */
139 /* Parameters:                                                    */
140 /*   node: NODE_ASN element pointer.                              */
141 /* Return: a null terminated string.                              */
142 /******************************************************************/
143 inline static char *
144 _asn1_get_name (asn1_node_const node)
145 {
146   if (node == NULL)
147     return NULL;
148   return (char *) node->name;
149 }
150
151 /******************************************************************/
152 /* Function : _asn1_mod_type                                      */
153 /* Description: change the field TYPE of an NODE_ASN element.     */
154 /*              The new value is the old one | (bitwise or) the   */
155 /*              paramener VALUE.                                  */
156 /* Parameters:                                                    */
157 /*   node: NODE_ASN element pointer.                              */
158 /*   value: the integer value that must be or-ed with the current */
159 /*          value of field TYPE.                                  */
160 /* Return: NODE pointer.                                          */
161 /******************************************************************/
162 inline static asn1_node
163 _asn1_mod_type (asn1_node node, unsigned int value)
164 {
165   if (node == NULL)
166     return node;
167   node->type |= value;
168   return node;
169 }
170
171 #endif