libksba  1.6.0
About: KSBA is a library to make the tasks of working with X.509 certificates, CMS data and related objects more easy.
  Fossies Dox: libksba-1.6.0.tar.bz2  ("unofficial" and yet experimental doxygen-generated source code documentation)  

asn1-func.h
Go to the documentation of this file.
1 /* asn1-func.h - definitions for asn1-func.c
2  * Copyright (C) 2000,2001 Fabio Fiorina
3  * Copyright (C) 2001 Free Software Foundation, Inc.
4  * Copyright (C) 2002, 2003, 2006, 2007, 2010, 2012 g10 Code GmbH
5  *
6  * This file is part of KSBA.
7  *
8  * KSBA is free software; you can redistribute it and/or modify
9  * it under the terms of either
10  *
11  * - the GNU Lesser General Public License as published by the Free
12  * Software Foundation; either version 3 of the License, or (at
13  * your option) any later version.
14  *
15  * or
16  *
17  * - the GNU General Public License as published by the Free
18  * Software Foundation; either version 2 of the License, or (at
19  * your option) any later version.
20  *
21  * or both in parallel, as here.
22  *
23  * KSBA is distributed in the hope that it will be useful, but WITHOUT
24  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
25  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
26  * License for more details.
27  *
28  * You should have received a copies of the GNU General Public License
29  * and the GNU Lesser General Public License along with this program;
30  * if not, see <http://www.gnu.org/licenses/>.
31  */
32 
33 #ifndef ASN1_FUNC_H
34 #define ASN1_FUNC_H
35 
36 #include "asn1-constants.h"
37 
38 /* Important: this must match the code in asn1-gentables.c */
39 struct node_flag_s {
40  enum tag_class class;
41  int explicit:1;
42  int implicit:1;
43  int has_imports:1;
44  int assignment:1; /* node is an assignment */
45  int one_param:1;
46  int has_tag:1;
47  int has_size:1;
48  int has_list:1;
49  int has_min_max:1;
51  int is_false:1;
52  int is_true:1;
53  int has_default:1; /* node has a default value (fixme:needed???)*/
54  int is_optional:1;
55  int is_implicit:1;
56  int in_set:1;
57  int in_choice:1;
58  int in_array:1;
59  int is_any:1; /* The der-encoder must change any to a real type
60  but still be aware that it actually is any */
61  int not_used:1;
62  int help_down:1; /* helper for create_tree */
63  int help_right:1; /* helper for create_tree */
64  int tag_seen:1;
65  int skip_this:1; /* helper */
66 };
67 
75 };
76 
77 union asn_value_u {
78  int v_bool;
79  char *v_cstr;
80  struct {
81  size_t len;
82  unsigned char *buf;
83  } v_mem;
84  long v_long;
85  unsigned long v_ulong;
86 };
87 
88 
89 /*
90  * Structure definition used for the node of the tree that represents
91  * an ASN.1 DEFINITION.
92  */
93 #ifndef HAVE_TYPEDEFD_ASNNODE
94 typedef struct asn_node_struct *AsnNode;
95 typedef struct asn_node_struct *asn_node_t;
96 #define HAVE_TYPEDEFD_ASNNODE
97 #endif
99  char *name; /* Node name */
101  struct node_flag_s flags;
102 
104  union asn_value_u value;
105  int off; /* offset of this TLV */
106  int nhdr; /* length of the header */
107  int len; /* length part of the TLV */
108  node_type_t actual_type; /* ugly helper to overcome TYPE_ANY probs*/
109 
110  AsnNode down; /* Pointer to the son node */
111  AsnNode right; /* Pointer to the brother node */
112  AsnNode left; /* Pointer to the next list element */
113  AsnNode link_next; /* to keep track of all nodes in a tree */
114 };
115 
116 /* Structure to keep an entire ASN.1 parse tree and associated information */
119  AsnNode node_list; /* for easier release of all nodes */
120  char filename[1];
121 };
122 
123 
124 typedef struct static_struct_asn {
125  unsigned int name_off; /* Node name */
126  node_type_t type; /* Node type */
127  struct node_flag_s flags;
128  unsigned int stringvalue_off;
130 
131 
132 /*-- asn1-parse.y --*/
133 void _ksba_asn_release_nodes (AsnNode node);
134 
135 
136 /*-- asn1-func.c --*/
137 void _ksba_asn_set_value (AsnNode node, enum asn_value_type vtype,
138  const void *value, size_t len);
139 void _ksba_asn_set_name (AsnNode node, const char *name);
142 AsnNode _ksba_asn_find_node(AsnNode pointer,const char *name);
149 AsnNode _ksba_asn_expand_tree (AsnNode parse_tree, const char *name);
151 
154 void _ksba_asn_node_dump (AsnNode p, FILE *fp);
155 void _ksba_asn_node_dump_all (AsnNode root, FILE *fp);
156 
157 AsnNode _ksba_asn_find_type_value (const unsigned char *image,
158  AsnNode root, int idx,
159  const void *oidbuf, size_t oidlen);
160 
161 
163 
164 /*-- asn2-func.c --*/
165 /*(functions are all declared in ksba.h)*/
166 
167 /*-- asn1-tables.c (generated) --*/
169  const char **stringtbl);
170 
171 
172 
173 #endif /*ASN1_FUNC_H*/
node_type_t
tag_class
int _ksba_asn_delete_not_used(AsnNode node)
void _ksba_asn_type_set_config(AsnNode node)
Definition: asn1-func.c:986
struct asn_node_struct * asn_node_t
Definition: asn1-func.h:95
asn_value_type
Definition: asn1-func.h:68
@ VALTYPE_CSTR
Definition: asn1-func.h:71
@ VALTYPE_ULONG
Definition: asn1-func.h:74
@ VALTYPE_MEM
Definition: asn1-func.h:72
@ VALTYPE_BOOL
Definition: asn1-func.h:70
@ VALTYPE_NULL
Definition: asn1-func.h:69
@ VALTYPE_LONG
Definition: asn1-func.h:73
void _ksba_asn_node_dump(AsnNode p, FILE *fp)
Definition: asn1-func.c:450
struct static_struct_asn static_asn
void _ksba_asn_set_value(AsnNode node, enum asn_value_type vtype, const void *value, size_t len)
Definition: asn1-func.c:127
AsnNode _ksba_asn_walk_tree_up_right(AsnNode root, AsnNode node)
Definition: asn1-func.c:825
AsnNode _ksba_asn_find_node(AsnNode pointer, const char *name)
Definition: asn1-func.c:383
void _ksba_asn_set_default_tag(AsnNode node)
Definition: asn1-func.c:953
AsnNode _ksba_asn_insert_copy(AsnNode node)
Definition: asn1-func.c:1258
AsnNode _ksba_asn_new_node(node_type_t type)
Definition: asn1-func.c:80
int _ksba_asn_is_primitive(node_type_t type)
Definition: asn1-func.c:87
const static_asn * _ksba_asn_lookup_table(const char *name, const char **stringtbl)
Definition: asn1-tables.c:1387
AsnNode _ksba_asn_expand_tree(AsnNode parse_tree, const char *name)
Definition: asn1-func.c:1246
struct asn_node_struct * AsnNode
Definition: asn1-func.h:94
void _ksba_asn_node_dump_all(AsnNode root, FILE *fp)
Definition: asn1-func.c:547
int _ksba_asn_delete_structure(AsnNode root)
Definition: asn1-func.c:671
void _ksba_asn_set_name(AsnNode node, const char *name)
Definition: asn1-func.c:239
int _ksba_asn_check_identifier(AsnNode node)
Definition: asn1-func.c:722
AsnNode _ksba_asn_walk_tree(AsnNode root, AsnNode node)
Definition: asn1-func.c:790
int _ksba_asn_expand_object_id(AsnNode node)
Definition: asn1-func.c:882
void _ksba_asn_release_nodes(AsnNode node)
Definition: asn1-parse.c:2886
int _ksba_asn_change_integer_value(AsnNode node)
Definition: asn1-func.c:856
AsnNode _ksba_asn_find_type_value(const unsigned char *image, AsnNode root, int idx, const void *oidbuf, size_t oidlen)
Definition: asn1-func.c:1291
size_t oidlen
Definition: dn.c:55
const char * name
Definition: dn.c:47
union asn_value_u value
Definition: asn1-func.h:104
AsnNode link_next
Definition: asn1-func.h:113
AsnNode right
Definition: asn1-func.h:111
enum asn_value_type valuetype
Definition: asn1-func.h:103
AsnNode down
Definition: asn1-func.h:110
node_type_t type
Definition: asn1-func.h:100
AsnNode left
Definition: asn1-func.h:112
struct node_flag_s flags
Definition: asn1-func.h:101
node_type_t actual_type
Definition: asn1-func.h:108
AsnNode node_list
Definition: asn1-func.h:119
char filename[1]
Definition: asn1-func.h:120
AsnNode parse_tree
Definition: asn1-func.h:118
int one_param
Definition: asn1-func.h:45
int in_array
Definition: asn1-func.h:58
int skip_this
Definition: asn1-func.h:65
int in_choice
Definition: asn1-func.h:57
int tag_seen
Definition: asn1-func.h:64
int has_tag
Definition: asn1-func.h:46
int implicit
Definition: asn1-func.h:42
int has_list
Definition: asn1-func.h:48
int is_optional
Definition: asn1-func.h:54
int has_size
Definition: asn1-func.h:47
int not_used
Definition: asn1-func.h:61
int help_down
Definition: asn1-func.h:62
int has_imports
Definition: asn1-func.h:43
int is_false
Definition: asn1-func.h:51
int in_set
Definition: asn1-func.h:56
int has_default
Definition: asn1-func.h:53
int help_right
Definition: asn1-func.h:63
int assignment
Definition: asn1-func.h:44
int is_implicit
Definition: asn1-func.h:55
int has_defined_by
Definition: asn1-func.h:50
int has_min_max
Definition: asn1-func.h:49
int is_true
Definition: asn1-func.h:52
int is_any
Definition: asn1-func.h:59
node_type_t type
Definition: asn1-func.h:126
unsigned int stringvalue_off
Definition: asn1-func.h:128
struct node_flag_s flags
Definition: asn1-func.h:127
unsigned int name_off
Definition: asn1-func.h:125
long v_long
Definition: asn1-func.h:84
char * v_cstr
Definition: asn1-func.h:79
int v_bool
Definition: asn1-func.h:78
size_t len
Definition: asn1-func.h:81
unsigned long v_ulong
Definition: asn1-func.h:85
unsigned char * buf
Definition: asn1-func.h:82
struct asn_value_u::@1 v_mem