blob: 77a377e11ec568faebc489fda28dbc5e7137c66f [file] [log] [blame]
Lev Walkinf15320b2004-06-03 03:38:44 +00001/*-
Lev Walkin59b176e2005-11-26 11:25:14 +00002 * Copyright (c) 2003, 2005 Lev Walkin <vlm@lionet.info>. All rights reserved.
Lev Walkinf15320b2004-06-03 03:38:44 +00003 * Redistribution and modifications are permitted subject to BSD license.
4 */
Lev Walkina9cc46e2004-09-22 16:06:28 +00005#include <asn_internal.h>
Lev Walkinb8ec15d2004-10-22 08:20:32 +00006#include <asn_codecs_prim.h>
Lev Walkinf15320b2004-06-03 03:38:44 +00007#include <NULL.h>
8#include <BOOLEAN.h> /* Implemented in terms of BOOLEAN type */
9
10/*
11 * NULL basic type description.
12 */
Wim Lewis18c2ec92014-07-29 11:30:10 -070013static const ber_tlv_tag_t asn_DEF_NULL_tags[] = {
Lev Walkinf15320b2004-06-03 03:38:44 +000014 (ASN_TAG_CLASS_UNIVERSAL | (5 << 2))
15};
Bi-Ruei, Chiu1f87ac02017-08-20 01:25:45 +080016asn_TYPE_operation_t asn_OP_NULL = {
Lev Walkina9cc46e2004-09-22 16:06:28 +000017 BOOLEAN_free,
18 NULL_print,
Lev Walkincd2f48e2017-08-10 02:14:59 -070019 NULL_compare,
Lev Walkinf15320b2004-06-03 03:38:44 +000020 BOOLEAN_decode_ber, /* Implemented in terms of BOOLEAN */
21 NULL_encode_der, /* Special handling of DER encoding */
Lev Walkinb8ec15d2004-10-22 08:20:32 +000022 NULL_decode_xer,
23 NULL_encode_xer,
Lev Walkincc159472017-07-06 08:26:36 -070024#ifdef ASN_DISABLE_OER_SUPPORT
25 0,
26 0,
27#else
Lev Walkinaa7c5a62017-08-30 17:41:32 -070028 NULL_decode_oer,
29 NULL_encode_oer,
Lev Walkincc159472017-07-06 08:26:36 -070030#endif /* ASN_DISABLE_OER_SUPPORT */
Lev Walkinb33425f2017-07-14 14:59:52 +040031#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 Walkina5972be2017-09-29 23:15:58 -070038 NULL_random_fill,
Bi-Ruei, Chiu1f87ac02017-08-20 01:25:45 +080039 0 /* Use generic outmost tag fetcher */
40};
41asn_TYPE_descriptor_t asn_DEF_NULL = {
42 "NULL",
43 "NULL",
44 &asn_OP_NULL,
Lev Walkin5e033762004-09-29 13:26:15 +000045 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 Walkina5972be2017-09-29 23:15:58 -070049 { 0, 0, asn_generic_no_constraint },
Lev Walkin449f8322004-08-20 13:23:42 +000050 0, 0, /* No members */
Lev Walkind9bd7752004-06-05 08:17:50 +000051 0 /* No specifics */
Lev Walkinf15320b2004-06-03 03:38:44 +000052};
53
Lev Walkina9cc46e2004-09-22 16:06:28 +000054asn_enc_rval_t
Lev Walkin20696a42017-10-17 21:27:33 -070055NULL_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 Walkinf15320b2004-06-03 03:38:44 +000058
Lev Walkin8e8078a2004-09-26 13:10:40 +000059 erval.encoded = der_write_tags(td, 0, tag_mode, 0, tag, cb, app_key);
Lev Walkinf15320b2004-06-03 03:38:44 +000060 if(erval.encoded == -1) {
Lev Walkina9cc46e2004-09-22 16:06:28 +000061 erval.failed_type = td;
Lev Walkinf15320b2004-06-03 03:38:44 +000062 erval.structure_ptr = ptr;
63 }
64
Lev Walkin7c1dc052016-03-14 03:08:15 -070065 ASN__ENCODED_OK(erval);
Lev Walkinf15320b2004-06-03 03:38:44 +000066}
67
Lev Walkina9cc46e2004-09-22 16:06:28 +000068asn_enc_rval_t
Lev Walkin20696a42017-10-17 21:27:33 -070069NULL_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 Walkina9cc46e2004-09-22 16:06:28 +000073
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 Walkin7c1dc052016-03-14 03:08:15 -070083 ASN__ENCODED_OK(er);
Lev Walkina9cc46e2004-09-22 16:06:28 +000084}
85
Lev Walkinb8ec15d2004-10-22 08:20:32 +000086
Lev Walkin0fab1a62005-03-09 22:19:25 +000087static enum xer_pbd_rval
Lev Walkin20696a42017-10-17 21:27:33 -070088NULL__xer_body_decode(const asn_TYPE_descriptor_t *td, void *sptr,
89 const void *chunk_buf, size_t chunk_size) {
90 (void)td;
Lev Walkinb8ec15d2004-10-22 08:20:32 +000091 (void)sptr;
Lev Walkinbfc76e82014-01-14 02:44:54 -080092 (void)chunk_buf; /* Going to be empty according to the rules below. */
Lev Walkin0fab1a62005-03-09 22:19:25 +000093
Lev Walkinf7982282013-03-16 07:01:42 -070094 /*
95 * There must be no content in self-terminating <NULL/> tag.
96 */
97 if(chunk_size)
Lev Walkin0fab1a62005-03-09 22:19:25 +000098 return XPBD_BROKEN_ENCODING;
Lev Walkinf7982282013-03-16 07:01:42 -070099 else
100 return XPBD_BODY_CONSUMED;
Lev Walkinb8ec15d2004-10-22 08:20:32 +0000101}
102
103asn_dec_rval_t
Lev Walkinafbf2a92017-09-12 23:30:27 -0700104NULL_decode_xer(const asn_codec_ctx_t *opt_codec_ctx,
Lev Walkin20696a42017-10-17 21:27:33 -0700105 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 Walkinb8ec15d2004-10-22 08:20:32 +0000108 sptr, sizeof(NULL_t), opt_mname, buf_ptr, size,
109 NULL__xer_body_decode);
110}
111
Lev Walkinf15320b2004-06-03 03:38:44 +0000112int
Lev Walkincd2f48e2017-08-10 02:14:59 -0700113NULL_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
120int
Lev Walkin20696a42017-10-17 21:27:33 -0700121NULL_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 Walkind9bd7752004-06-05 08:17:50 +0000124 (void)ilevel; /* Unused argument */
125
Lev Walkinf15320b2004-06-03 03:38:44 +0000126 if(sptr) {
Lev Walkin8e8078a2004-09-26 13:10:40 +0000127 return (cb("<present>", 9, app_key) < 0) ? -1 : 0;
Lev Walkinf15320b2004-06-03 03:38:44 +0000128 } else {
Lev Walkin8e8078a2004-09-26 13:10:40 +0000129 return (cb("<absent>", 8, app_key) < 0) ? -1 : 0;
Lev Walkinf15320b2004-06-03 03:38:44 +0000130 }
131}
Lev Walkin59b176e2005-11-26 11:25:14 +0000132
Lev Walkinaa7c5a62017-08-30 17:41:32 -0700133#ifndef ASN_DISABLE_OER_SUPPORT
134
135asn_dec_rval_t
Lev Walkin20696a42017-10-17 21:27:33 -0700136NULL_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 Walkinaa7c5a62017-08-30 17:41:32 -0700140 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
150asn_enc_rval_t
Lev Walkin20696a42017-10-17 21:27:33 -0700151NULL_encode_oer(const asn_TYPE_descriptor_t *td,
152 const asn_oer_constraints_t *constraints, const void *sptr,
Lev Walkinaa7c5a62017-08-30 17:41:32 -0700153 asn_app_consume_bytes_f *cb, void *app_key) {
Lev Walkin0b597632017-09-12 22:37:25 -0700154 asn_enc_rval_t er;
Lev Walkinaa7c5a62017-08-30 17:41:32 -0700155
Lev Walkin91da82f2017-09-12 23:05:16 -0700156 (void)td;
157 (void)sptr;
Lev Walkinaa7c5a62017-08-30 17:41:32 -0700158 (void)constraints;
159 (void)cb;
160 (void)app_key;
161
Lev Walkin0b597632017-09-12 22:37:25 -0700162 er.encoded = 0; /* Encoding in 0 bytes. */
163
164 ASN__ENCODED_OK(er);
Lev Walkinaa7c5a62017-08-30 17:41:32 -0700165}
166
167#endif /* ASN_DISABLE_OER_SUPPORT */
168
169#ifndef ASN_DISABLE_PER_SUPPORT
170
Lev Walkin59b176e2005-11-26 11:25:14 +0000171asn_dec_rval_t
Lev Walkin20696a42017-10-17 21:27:33 -0700172NULL_decode_uper(const asn_codec_ctx_t *opt_codec_ctx,
173 const asn_TYPE_descriptor_t *td,
Lev Walkin494fb702017-08-07 20:07:00 -0700174 const asn_per_constraints_t *constraints, void **sptr,
175 asn_per_data_t *pd) {
176 asn_dec_rval_t rv;
Lev Walkin59b176e2005-11-26 11:25:14 +0000177
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 Walkin7c1dc052016-03-14 03:08:15 -0700188 ASN__DECODE_FAILED;
Lev Walkin59b176e2005-11-26 11:25:14 +0000189 }
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 Walkin523de9e2006-08-18 01:34:18 +0000200
201asn_enc_rval_t
Lev Walkin20696a42017-10-17 21:27:33 -0700202NULL_encode_uper(const asn_TYPE_descriptor_t *td,
203 const asn_per_constraints_t *constraints, const void *sptr,
Lev Walkin494fb702017-08-07 20:07:00 -0700204 asn_per_outp_t *po) {
205 asn_enc_rval_t er;
Lev Walkin523de9e2006-08-18 01:34:18 +0000206
207 (void)td;
208 (void)constraints;
209 (void)sptr;
210 (void)po;
211
212 er.encoded = 0;
Lev Walkin7c1dc052016-03-14 03:08:15 -0700213 ASN__ENCODED_OK(er);
Lev Walkin523de9e2006-08-18 01:34:18 +0000214}
Lev Walkinaa7c5a62017-08-30 17:41:32 -0700215
216#endif /* ASN_DISABLE_PER_SUPPORT */
Lev Walkina5972be2017-09-29 23:15:58 -0700217
218asn_random_fill_result_t
219NULL_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