1 /*****************************************************************************
3 # Copyright 2019 AT&T Intellectual Property *
5 # Licensed under the Apache License, Version 2.0 (the "License"); *
6 # you may not use this file except in compliance with the License. *
7 # You may obtain a copy of the License at *
9 # http://www.apache.org/licenses/LICENSE-2.0 *
11 # Unless required by applicable law or agreed to in writing, software *
12 # distributed under the License is distributed on an "AS IS" BASIS, *
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
14 # See the License for the specific language governing permissions and *
15 # limitations under the License. *
17 ******************************************************************************/
20 * Copyright (c) 2003, 2005 Lev Walkin <vlm@lionet.info>. All rights reserved.
21 * Redistribution and modifications are permitted subject to BSD license.
23 #include <asn_internal.h>
24 #include <asn_codecs_prim.h>
26 #include <BOOLEAN.h> /* Implemented in terms of BOOLEAN type */
29 * NULL basic type description.
31 static const ber_tlv_tag_t asn_DEF_NULL_tags[] = {
32 (ASN_TAG_CLASS_UNIVERSAL | (5 << 2))
34 asn_TYPE_operation_t asn_OP_NULL = {
38 BOOLEAN_decode_ber, /* Implemented in terms of BOOLEAN */
39 NULL_encode_der, /* Special handling of DER encoding */
42 #ifdef ASN_DISABLE_OER_SUPPORT
48 #endif /* ASN_DISABLE_OER_SUPPORT */
49 #ifdef ASN_DISABLE_PER_SUPPORT
55 NULL_decode_uper, /* Unaligned PER decoder */
56 NULL_encode_uper, /* Unaligned PER encoder */
57 NULL_decode_aper, /* Aligned PER decoder */
58 NULL_encode_aper, /* Aligned PER encoder */
59 #endif /* ASN_DISABLE_PER_SUPPORT */
61 0 /* Use generic outmost tag fetcher */
63 asn_TYPE_descriptor_t asn_DEF_NULL = {
68 sizeof(asn_DEF_NULL_tags) / sizeof(asn_DEF_NULL_tags[0]),
69 asn_DEF_NULL_tags, /* Same as above */
70 sizeof(asn_DEF_NULL_tags) / sizeof(asn_DEF_NULL_tags[0]),
71 { 0, 0, asn_generic_no_constraint },
72 0, 0, /* No members */
77 NULL_encode_der(const asn_TYPE_descriptor_t *td, const void *ptr, int tag_mode,
78 ber_tlv_tag_t tag, asn_app_consume_bytes_f *cb, void *app_key) {
79 asn_enc_rval_t erval = {0,0,0};
81 erval.encoded = der_write_tags(td, 0, tag_mode, 0, tag, cb, app_key);
82 if(erval.encoded == -1) {
83 erval.failed_type = td;
84 erval.structure_ptr = ptr;
87 ASN__ENCODED_OK(erval);
91 NULL_encode_xer(const asn_TYPE_descriptor_t *td, const void *sptr, int ilevel,
92 enum xer_encoder_flags_e flags, asn_app_consume_bytes_f *cb,
94 asn_enc_rval_t er = {0,0,0};
103 /* XMLNullValue is empty */
109 static enum xer_pbd_rval
110 NULL__xer_body_decode(const asn_TYPE_descriptor_t *td, void *sptr,
111 const void *chunk_buf, size_t chunk_size) {
114 (void)chunk_buf; /* Going to be empty according to the rules below. */
117 * There must be no content in self-terminating <NULL/> tag.
120 return XPBD_BROKEN_ENCODING;
122 return XPBD_BODY_CONSUMED;
126 NULL_decode_xer(const asn_codec_ctx_t *opt_codec_ctx,
127 const asn_TYPE_descriptor_t *td, void **sptr,
128 const char *opt_mname, const void *buf_ptr, size_t size) {
129 return xer_decode_primitive(opt_codec_ctx, td,
130 sptr, sizeof(NULL_t), opt_mname, buf_ptr, size,
131 NULL__xer_body_decode);
135 NULL_compare(const asn_TYPE_descriptor_t *td, const void *a, const void *b) {
143 NULL_print(const asn_TYPE_descriptor_t *td, const void *sptr, int ilevel,
144 asn_app_consume_bytes_f *cb, void *app_key) {
145 (void)td; /* Unused argument */
146 (void)ilevel; /* Unused argument */
149 return (cb("<present>", 9, app_key) < 0) ? -1 : 0;
151 return (cb("<absent>", 8, app_key) < 0) ? -1 : 0;
155 #ifndef ASN_DISABLE_OER_SUPPORT
158 NULL_decode_oer(const asn_codec_ctx_t *opt_codec_ctx,
159 const asn_TYPE_descriptor_t *td,
160 const asn_oer_constraints_t *constraints, void **sptr,
161 const void *ptr, size_t size) {
162 asn_dec_rval_t rv = {RC_OK, 0};
170 *sptr = MALLOC(sizeof(NULL_t));
172 *(NULL_t *)*sptr = 0;
182 NULL_encode_oer(const asn_TYPE_descriptor_t *td,
183 const asn_oer_constraints_t *constraints, const void *sptr,
184 asn_app_consume_bytes_f *cb, void *app_key) {
185 asn_enc_rval_t er = {0,0,0};
193 er.encoded = 0; /* Encoding in 0 bytes. */
198 #endif /* ASN_DISABLE_OER_SUPPORT */
200 #ifndef ASN_DISABLE_PER_SUPPORT
203 NULL_decode_uper(const asn_codec_ctx_t *opt_codec_ctx,
204 const asn_TYPE_descriptor_t *td,
205 const asn_per_constraints_t *constraints, void **sptr,
206 asn_per_data_t *pd) {
215 *sptr = MALLOC(sizeof(NULL_t));
217 *(NULL_t *)*sptr = 0;
224 * NULL type does not have content octets.
233 NULL_encode_uper(const asn_TYPE_descriptor_t *td,
234 const asn_per_constraints_t *constraints, const void *sptr,
235 asn_per_outp_t *po) {
236 asn_enc_rval_t er = {0,0,0};
248 NULL_decode_aper(const asn_codec_ctx_t *opt_codec_ctx,
249 const asn_TYPE_descriptor_t *td,
250 const asn_per_constraints_t *constraints, void **sptr, asn_per_data_t *pd) {
251 asn_dec_rval_t rv = {RC_OK, 0};
259 *sptr = MALLOC(sizeof(NULL_t));
261 *(NULL_t *)*sptr = 0;
268 * NULL type does not have content octets.
278 NULL_encode_aper(const asn_TYPE_descriptor_t *td,
279 const asn_per_constraints_t *constraints,
280 const void *sptr, asn_per_outp_t *po) {
281 asn_enc_rval_t er = {0,0,0};
292 #endif /* ASN_DISABLE_PER_SUPPORT */
294 asn_random_fill_result_t
295 NULL_random_fill(const asn_TYPE_descriptor_t *td, void **sptr,
296 const asn_encoding_constraints_t *constr,
298 asn_random_fill_result_t result_ok = {ARFILL_OK, 1};
299 asn_random_fill_result_t result_failed = {ARFILL_FAILED, 0};
300 asn_random_fill_result_t result_skipped = {ARFILL_SKIPPED, 0};
306 if(max_length == 0) return result_skipped;
309 st = (NULL_t *)(*sptr = CALLOC(1, sizeof(*st)));
311 return result_failed;