| 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 |
unsigned int explicit:1; |
| 42 |
unsigned int implicit:1; |
| 43 |
unsigned int has_imports:1; |
| 44 |
unsigned int assignment:1; /* node is an assignment */ |
| 45 |
unsigned int one_param:1; |
| 46 |
unsigned int has_tag:1; |
| 47 |
unsigned int has_size:1; |
| 48 |
unsigned int has_list:1; |
| 49 |
unsigned int has_min_max:1; |
| 50 |
unsigned int has_defined_by:1; |
| 51 |
unsigned int is_false:1; |
| 52 |
unsigned int is_true:1; |
| 53 |
unsigned int has_default:1; /* node has a default value (fixme:needed???)*/ |
| 54 |
unsigned int is_optional:1; |
| 55 |
unsigned int is_implicit:1; |
| 56 |
unsigned int in_set:1; |
| 57 |
unsigned int in_choice:1; |
| 58 |
unsigned int in_array:1; |
| 59 |
unsigned 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 |
unsigned int not_used:1; |
| 62 |
unsigned int help_down:1; /* helper for create_tree */ |
| 63 |
unsigned int help_right:1; /* helper for create_tree */ |
| 64 |
unsigned int tag_seen:1; |
| 65 |
unsigned int skip_this:1; /* helper */ |
| 66 |
}; |
| 67 |
|
| 68 |
enum asn_value_type { |
| 69 |
VALTYPE_NULL = 0, |
| 70 |
VALTYPE_BOOL, |
| 71 |
VALTYPE_CSTR, |
| 72 |
VALTYPE_MEM, |
| 73 |
VALTYPE_LONG, |
| 74 |
VALTYPE_ULONG |
| 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 |
| 98 |
struct asn_node_struct { |
| 99 |
char *name; /* Node name */ |
| 100 |
node_type_t type; |
| 101 |
struct node_flag_s flags; |
| 102 |
|
| 103 |
enum asn_value_type valuetype; |
| 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 */ |
| 117 |
struct ksba_asn_tree_s { |
| 118 |
AsnNode parse_tree; |
| 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; |
| 129 |
} static_asn; |
| 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); |
| 140 |
AsnNode _ksba_asn_walk_tree (AsnNode root, AsnNode node); |
| 141 |
AsnNode _ksba_asn_walk_tree_up_right (AsnNode root, AsnNode node); |
| 142 |
AsnNode _ksba_asn_find_node(AsnNode pointer,const char *name); |
| 143 |
int _ksba_asn_check_identifier(AsnNode node); |
| 144 |
int _ksba_asn_change_integer_value(AsnNode node); |
| 145 |
int _ksba_asn_delete_not_used(AsnNode node); |
| 146 |
int _ksba_asn_expand_object_id(AsnNode node); |
| 147 |
void _ksba_asn_set_default_tag (AsnNode node); |
| 148 |
void _ksba_asn_type_set_config (AsnNode node); |
| 149 |
AsnNode _ksba_asn_expand_tree (AsnNode parse_tree, const char *name); |
| 150 |
AsnNode _ksba_asn_insert_copy (AsnNode node); |
| 151 |
|
| 152 |
int _ksba_asn_is_primitive (node_type_t type); |
| 153 |
AsnNode _ksba_asn_new_node (node_type_t type); |
| 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 |
|
| 162 |
int _ksba_asn_delete_structure (AsnNode root); |
| 163 |
|
| 164 |
/*-- asn2-func.c --*/ |
| 165 |
/*(functions are all declared in ksba.h)*/ |
| 166 |
|
| 167 |
/*-- asn1-tables.c (generated) --*/ |
| 168 |
const static_asn *_ksba_asn_lookup_table (const char *name, |
| 169 |
const char **stringtbl); |
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
#endif /*ASN1_FUNC_H*/ |