fixes in length calculation in _asn1_extract_der_octet().
[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 /*  Functions used by ASN.1 parser     */
27 /***************************************/
28 asn1_node _asn1_add_static_node (unsigned int type);
29
30 asn1_node
31 _asn1_set_value (asn1_node node, const void *value, unsigned int len);
32
33 asn1_node _asn1_set_value_m (asn1_node node, void *value, unsigned int len);
34
35 asn1_node
36 _asn1_set_value_lv (asn1_node node, const void *value, unsigned int len);
37
38 asn1_node
39 _asn1_append_value (asn1_node node, const void *value, unsigned int len);
40
41 asn1_node _asn1_set_name (asn1_node node, const char *name);
42
43 asn1_node _asn1_cpy_name (asn1_node dst, asn1_node src);
44
45 asn1_node _asn1_set_right (asn1_node node, asn1_node right);
46
47 asn1_node _asn1_get_last_right (asn1_node node);
48
49 void _asn1_remove_node (asn1_node node, unsigned int flags);
50
51 void _asn1_delete_list (void);
52
53 void _asn1_delete_list_and_nodes (void);
54
55 #define LTOSTR_MAX_SIZE 20
56 char *_asn1_ltostr (long v, char *str);
57
58 asn1_node _asn1_find_up (asn1_node node);
59
60 int _asn1_change_integer_value (asn1_node node);
61
62 int _asn1_expand_object_id (asn1_node node);
63
64 int _asn1_type_set_config (asn1_node node);
65
66 int _asn1_check_identifier (asn1_node node);
67
68 int _asn1_set_default_tag (asn1_node node);
69
70 /******************************************************************/
71 /* Function : _asn1_get_right                                     */
72 /* Description: returns the element pointed by the RIGHT field of */
73 /*              a NODE_ASN element.                               */
74 /* Parameters:                                                    */
75 /*   node: NODE_ASN element pointer.                              */
76 /* Return: field RIGHT of NODE.                                   */
77 /******************************************************************/
78 inline static asn1_node
79 _asn1_get_right (asn1_node node)
80 {
81   if (node == NULL)
82     return NULL;
83   return node->right;
84 }
85
86 /******************************************************************/
87 /* Function : _asn1_set_down                                      */
88 /* Description: sets the field DOWN in a NODE_ASN element.        */
89 /* Parameters:                                                    */
90 /*   node: element pointer.                                       */
91 /*   down: pointer to a NODE_ASN element that you want be pointed */
92 /*          by NODE.                                              */
93 /* Return: pointer to *NODE.                                      */
94 /******************************************************************/
95 inline static asn1_node
96 _asn1_set_down (asn1_node node, asn1_node down)
97 {
98   if (node == NULL)
99     return node;
100   node->down = down;
101   if (down)
102     down->left = node;
103   return node;
104 }
105
106 /******************************************************************/
107 /* Function : _asn1_get_down                                      */
108 /* Description: returns the element pointed by the DOWN field of  */
109 /*              a NODE_ASN element.                               */
110 /* Parameters:                                                    */
111 /*   node: NODE_ASN element pointer.                              */
112 /* Return: field DOWN of NODE.                                    */
113 /******************************************************************/
114 inline static asn1_node
115 _asn1_get_down (asn1_node node)
116 {
117   if (node == NULL)
118     return NULL;
119   return node->down;
120 }
121
122 /******************************************************************/
123 /* Function : _asn1_get_name                                      */
124 /* Description: returns the name of a NODE_ASN element.           */
125 /* Parameters:                                                    */
126 /*   node: NODE_ASN element pointer.                              */
127 /* Return: a null terminated string.                              */
128 /******************************************************************/
129 inline static char *
130 _asn1_get_name (asn1_node node)
131 {
132   if (node == NULL)
133     return NULL;
134   return node->name;
135 }
136
137 /******************************************************************/
138 /* Function : _asn1_mod_type                                      */
139 /* Description: change the field TYPE of an NODE_ASN element.     */
140 /*              The new value is the old one | (bitwise or) the   */
141 /*              paramener VALUE.                                  */
142 /* Parameters:                                                    */
143 /*   node: NODE_ASN element pointer.                              */
144 /*   value: the integer value that must be or-ed with the current */
145 /*          value of field TYPE.                                  */
146 /* Return: NODE pointer.                                          */
147 /******************************************************************/
148 inline static asn1_node
149 _asn1_mod_type (asn1_node node, unsigned int value)
150 {
151   if (node == NULL)
152     return node;
153   node->type |= value;
154   return node;
155 }
156
157 #endif