blob: 8cb3fa8d31ac92b482b7b3cd49873a5af72ee254 [file] [log] [blame]
Lev Walkinf15320b2004-06-03 03:38:44 +00001/*-
2 * Copyright (c) 2003, 2004 Lev Walkin <vlm@lionet.info>. All rights reserved.
3 * Redistribution and modifications are permitted subject to BSD license.
4 */
5#ifndef _CONSTR_SET_H_
6#define _CONSTR_SET_H_
7
8#include <constr_TYPE.h>
9
10/*
11 * Description of a single element of the SET type.
12 */
13typedef struct asn1_SET_element_s {
14 int memb_offset; /* Offset of the element */
15 int optional; /* Whether the element is optional */
16 ber_tlv_tag_t tag; /* Outmost (most immediate) tag */
17 int tag_mode; /* IMPLICIT/no/EXPLICIT tag at current level */
Lev Walkin4c36e302004-06-06 07:20:02 +000018 asn1_TYPE_descriptor_t *type; /* Member type descriptor */
Lev Walkinf15320b2004-06-03 03:38:44 +000019 char *name; /* ASN.1 identifier of the element */
20} asn1_SET_element_t;
21
Lev Walkinf15320b2004-06-03 03:38:44 +000022
23typedef struct asn1_SET_specifics_s {
24 /*
25 * Target structure description.
26 */
27 int struct_size; /* Size of the target structure. */
28 int ctx_offset; /* Offset of the ber_dec_ctx_t member */
29 int pres_offset; /* Offset of _presence_map member */
30
31 /*
32 * Members of the SET structure.
33 */
34 asn1_SET_element_t *elements;
35 int elements_count;
36
37 /*
38 * Tags to members mapping table (sorted).
39 */
Lev Walkin4c36e302004-06-06 07:20:02 +000040 asn1_TYPE_tag2member_t *tag2el;
Lev Walkinf15320b2004-06-03 03:38:44 +000041 int tag2el_count;
42
43 /*
44 * Extensions-related stuff.
45 */
46 int extensible; /* Whether SET is extensible */
47 unsigned int *_mandatory_elements; /* Bitmask of mandatory ones */
48} asn1_SET_specifics_t;
49
50/*
51 * A set specialized functions dealing with the SET type.
52 */
53asn_constr_check_f SET_constraint;
54ber_type_decoder_f SET_decode_ber;
55der_type_encoder_f SET_encode_der;
56asn_struct_print_f SET_print;
57asn_struct_free_f SET_free;
58
59/***********************
60 * Some handy helpers. *
61 ***********************/
62
63/*
64 * Figure out whether the SET member indicated by PR_x has already been decoded.
65 * It is very simple bitfield test, despite its visual complexity.
66 */
67#define ASN_SET_ISPRESENT(set_ptr, PR_x) \
68 ASN_SET_ISPRESENT2(&((set_ptr)->_presence_map))
69#define ASN_SET_ISPRESENT2(map_ptr, PR_x) \
70 (((unsigned int *)(map_ptr)) \
71 [(PR_x) / (8 * sizeof(unsigned int))] \
72 & (1 << ((8 * sizeof(unsigned int)) - 1 \
73 - ((PR_x) % (8 * sizeof(unsigned int))))))
74
75#define ASN_SET_MKPRESENT(map_ptr, PR_x) \
76 (((unsigned int *)(map_ptr)) \
77 [(PR_x) / (8 * sizeof(unsigned int))] \
78 |= (1 << ((8 * sizeof(unsigned int)) - 1 \
79 - ((PR_x) % (8 * sizeof(unsigned int))))))
80
81#endif /* _CONSTR_SET_H_ */