2 * Copyright (c) 2003, 2005 Lev Walkin <vlm@lionet.info>. All rights reserved.
3 * Redistribution and modifications are permitted subject to BSD license.
5 #include <asn_internal.h>
6 #include <asn_codecs_prim.h>
10 * NULL basic type description.
12 static const ber_tlv_tag_t asn_DEF_NULL_tags[] = {
13 (ASN_TAG_CLASS_UNIVERSAL | (5 << 2))
15 asn_TYPE_operation_t asn_OP_NULL = {
20 NULL_encode_der, /* Special handling of DER encoding */
23 #ifdef ASN_DISABLE_OER_SUPPORT
29 #endif /* ASN_DISABLE_OER_SUPPORT */
30 #ifdef ASN_DISABLE_PER_SUPPORT
34 NULL_decode_uper, /* Unaligned PER decoder */
35 NULL_encode_uper, /* Unaligned PER encoder */
36 #endif /* ASN_DISABLE_PER_SUPPORT */
38 0 /* Use generic outmost tag fetcher */
40 asn_TYPE_descriptor_t asn_DEF_NULL = {
45 sizeof(asn_DEF_NULL_tags) / sizeof(asn_DEF_NULL_tags[0]),
46 asn_DEF_NULL_tags, /* Same as above */
47 sizeof(asn_DEF_NULL_tags) / sizeof(asn_DEF_NULL_tags[0]),
48 { 0, 0, asn_generic_no_constraint },
49 0, 0, /* No members */
54 NULL_free(const asn_TYPE_descriptor_t *td, void *ptr,
55 enum asn_struct_free_method method) {
58 case ASFM_FREE_EVERYTHING:
61 case ASFM_FREE_UNDERLYING:
63 case ASFM_FREE_UNDERLYING_AND_RESET:
64 memset(ptr, 0, sizeof(NULL_t));
74 NULL_decode_ber(const asn_codec_ctx_t *opt_codec_ctx,
75 const asn_TYPE_descriptor_t *td, void **bool_value,
76 const void *buf_ptr, size_t size, int tag_mode) {
77 NULL_t *st = (NULL_t *)*bool_value;
82 st = (NULL_t *)(*bool_value = CALLOC(1, sizeof(*st)));
90 ASN_DEBUG("Decoding %s as NULL (tm=%d)", td->name, tag_mode);
95 rval = ber_check_tags(opt_codec_ctx, td, 0, buf_ptr, size, tag_mode, 0,
97 if(rval.code != RC_OK) {
101 // X.690-201508, #8.8.2, length shall be zero.
103 ASN_DEBUG("Decoding %s as NULL failed: too much data", td->name);
113 NULL_encode_der(const asn_TYPE_descriptor_t *td, const void *ptr, int tag_mode,
114 ber_tlv_tag_t tag, asn_app_consume_bytes_f *cb, void *app_key) {
115 asn_enc_rval_t erval;
117 erval.encoded = der_write_tags(td, 0, tag_mode, 0, tag, cb, app_key);
118 if(erval.encoded == -1) {
119 erval.failed_type = td;
120 erval.structure_ptr = ptr;
123 ASN__ENCODED_OK(erval);
127 NULL_encode_xer(const asn_TYPE_descriptor_t *td, const void *sptr, int ilevel,
128 enum xer_encoder_flags_e flags, asn_app_consume_bytes_f *cb,
139 /* XMLNullValue is empty */
145 static enum xer_pbd_rval
146 NULL__xer_body_decode(const asn_TYPE_descriptor_t *td, void *sptr,
147 const void *chunk_buf, size_t chunk_size) {
150 (void)chunk_buf; /* Going to be empty according to the rules below. */
153 * There must be no content in self-terminating <NULL/> tag.
156 return XPBD_BROKEN_ENCODING;
158 return XPBD_BODY_CONSUMED;
162 NULL_decode_xer(const asn_codec_ctx_t *opt_codec_ctx,
163 const asn_TYPE_descriptor_t *td, void **sptr,
164 const char *opt_mname, const void *buf_ptr, size_t size) {
165 return xer_decode_primitive(opt_codec_ctx, td,
166 sptr, sizeof(NULL_t), opt_mname, buf_ptr, size,
167 NULL__xer_body_decode);
171 NULL_compare(const asn_TYPE_descriptor_t *td, const void *a, const void *b) {
179 NULL_print(const asn_TYPE_descriptor_t *td, const void *sptr, int ilevel,
180 asn_app_consume_bytes_f *cb, void *app_key) {
181 (void)td; /* Unused argument */
182 (void)ilevel; /* Unused argument */
185 return (cb("<present>", 9, app_key) < 0) ? -1 : 0;
187 return (cb("<absent>", 8, app_key) < 0) ? -1 : 0;
191 #ifndef ASN_DISABLE_OER_SUPPORT
194 NULL_decode_oer(const asn_codec_ctx_t *opt_codec_ctx,
195 const asn_TYPE_descriptor_t *td,
196 const asn_oer_constraints_t *constraints, void **sptr,
197 const void *ptr, size_t size) {
198 asn_dec_rval_t rv = {RC_OK, 0};
206 *sptr = MALLOC(sizeof(NULL_t));
208 *(NULL_t *)*sptr = 0;
218 NULL_encode_oer(const asn_TYPE_descriptor_t *td,
219 const asn_oer_constraints_t *constraints, const void *sptr,
220 asn_app_consume_bytes_f *cb, void *app_key) {
229 er.encoded = 0; /* Encoding in 0 bytes. */
234 #endif /* ASN_DISABLE_OER_SUPPORT */
236 #ifndef ASN_DISABLE_PER_SUPPORT
239 NULL_decode_uper(const asn_codec_ctx_t *opt_codec_ctx,
240 const asn_TYPE_descriptor_t *td,
241 const asn_per_constraints_t *constraints, void **sptr,
242 asn_per_data_t *pd) {
251 *sptr = MALLOC(sizeof(NULL_t));
253 *(NULL_t *)*sptr = 0;
260 * NULL type does not have content octets.
269 NULL_encode_uper(const asn_TYPE_descriptor_t *td,
270 const asn_per_constraints_t *constraints, const void *sptr,
271 asn_per_outp_t *po) {
283 #endif /* ASN_DISABLE_PER_SUPPORT */
285 asn_random_fill_result_t
286 NULL_random_fill(const asn_TYPE_descriptor_t *td, void **sptr,
287 const asn_encoding_constraints_t *constr,
289 asn_random_fill_result_t result_ok = {ARFILL_OK, 1};
290 asn_random_fill_result_t result_failed = {ARFILL_FAILED, 0};
291 asn_random_fill_result_t result_skipped = {ARFILL_SKIPPED, 0};
297 if(max_length == 0) return result_skipped;
300 st = (NULL_t *)(*sptr = CALLOC(1, sizeof(*st)));
302 return result_failed;