blob: ed7f853daa9c74acff7678854ab5b53e00df7653 [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 Walkin5e033762004-09-29 13:26:15 +000055NULL_encode_der(asn_TYPE_descriptor_t *td, void *ptr,
Lev Walkinf15320b2004-06-03 03:38:44 +000056 int tag_mode, ber_tlv_tag_t tag,
57 asn_app_consume_bytes_f *cb, void *app_key) {
Lev Walkina9cc46e2004-09-22 16:06:28 +000058 asn_enc_rval_t erval;
Lev Walkinf15320b2004-06-03 03:38:44 +000059
Lev Walkin8e8078a2004-09-26 13:10:40 +000060 erval.encoded = der_write_tags(td, 0, tag_mode, 0, tag, cb, app_key);
Lev Walkinf15320b2004-06-03 03:38:44 +000061 if(erval.encoded == -1) {
Lev Walkina9cc46e2004-09-22 16:06:28 +000062 erval.failed_type = td;
Lev Walkinf15320b2004-06-03 03:38:44 +000063 erval.structure_ptr = ptr;
64 }
65
Lev Walkin7c1dc052016-03-14 03:08:15 -070066 ASN__ENCODED_OK(erval);
Lev Walkinf15320b2004-06-03 03:38:44 +000067}
68
Lev Walkina9cc46e2004-09-22 16:06:28 +000069asn_enc_rval_t
Lev Walkin5e033762004-09-29 13:26:15 +000070NULL_encode_xer(asn_TYPE_descriptor_t *td, void *sptr,
Lev Walkina9cc46e2004-09-22 16:06:28 +000071 int ilevel, enum xer_encoder_flags_e flags,
72 asn_app_consume_bytes_f *cb, void *app_key) {
73 asn_enc_rval_t er;
74
75 (void)td;
76 (void)sptr;
77 (void)ilevel;
78 (void)flags;
79 (void)cb;
80 (void)app_key;
81
82 /* XMLNullValue is empty */
83 er.encoded = 0;
Lev Walkin7c1dc052016-03-14 03:08:15 -070084 ASN__ENCODED_OK(er);
Lev Walkina9cc46e2004-09-22 16:06:28 +000085}
86
Lev Walkinb8ec15d2004-10-22 08:20:32 +000087
Lev Walkin0fab1a62005-03-09 22:19:25 +000088static enum xer_pbd_rval
89NULL__xer_body_decode(asn_TYPE_descriptor_t *td, void *sptr, const void *chunk_buf, size_t chunk_size) {
Lev Walkine0b56e02005-02-25 12:10:27 +000090 (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 Walkinb8ec15d2004-10-22 08:20:32 +0000105 asn_TYPE_descriptor_t *td, void **sptr, const char *opt_mname,
Lev Walkin8c3b8542005-03-10 18:52:02 +0000106 const void *buf_ptr, size_t size) {
Lev Walkinb8ec15d2004-10-22 08:20:32 +0000107
108 return xer_decode_primitive(opt_codec_ctx, td,
109 sptr, sizeof(NULL_t), opt_mname, buf_ptr, size,
110 NULL__xer_body_decode);
111}
112
Lev Walkinf15320b2004-06-03 03:38:44 +0000113int
Lev Walkincd2f48e2017-08-10 02:14:59 -0700114NULL_compare(const asn_TYPE_descriptor_t *td, const void *a, const void *b) {
115 (void)td;
116 (void)a;
117 (void)b;
118 return 0;
119}
120
121int
Lev Walkin5e033762004-09-29 13:26:15 +0000122NULL_print(asn_TYPE_descriptor_t *td, const void *sptr, int ilevel,
Lev Walkinf15320b2004-06-03 03:38:44 +0000123 asn_app_consume_bytes_f *cb, void *app_key) {
Lev Walkind9bd7752004-06-05 08:17:50 +0000124
125 (void)td; /* Unused argument */
126 (void)ilevel; /* Unused argument */
127
Lev Walkinf15320b2004-06-03 03:38:44 +0000128 if(sptr) {
Lev Walkin8e8078a2004-09-26 13:10:40 +0000129 return (cb("<present>", 9, app_key) < 0) ? -1 : 0;
Lev Walkinf15320b2004-06-03 03:38:44 +0000130 } else {
Lev Walkin8e8078a2004-09-26 13:10:40 +0000131 return (cb("<absent>", 8, app_key) < 0) ? -1 : 0;
Lev Walkinf15320b2004-06-03 03:38:44 +0000132 }
133}
Lev Walkin59b176e2005-11-26 11:25:14 +0000134
Lev Walkinaa7c5a62017-08-30 17:41:32 -0700135#ifndef ASN_DISABLE_OER_SUPPORT
136
137asn_dec_rval_t
Lev Walkinafbf2a92017-09-12 23:30:27 -0700138NULL_decode_oer(const asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td,
Lev Walkinaa7c5a62017-08-30 17:41:32 -0700139 const asn_oer_constraints_t *constraints, void **struct_ptr,
140 const void *ptr, size_t size) {
141 asn_dec_rval_t rv = {RC_OK, 0};
142 (void)opt_codec_ctx;
143 (void)td;
144 (void)constraints;
145 (void)struct_ptr;
146 (void)ptr;
147 (void)size;
148 return rv;
149}
150
151asn_enc_rval_t
152NULL_encode_oer(asn_TYPE_descriptor_t *td,
153 const asn_oer_constraints_t *constraints, void *sptr,
154 asn_app_consume_bytes_f *cb, void *app_key) {
Lev Walkin0b597632017-09-12 22:37:25 -0700155 asn_enc_rval_t er;
Lev Walkinaa7c5a62017-08-30 17:41:32 -0700156
Lev Walkin91da82f2017-09-12 23:05:16 -0700157 (void)td;
158 (void)sptr;
Lev Walkinaa7c5a62017-08-30 17:41:32 -0700159 (void)constraints;
160 (void)cb;
161 (void)app_key;
162
Lev Walkin0b597632017-09-12 22:37:25 -0700163 er.encoded = 0; /* Encoding in 0 bytes. */
164
165 ASN__ENCODED_OK(er);
Lev Walkinaa7c5a62017-08-30 17:41:32 -0700166}
167
168#endif /* ASN_DISABLE_OER_SUPPORT */
169
170#ifndef ASN_DISABLE_PER_SUPPORT
171
Lev Walkin59b176e2005-11-26 11:25:14 +0000172asn_dec_rval_t
Lev Walkinafbf2a92017-09-12 23:30:27 -0700173NULL_decode_uper(const asn_codec_ctx_t *opt_codec_ctx, 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 Walkin494fb702017-08-07 20:07:00 -0700202NULL_encode_uper(asn_TYPE_descriptor_t *td,
203 const asn_per_constraints_t *constraints, void *sptr,
204 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