Lev Walkin | 5bbff1e | 2004-06-28 21:13:22 +0000 | [diff] [blame] | 1 | |
Lev Walkin | b47ddce | 2004-08-11 05:25:47 +0000 | [diff] [blame] | 2 | /*** <<< INCLUDES [PrimitiveType] >>> ***/ |
Lev Walkin | 5bbff1e | 2004-06-28 21:13:22 +0000 | [diff] [blame] | 3 | |
| 4 | #include <OCTET_STRING.h> |
| 5 | |
| 6 | /*** <<< TYPE-DECLS [PrimitiveType] >>> ***/ |
| 7 | |
| 8 | |
| 9 | typedef OCTET_STRING_t PrimitiveType_t; |
| 10 | |
Lev Walkin | 5bbff1e | 2004-06-28 21:13:22 +0000 | [diff] [blame] | 11 | /*** <<< FUNC-DECLS [PrimitiveType] >>> ***/ |
| 12 | |
| 13 | extern asn1_TYPE_descriptor_t asn1_DEF_PrimitiveType; |
| 14 | asn_constr_check_f PrimitiveType_constraint; |
| 15 | ber_type_decoder_f PrimitiveType_decode_ber; |
| 16 | der_type_encoder_f PrimitiveType_encode_der; |
| 17 | asn_struct_print_f PrimitiveType_print; |
| 18 | asn_struct_free_f PrimitiveType_free; |
| 19 | |
Lev Walkin | 2e3055d | 2004-08-20 13:36:32 +0000 | [diff] [blame] | 20 | /*** <<< CODE [PrimitiveType] >>> ***/ |
| 21 | |
| 22 | int |
| 23 | PrimitiveType_constraint(asn1_TYPE_descriptor_t *td, const void *sptr, |
| 24 | asn_app_consume_bytes_f *app_errlog, void *app_key) { |
| 25 | |
| 26 | /* Make the underlying type checker permanent */ |
| 27 | td->check_constraints = asn1_DEF_OCTET_STRING.check_constraints; |
| 28 | return td->check_constraints |
| 29 | (td, sptr, app_errlog, app_key); |
| 30 | } |
| 31 | |
| 32 | /* |
| 33 | * This type is implemented using OCTET_STRING, |
| 34 | * so adjust the DEF appropriately. |
| 35 | */ |
| 36 | static void |
| 37 | PrimitiveType_inherit_TYPE_descriptor(asn1_TYPE_descriptor_t *td) { |
| 38 | td->ber_decoder = asn1_DEF_OCTET_STRING.ber_decoder; |
| 39 | td->der_encoder = asn1_DEF_OCTET_STRING.der_encoder; |
| 40 | td->free_struct = asn1_DEF_OCTET_STRING.free_struct; |
| 41 | td->print_struct = asn1_DEF_OCTET_STRING.print_struct; |
| 42 | td->last_tag_form = asn1_DEF_OCTET_STRING.last_tag_form; |
| 43 | td->elements = asn1_DEF_OCTET_STRING.elements; |
| 44 | td->elements_count = asn1_DEF_OCTET_STRING.elements_count; |
| 45 | td->specifics = asn1_DEF_OCTET_STRING.specifics; |
| 46 | } |
| 47 | |
| 48 | ber_dec_rval_t |
| 49 | PrimitiveType_decode_ber(asn1_TYPE_descriptor_t *td, |
| 50 | void **structure, void *bufptr, size_t size, int tag_mode) { |
| 51 | PrimitiveType_inherit_TYPE_descriptor(td); |
| 52 | return td->ber_decoder(td, structure, |
| 53 | bufptr, size, tag_mode); |
| 54 | } |
| 55 | |
| 56 | der_enc_rval_t |
| 57 | PrimitiveType_encode_der(asn1_TYPE_descriptor_t *td, |
| 58 | void *structure, int tag_mode, ber_tlv_tag_t tag, |
| 59 | asn_app_consume_bytes_f *cb, void *app_key) { |
| 60 | PrimitiveType_inherit_TYPE_descriptor(td); |
| 61 | return td->der_encoder(td, structure, tag_mode, tag, cb, app_key); |
| 62 | } |
| 63 | |
| 64 | int |
| 65 | PrimitiveType_print(asn1_TYPE_descriptor_t *td, const void *struct_ptr, |
| 66 | int ilevel, asn_app_consume_bytes_f *cb, void *app_key) { |
| 67 | PrimitiveType_inherit_TYPE_descriptor(td); |
| 68 | return td->print_struct(td, struct_ptr, ilevel, cb, app_key); |
| 69 | } |
| 70 | |
| 71 | void |
| 72 | PrimitiveType_free(asn1_TYPE_descriptor_t *td, |
| 73 | void *struct_ptr, int contents_only) { |
| 74 | PrimitiveType_inherit_TYPE_descriptor(td); |
| 75 | td->free_struct(td, struct_ptr, contents_only); |
| 76 | } |
| 77 | |
| 78 | |
Lev Walkin | 5bbff1e | 2004-06-28 21:13:22 +0000 | [diff] [blame] | 79 | /*** <<< STAT-DEFS [PrimitiveType] >>> ***/ |
| 80 | |
| 81 | static ber_tlv_tag_t asn1_DEF_PrimitiveType_tags[] = { |
| 82 | (ASN_TAG_CLASS_UNIVERSAL | (4 << 2)) |
| 83 | }; |
| 84 | asn1_TYPE_descriptor_t asn1_DEF_PrimitiveType = { |
| 85 | "PrimitiveType", |
| 86 | PrimitiveType_constraint, |
| 87 | PrimitiveType_decode_ber, |
| 88 | PrimitiveType_encode_der, |
| 89 | PrimitiveType_print, |
| 90 | PrimitiveType_free, |
| 91 | 0, /* Use generic outmost tag fetcher */ |
| 92 | asn1_DEF_PrimitiveType_tags, |
| 93 | sizeof(asn1_DEF_PrimitiveType_tags) |
Lev Walkin | 6439972 | 2004-08-11 07:17:22 +0000 | [diff] [blame] | 94 | /sizeof(asn1_DEF_PrimitiveType_tags[0]), /* 1 */ |
Lev Walkin | 5bbff1e | 2004-06-28 21:13:22 +0000 | [diff] [blame] | 95 | 1, /* Tags to skip */ |
| 96 | -0, /* Unknown yet */ |
Lev Walkin | 2e3055d | 2004-08-20 13:36:32 +0000 | [diff] [blame] | 97 | 0, 0, /* No members */ |
Lev Walkin | 5bbff1e | 2004-06-28 21:13:22 +0000 | [diff] [blame] | 98 | 0 /* No specifics */ |
| 99 | }; |
| 100 | |
Lev Walkin | 5bbff1e | 2004-06-28 21:13:22 +0000 | [diff] [blame] | 101 | |
Lev Walkin | b47ddce | 2004-08-11 05:25:47 +0000 | [diff] [blame] | 102 | /*** <<< INCLUDES [ConstructedType] >>> ***/ |
Lev Walkin | 5bbff1e | 2004-06-28 21:13:22 +0000 | [diff] [blame] | 103 | |
Lev Walkin | 5bbff1e | 2004-06-28 21:13:22 +0000 | [diff] [blame] | 104 | #include <PrimitiveType.h> |
Lev Walkin | 5bbff1e | 2004-06-28 21:13:22 +0000 | [diff] [blame] | 105 | #include <constr_SEQUENCE.h> |
| 106 | |
Lev Walkin | b47ddce | 2004-08-11 05:25:47 +0000 | [diff] [blame] | 107 | /*** <<< DEPS [ConstructedType] >>> ***/ |
| 108 | |
Lev Walkin | 5bbff1e | 2004-06-28 21:13:22 +0000 | [diff] [blame] | 109 | extern asn1_TYPE_descriptor_t asn1_DEF_ConstructedType; |
| 110 | |
| 111 | /*** <<< TYPE-DECLS [ConstructedType] >>> ***/ |
| 112 | |
| 113 | |
| 114 | typedef struct ConstructedType { |
| 115 | PrimitiveType_t field; |
| 116 | |
| 117 | /* Context for parsing across buffer boundaries */ |
| 118 | ber_dec_ctx_t _ber_dec_ctx; |
| 119 | } ConstructedType_t; |
| 120 | |
| 121 | /*** <<< STAT-DEFS [ConstructedType] >>> ***/ |
| 122 | |
Lev Walkin | 2e3055d | 2004-08-20 13:36:32 +0000 | [diff] [blame] | 123 | static asn1_TYPE_member_t asn1_MBR_ConstructedType[] = { |
| 124 | { 0, offsetof(struct ConstructedType, field), |
| 125 | .tag = (ASN_TAG_CLASS_CONTEXT | (5 << 2)), |
| 126 | .tag_mode = -1, /* IMPLICIT tag at current level */ |
| 127 | .type = (void *)&asn1_DEF_PrimitiveType, |
| 128 | .memb_constraints = 0, /* Defer to actual type */ |
| 129 | .name = "field" |
Lev Walkin | 5bbff1e | 2004-06-28 21:13:22 +0000 | [diff] [blame] | 130 | }, |
| 131 | }; |
| 132 | static ber_tlv_tag_t asn1_DEF_ConstructedType_tags[] = { |
| 133 | (ASN_TAG_CLASS_UNIVERSAL | (16 << 2)) |
| 134 | }; |
| 135 | static asn1_TYPE_tag2member_t asn1_DEF_ConstructedType_tag2el[] = { |
| 136 | { (ASN_TAG_CLASS_CONTEXT | (5 << 2)), 0, 0, 0 }, /* field at 18 */ |
| 137 | }; |
| 138 | static asn1_SEQUENCE_specifics_t asn1_DEF_ConstructedType_specs = { |
| 139 | sizeof(struct ConstructedType), |
| 140 | offsetof(struct ConstructedType, _ber_dec_ctx), |
Lev Walkin | 5bbff1e | 2004-06-28 21:13:22 +0000 | [diff] [blame] | 141 | asn1_DEF_ConstructedType_tag2el, |
| 142 | 1, /* Count of tags in the map */ |
| 143 | -1, /* Start extensions */ |
| 144 | -1 /* Stop extensions */ |
| 145 | }; |
| 146 | asn1_TYPE_descriptor_t asn1_DEF_ConstructedType = { |
| 147 | "ConstructedType", |
| 148 | SEQUENCE_constraint, |
| 149 | SEQUENCE_decode_ber, |
| 150 | SEQUENCE_encode_der, |
| 151 | SEQUENCE_print, |
| 152 | SEQUENCE_free, |
| 153 | 0, /* Use generic outmost tag fetcher */ |
| 154 | asn1_DEF_ConstructedType_tags, |
| 155 | sizeof(asn1_DEF_ConstructedType_tags) |
Lev Walkin | 6439972 | 2004-08-11 07:17:22 +0000 | [diff] [blame] | 156 | /sizeof(asn1_DEF_ConstructedType_tags[0]), /* 1 */ |
Lev Walkin | 5bbff1e | 2004-06-28 21:13:22 +0000 | [diff] [blame] | 157 | 1, /* Tags to skip */ |
| 158 | 1, /* Whether CONSTRUCTED */ |
Lev Walkin | 2e3055d | 2004-08-20 13:36:32 +0000 | [diff] [blame] | 159 | asn1_MBR_ConstructedType, |
| 160 | 1, /* Elements count */ |
Lev Walkin | 5bbff1e | 2004-06-28 21:13:22 +0000 | [diff] [blame] | 161 | &asn1_DEF_ConstructedType_specs /* Additional specs */ |
| 162 | }; |
| 163 | |
| 164 | |
Lev Walkin | b47ddce | 2004-08-11 05:25:47 +0000 | [diff] [blame] | 165 | /*** <<< INCLUDES [T] >>> ***/ |
Lev Walkin | 5bbff1e | 2004-06-28 21:13:22 +0000 | [diff] [blame] | 166 | |
| 167 | #include <ConstructedType.h> |
| 168 | |
| 169 | /*** <<< TYPE-DECLS [T] >>> ***/ |
| 170 | |
| 171 | |
| 172 | typedef ConstructedType_t T_t; |
| 173 | |
Lev Walkin | 5bbff1e | 2004-06-28 21:13:22 +0000 | [diff] [blame] | 174 | /*** <<< FUNC-DECLS [T] >>> ***/ |
| 175 | |
| 176 | extern asn1_TYPE_descriptor_t asn1_DEF_T; |
| 177 | asn_constr_check_f T_constraint; |
| 178 | ber_type_decoder_f T_decode_ber; |
| 179 | der_type_encoder_f T_encode_der; |
| 180 | asn_struct_print_f T_print; |
| 181 | asn_struct_free_f T_free; |
| 182 | |
Lev Walkin | 2e3055d | 2004-08-20 13:36:32 +0000 | [diff] [blame] | 183 | /*** <<< CODE [T] >>> ***/ |
| 184 | |
| 185 | int |
| 186 | T_constraint(asn1_TYPE_descriptor_t *td, const void *sptr, |
| 187 | asn_app_consume_bytes_f *app_errlog, void *app_key) { |
| 188 | |
| 189 | /* Make the underlying type checker permanent */ |
| 190 | td->check_constraints = asn1_DEF_ConstructedType.check_constraints; |
| 191 | return td->check_constraints |
| 192 | (td, sptr, app_errlog, app_key); |
| 193 | } |
| 194 | |
| 195 | /* |
| 196 | * This type is implemented using ConstructedType, |
| 197 | * so adjust the DEF appropriately. |
| 198 | */ |
| 199 | static void |
| 200 | T_inherit_TYPE_descriptor(asn1_TYPE_descriptor_t *td) { |
| 201 | td->ber_decoder = asn1_DEF_ConstructedType.ber_decoder; |
| 202 | td->der_encoder = asn1_DEF_ConstructedType.der_encoder; |
| 203 | td->free_struct = asn1_DEF_ConstructedType.free_struct; |
| 204 | td->print_struct = asn1_DEF_ConstructedType.print_struct; |
| 205 | td->last_tag_form = asn1_DEF_ConstructedType.last_tag_form; |
| 206 | td->elements = asn1_DEF_ConstructedType.elements; |
| 207 | td->elements_count = asn1_DEF_ConstructedType.elements_count; |
| 208 | td->specifics = asn1_DEF_ConstructedType.specifics; |
| 209 | } |
| 210 | |
| 211 | ber_dec_rval_t |
| 212 | T_decode_ber(asn1_TYPE_descriptor_t *td, |
| 213 | void **structure, void *bufptr, size_t size, int tag_mode) { |
| 214 | T_inherit_TYPE_descriptor(td); |
| 215 | return td->ber_decoder(td, structure, |
| 216 | bufptr, size, tag_mode); |
| 217 | } |
| 218 | |
| 219 | der_enc_rval_t |
| 220 | T_encode_der(asn1_TYPE_descriptor_t *td, |
| 221 | void *structure, int tag_mode, ber_tlv_tag_t tag, |
| 222 | asn_app_consume_bytes_f *cb, void *app_key) { |
| 223 | T_inherit_TYPE_descriptor(td); |
| 224 | return td->der_encoder(td, structure, tag_mode, tag, cb, app_key); |
| 225 | } |
| 226 | |
| 227 | int |
| 228 | T_print(asn1_TYPE_descriptor_t *td, const void *struct_ptr, |
| 229 | int ilevel, asn_app_consume_bytes_f *cb, void *app_key) { |
| 230 | T_inherit_TYPE_descriptor(td); |
| 231 | return td->print_struct(td, struct_ptr, ilevel, cb, app_key); |
| 232 | } |
| 233 | |
| 234 | void |
| 235 | T_free(asn1_TYPE_descriptor_t *td, |
| 236 | void *struct_ptr, int contents_only) { |
| 237 | T_inherit_TYPE_descriptor(td); |
| 238 | td->free_struct(td, struct_ptr, contents_only); |
| 239 | } |
| 240 | |
| 241 | |
Lev Walkin | 5bbff1e | 2004-06-28 21:13:22 +0000 | [diff] [blame] | 242 | /*** <<< STAT-DEFS [T] >>> ***/ |
| 243 | |
| 244 | static ber_tlv_tag_t asn1_DEF_T_tags[] = { |
| 245 | (ASN_TAG_CLASS_CONTEXT | (3 << 2)) |
| 246 | }; |
| 247 | asn1_TYPE_descriptor_t asn1_DEF_T = { |
| 248 | "T", |
| 249 | T_constraint, |
| 250 | T_decode_ber, |
| 251 | T_encode_der, |
| 252 | T_print, |
| 253 | T_free, |
| 254 | 0, /* Use generic outmost tag fetcher */ |
| 255 | asn1_DEF_T_tags, |
| 256 | sizeof(asn1_DEF_T_tags) |
Lev Walkin | 6439972 | 2004-08-11 07:17:22 +0000 | [diff] [blame] | 257 | /sizeof(asn1_DEF_T_tags[0]), /* 1 */ |
Lev Walkin | 5bbff1e | 2004-06-28 21:13:22 +0000 | [diff] [blame] | 258 | 1, /* Tags to skip */ |
| 259 | -0, /* Unknown yet */ |
Lev Walkin | 2e3055d | 2004-08-20 13:36:32 +0000 | [diff] [blame] | 260 | 0, 0, /* Defined elsewhere */ |
Lev Walkin | 5bbff1e | 2004-06-28 21:13:22 +0000 | [diff] [blame] | 261 | 0 /* No specifics */ |
| 262 | }; |
| 263 | |