Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1 | /*- |
Lev Walkin | 59b176e | 2005-11-26 11:25:14 +0000 | [diff] [blame] | 2 | * Copyright (c) 2003, 2005 Lev Walkin <vlm@lionet.info>. All rights reserved. |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 3 | * Redistribution and modifications are permitted subject to BSD license. |
| 4 | */ |
Lev Walkin | a9cc46e | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 5 | #include <asn_internal.h> |
Lev Walkin | b8ec15d | 2004-10-22 08:20:32 +0000 | [diff] [blame] | 6 | #include <asn_codecs_prim.h> |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 7 | #include <NULL.h> |
| 8 | #include <BOOLEAN.h> /* Implemented in terms of BOOLEAN type */ |
| 9 | |
| 10 | /* |
| 11 | * NULL basic type description. |
| 12 | */ |
Wim Lewis | 18c2ec9 | 2014-07-29 11:30:10 -0700 | [diff] [blame] | 13 | static const ber_tlv_tag_t asn_DEF_NULL_tags[] = { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 14 | (ASN_TAG_CLASS_UNIVERSAL | (5 << 2)) |
| 15 | }; |
Bi-Ruei, Chiu | 1f87ac0 | 2017-08-20 01:25:45 +0800 | [diff] [blame] | 16 | asn_TYPE_operation_t asn_OP_NULL = { |
Lev Walkin | a9cc46e | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 17 | BOOLEAN_free, |
| 18 | NULL_print, |
Lev Walkin | cd2f48e | 2017-08-10 02:14:59 -0700 | [diff] [blame] | 19 | NULL_compare, |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 20 | BOOLEAN_decode_ber, /* Implemented in terms of BOOLEAN */ |
| 21 | NULL_encode_der, /* Special handling of DER encoding */ |
Lev Walkin | b8ec15d | 2004-10-22 08:20:32 +0000 | [diff] [blame] | 22 | NULL_decode_xer, |
| 23 | NULL_encode_xer, |
Lev Walkin | cc15947 | 2017-07-06 08:26:36 -0700 | [diff] [blame] | 24 | #ifdef ASN_DISABLE_OER_SUPPORT |
| 25 | 0, |
| 26 | 0, |
| 27 | #else |
Lev Walkin | aa7c5a6 | 2017-08-30 17:41:32 -0700 | [diff] [blame] | 28 | NULL_decode_oer, |
| 29 | NULL_encode_oer, |
Lev Walkin | cc15947 | 2017-07-06 08:26:36 -0700 | [diff] [blame] | 30 | #endif /* ASN_DISABLE_OER_SUPPORT */ |
Lev Walkin | b33425f | 2017-07-14 14:59:52 +0400 | [diff] [blame] | 31 | #ifdef ASN_DISABLE_PER_SUPPORT |
| 32 | 0, |
| 33 | 0, |
| 34 | #else |
| 35 | NULL_decode_uper, /* Unaligned PER decoder */ |
| 36 | NULL_encode_uper, /* Unaligned PER encoder */ |
| 37 | #endif /* ASN_DISABLE_PER_SUPPORT */ |
Lev Walkin | a5972be | 2017-09-29 23:15:58 -0700 | [diff] [blame] | 38 | NULL_random_fill, |
Bi-Ruei, Chiu | 1f87ac0 | 2017-08-20 01:25:45 +0800 | [diff] [blame] | 39 | 0 /* Use generic outmost tag fetcher */ |
| 40 | }; |
| 41 | asn_TYPE_descriptor_t asn_DEF_NULL = { |
| 42 | "NULL", |
| 43 | "NULL", |
| 44 | &asn_OP_NULL, |
Lev Walkin | 5e03376 | 2004-09-29 13:26:15 +0000 | [diff] [blame] | 45 | asn_DEF_NULL_tags, |
| 46 | sizeof(asn_DEF_NULL_tags) / sizeof(asn_DEF_NULL_tags[0]), |
| 47 | asn_DEF_NULL_tags, /* Same as above */ |
| 48 | sizeof(asn_DEF_NULL_tags) / sizeof(asn_DEF_NULL_tags[0]), |
Lev Walkin | a5972be | 2017-09-29 23:15:58 -0700 | [diff] [blame] | 49 | { 0, 0, asn_generic_no_constraint }, |
Lev Walkin | 449f832 | 2004-08-20 13:23:42 +0000 | [diff] [blame] | 50 | 0, 0, /* No members */ |
Lev Walkin | d9bd775 | 2004-06-05 08:17:50 +0000 | [diff] [blame] | 51 | 0 /* No specifics */ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 52 | }; |
| 53 | |
Lev Walkin | a9cc46e | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 54 | asn_enc_rval_t |
Lev Walkin | 20696a4 | 2017-10-17 21:27:33 -0700 | [diff] [blame] | 55 | NULL_encode_der(const asn_TYPE_descriptor_t *td, const void *ptr, int tag_mode, |
| 56 | ber_tlv_tag_t tag, asn_app_consume_bytes_f *cb, void *app_key) { |
| 57 | asn_enc_rval_t erval; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 58 | |
Lev Walkin | 8e8078a | 2004-09-26 13:10:40 +0000 | [diff] [blame] | 59 | erval.encoded = der_write_tags(td, 0, tag_mode, 0, tag, cb, app_key); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 60 | if(erval.encoded == -1) { |
Lev Walkin | a9cc46e | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 61 | erval.failed_type = td; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 62 | erval.structure_ptr = ptr; |
| 63 | } |
| 64 | |
Lev Walkin | 7c1dc05 | 2016-03-14 03:08:15 -0700 | [diff] [blame] | 65 | ASN__ENCODED_OK(erval); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 66 | } |
| 67 | |
Lev Walkin | a9cc46e | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 68 | asn_enc_rval_t |
Lev Walkin | 20696a4 | 2017-10-17 21:27:33 -0700 | [diff] [blame] | 69 | NULL_encode_xer(const asn_TYPE_descriptor_t *td, const void *sptr, int ilevel, |
| 70 | enum xer_encoder_flags_e flags, asn_app_consume_bytes_f *cb, |
| 71 | void *app_key) { |
| 72 | asn_enc_rval_t er; |
Lev Walkin | a9cc46e | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 73 | |
| 74 | (void)td; |
| 75 | (void)sptr; |
| 76 | (void)ilevel; |
| 77 | (void)flags; |
| 78 | (void)cb; |
| 79 | (void)app_key; |
| 80 | |
| 81 | /* XMLNullValue is empty */ |
| 82 | er.encoded = 0; |
Lev Walkin | 7c1dc05 | 2016-03-14 03:08:15 -0700 | [diff] [blame] | 83 | ASN__ENCODED_OK(er); |
Lev Walkin | a9cc46e | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 84 | } |
| 85 | |
Lev Walkin | b8ec15d | 2004-10-22 08:20:32 +0000 | [diff] [blame] | 86 | |
Lev Walkin | 0fab1a6 | 2005-03-09 22:19:25 +0000 | [diff] [blame] | 87 | static enum xer_pbd_rval |
Lev Walkin | 20696a4 | 2017-10-17 21:27:33 -0700 | [diff] [blame] | 88 | NULL__xer_body_decode(const asn_TYPE_descriptor_t *td, void *sptr, |
| 89 | const void *chunk_buf, size_t chunk_size) { |
| 90 | (void)td; |
Lev Walkin | b8ec15d | 2004-10-22 08:20:32 +0000 | [diff] [blame] | 91 | (void)sptr; |
Lev Walkin | bfc76e8 | 2014-01-14 02:44:54 -0800 | [diff] [blame] | 92 | (void)chunk_buf; /* Going to be empty according to the rules below. */ |
Lev Walkin | 0fab1a6 | 2005-03-09 22:19:25 +0000 | [diff] [blame] | 93 | |
Lev Walkin | f798228 | 2013-03-16 07:01:42 -0700 | [diff] [blame] | 94 | /* |
| 95 | * There must be no content in self-terminating <NULL/> tag. |
| 96 | */ |
| 97 | if(chunk_size) |
Lev Walkin | 0fab1a6 | 2005-03-09 22:19:25 +0000 | [diff] [blame] | 98 | return XPBD_BROKEN_ENCODING; |
Lev Walkin | f798228 | 2013-03-16 07:01:42 -0700 | [diff] [blame] | 99 | else |
| 100 | return XPBD_BODY_CONSUMED; |
Lev Walkin | b8ec15d | 2004-10-22 08:20:32 +0000 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | asn_dec_rval_t |
Lev Walkin | afbf2a9 | 2017-09-12 23:30:27 -0700 | [diff] [blame] | 104 | NULL_decode_xer(const asn_codec_ctx_t *opt_codec_ctx, |
Lev Walkin | 20696a4 | 2017-10-17 21:27:33 -0700 | [diff] [blame] | 105 | const asn_TYPE_descriptor_t *td, void **sptr, |
| 106 | const char *opt_mname, const void *buf_ptr, size_t size) { |
| 107 | return xer_decode_primitive(opt_codec_ctx, td, |
Lev Walkin | b8ec15d | 2004-10-22 08:20:32 +0000 | [diff] [blame] | 108 | sptr, sizeof(NULL_t), opt_mname, buf_ptr, size, |
| 109 | NULL__xer_body_decode); |
| 110 | } |
| 111 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 112 | int |
Lev Walkin | cd2f48e | 2017-08-10 02:14:59 -0700 | [diff] [blame] | 113 | NULL_compare(const asn_TYPE_descriptor_t *td, const void *a, const void *b) { |
| 114 | (void)td; |
| 115 | (void)a; |
| 116 | (void)b; |
| 117 | return 0; |
| 118 | } |
| 119 | |
| 120 | int |
Lev Walkin | 20696a4 | 2017-10-17 21:27:33 -0700 | [diff] [blame] | 121 | NULL_print(const asn_TYPE_descriptor_t *td, const void *sptr, int ilevel, |
| 122 | asn_app_consume_bytes_f *cb, void *app_key) { |
| 123 | (void)td; /* Unused argument */ |
Lev Walkin | d9bd775 | 2004-06-05 08:17:50 +0000 | [diff] [blame] | 124 | (void)ilevel; /* Unused argument */ |
| 125 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 126 | if(sptr) { |
Lev Walkin | 8e8078a | 2004-09-26 13:10:40 +0000 | [diff] [blame] | 127 | return (cb("<present>", 9, app_key) < 0) ? -1 : 0; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 128 | } else { |
Lev Walkin | 8e8078a | 2004-09-26 13:10:40 +0000 | [diff] [blame] | 129 | return (cb("<absent>", 8, app_key) < 0) ? -1 : 0; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 130 | } |
| 131 | } |
Lev Walkin | 59b176e | 2005-11-26 11:25:14 +0000 | [diff] [blame] | 132 | |
Lev Walkin | aa7c5a6 | 2017-08-30 17:41:32 -0700 | [diff] [blame] | 133 | #ifndef ASN_DISABLE_OER_SUPPORT |
| 134 | |
| 135 | asn_dec_rval_t |
Lev Walkin | 20696a4 | 2017-10-17 21:27:33 -0700 | [diff] [blame] | 136 | NULL_decode_oer(const asn_codec_ctx_t *opt_codec_ctx, |
| 137 | const asn_TYPE_descriptor_t *td, |
| 138 | const asn_oer_constraints_t *constraints, void **struct_ptr, |
| 139 | const void *ptr, size_t size) { |
Lev Walkin | aa7c5a6 | 2017-08-30 17:41:32 -0700 | [diff] [blame] | 140 | asn_dec_rval_t rv = {RC_OK, 0}; |
| 141 | (void)opt_codec_ctx; |
| 142 | (void)td; |
| 143 | (void)constraints; |
| 144 | (void)struct_ptr; |
| 145 | (void)ptr; |
| 146 | (void)size; |
| 147 | return rv; |
| 148 | } |
| 149 | |
| 150 | asn_enc_rval_t |
Lev Walkin | 20696a4 | 2017-10-17 21:27:33 -0700 | [diff] [blame] | 151 | NULL_encode_oer(const asn_TYPE_descriptor_t *td, |
| 152 | const asn_oer_constraints_t *constraints, const void *sptr, |
Lev Walkin | aa7c5a6 | 2017-08-30 17:41:32 -0700 | [diff] [blame] | 153 | asn_app_consume_bytes_f *cb, void *app_key) { |
Lev Walkin | 0b59763 | 2017-09-12 22:37:25 -0700 | [diff] [blame] | 154 | asn_enc_rval_t er; |
Lev Walkin | aa7c5a6 | 2017-08-30 17:41:32 -0700 | [diff] [blame] | 155 | |
Lev Walkin | 91da82f | 2017-09-12 23:05:16 -0700 | [diff] [blame] | 156 | (void)td; |
| 157 | (void)sptr; |
Lev Walkin | aa7c5a6 | 2017-08-30 17:41:32 -0700 | [diff] [blame] | 158 | (void)constraints; |
| 159 | (void)cb; |
| 160 | (void)app_key; |
| 161 | |
Lev Walkin | 0b59763 | 2017-09-12 22:37:25 -0700 | [diff] [blame] | 162 | er.encoded = 0; /* Encoding in 0 bytes. */ |
| 163 | |
| 164 | ASN__ENCODED_OK(er); |
Lev Walkin | aa7c5a6 | 2017-08-30 17:41:32 -0700 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | #endif /* ASN_DISABLE_OER_SUPPORT */ |
| 168 | |
| 169 | #ifndef ASN_DISABLE_PER_SUPPORT |
| 170 | |
Lev Walkin | 59b176e | 2005-11-26 11:25:14 +0000 | [diff] [blame] | 171 | asn_dec_rval_t |
Lev Walkin | 20696a4 | 2017-10-17 21:27:33 -0700 | [diff] [blame] | 172 | NULL_decode_uper(const asn_codec_ctx_t *opt_codec_ctx, |
| 173 | const asn_TYPE_descriptor_t *td, |
Lev Walkin | 494fb70 | 2017-08-07 20:07:00 -0700 | [diff] [blame] | 174 | const asn_per_constraints_t *constraints, void **sptr, |
| 175 | asn_per_data_t *pd) { |
| 176 | asn_dec_rval_t rv; |
Lev Walkin | 59b176e | 2005-11-26 11:25:14 +0000 | [diff] [blame] | 177 | |
| 178 | (void)opt_codec_ctx; |
| 179 | (void)td; |
| 180 | (void)constraints; |
| 181 | (void)pd; |
| 182 | |
| 183 | if(!*sptr) { |
| 184 | *sptr = MALLOC(sizeof(NULL_t)); |
| 185 | if(*sptr) { |
| 186 | *(NULL_t *)*sptr = 0; |
| 187 | } else { |
Lev Walkin | 7c1dc05 | 2016-03-14 03:08:15 -0700 | [diff] [blame] | 188 | ASN__DECODE_FAILED; |
Lev Walkin | 59b176e | 2005-11-26 11:25:14 +0000 | [diff] [blame] | 189 | } |
| 190 | } |
| 191 | |
| 192 | /* |
| 193 | * NULL type does not have content octets. |
| 194 | */ |
| 195 | |
| 196 | rv.code = RC_OK; |
| 197 | rv.consumed = 0; |
| 198 | return rv; |
| 199 | } |
Lev Walkin | 523de9e | 2006-08-18 01:34:18 +0000 | [diff] [blame] | 200 | |
| 201 | asn_enc_rval_t |
Lev Walkin | 20696a4 | 2017-10-17 21:27:33 -0700 | [diff] [blame] | 202 | NULL_encode_uper(const asn_TYPE_descriptor_t *td, |
| 203 | const asn_per_constraints_t *constraints, const void *sptr, |
Lev Walkin | 494fb70 | 2017-08-07 20:07:00 -0700 | [diff] [blame] | 204 | asn_per_outp_t *po) { |
| 205 | asn_enc_rval_t er; |
Lev Walkin | 523de9e | 2006-08-18 01:34:18 +0000 | [diff] [blame] | 206 | |
| 207 | (void)td; |
| 208 | (void)constraints; |
| 209 | (void)sptr; |
| 210 | (void)po; |
| 211 | |
| 212 | er.encoded = 0; |
Lev Walkin | 7c1dc05 | 2016-03-14 03:08:15 -0700 | [diff] [blame] | 213 | ASN__ENCODED_OK(er); |
Lev Walkin | 523de9e | 2006-08-18 01:34:18 +0000 | [diff] [blame] | 214 | } |
Lev Walkin | aa7c5a6 | 2017-08-30 17:41:32 -0700 | [diff] [blame] | 215 | |
| 216 | #endif /* ASN_DISABLE_PER_SUPPORT */ |
Lev Walkin | a5972be | 2017-09-29 23:15:58 -0700 | [diff] [blame] | 217 | |
| 218 | asn_random_fill_result_t |
| 219 | NULL_random_fill(const asn_TYPE_descriptor_t *td, void **sptr, |
| 220 | const asn_encoding_constraints_t *constr, |
| 221 | size_t max_length) { |
| 222 | asn_random_fill_result_t result_ok = {ARFILL_OK, 1}; |
| 223 | asn_random_fill_result_t result_failed = {ARFILL_FAILED, 0}; |
| 224 | asn_random_fill_result_t result_skipped = {ARFILL_SKIPPED, 0}; |
| 225 | NULL_t *st = *sptr; |
| 226 | |
| 227 | (void)td; |
| 228 | (void)constr; |
| 229 | |
| 230 | if(max_length == 0) return result_skipped; |
| 231 | |
| 232 | if(st == NULL) { |
| 233 | st = (NULL_t *)(*sptr = CALLOC(1, sizeof(*st))); |
| 234 | if(st == NULL) { |
| 235 | return result_failed; |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | return result_ok; |
| 240 | } |
| 241 | |