Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame^] | 1 | /*- |
| 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 | */ |
| 13 | typedef 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 */ |
| 18 | asn1_TYPE_descriptor_t |
| 19 | *type; /* Member type descriptor */ |
| 20 | char *name; /* ASN.1 identifier of the element */ |
| 21 | } asn1_SET_element_t; |
| 22 | |
| 23 | /* |
| 24 | * Map between the outmost tag of the element and the corresponding |
| 25 | * element's index. |
| 26 | */ |
| 27 | typedef struct asn1_SET_tag2member_s { |
| 28 | ber_tlv_tag_t el_tag; /* Outmost tag of the member */ |
| 29 | int el_no; /* Index of the associated member, base 0 */ |
| 30 | } asn1_SET_tag2member_t; |
| 31 | |
| 32 | typedef struct asn1_SET_specifics_s { |
| 33 | /* |
| 34 | * Target structure description. |
| 35 | */ |
| 36 | int struct_size; /* Size of the target structure. */ |
| 37 | int ctx_offset; /* Offset of the ber_dec_ctx_t member */ |
| 38 | int pres_offset; /* Offset of _presence_map member */ |
| 39 | |
| 40 | /* |
| 41 | * Members of the SET structure. |
| 42 | */ |
| 43 | asn1_SET_element_t *elements; |
| 44 | int elements_count; |
| 45 | |
| 46 | /* |
| 47 | * Tags to members mapping table (sorted). |
| 48 | */ |
| 49 | asn1_SET_tag2member_t *tag2el; |
| 50 | int tag2el_count; |
| 51 | |
| 52 | /* |
| 53 | * Extensions-related stuff. |
| 54 | */ |
| 55 | int extensible; /* Whether SET is extensible */ |
| 56 | unsigned int *_mandatory_elements; /* Bitmask of mandatory ones */ |
| 57 | } asn1_SET_specifics_t; |
| 58 | |
| 59 | /* |
| 60 | * A set specialized functions dealing with the SET type. |
| 61 | */ |
| 62 | asn_constr_check_f SET_constraint; |
| 63 | ber_type_decoder_f SET_decode_ber; |
| 64 | der_type_encoder_f SET_encode_der; |
| 65 | asn_struct_print_f SET_print; |
| 66 | asn_struct_free_f SET_free; |
| 67 | |
| 68 | /*********************** |
| 69 | * Some handy helpers. * |
| 70 | ***********************/ |
| 71 | |
| 72 | /* |
| 73 | * Figure out whether the SET member indicated by PR_x has already been decoded. |
| 74 | * It is very simple bitfield test, despite its visual complexity. |
| 75 | */ |
| 76 | #define ASN_SET_ISPRESENT(set_ptr, PR_x) \ |
| 77 | ASN_SET_ISPRESENT2(&((set_ptr)->_presence_map)) |
| 78 | #define ASN_SET_ISPRESENT2(map_ptr, PR_x) \ |
| 79 | (((unsigned int *)(map_ptr)) \ |
| 80 | [(PR_x) / (8 * sizeof(unsigned int))] \ |
| 81 | & (1 << ((8 * sizeof(unsigned int)) - 1 \ |
| 82 | - ((PR_x) % (8 * sizeof(unsigned int)))))) |
| 83 | |
| 84 | #define ASN_SET_MKPRESENT(map_ptr, PR_x) \ |
| 85 | (((unsigned int *)(map_ptr)) \ |
| 86 | [(PR_x) / (8 * sizeof(unsigned int))] \ |
| 87 | |= (1 << ((8 * sizeof(unsigned int)) - 1 \ |
| 88 | - ((PR_x) % (8 * sizeof(unsigned int)))))) |
| 89 | |
| 90 | #endif /* _CONSTR_SET_H_ */ |