blob: f514ca29de91c9d5af9441d8175282287f7ad54b [file] [log] [blame]
Harald Welte92c45f32010-06-12 18:59:38 +02001/*-
2 * Copyright (c) 2003, 2005 Lev Walkin <vlm@lionet.info>. All rights reserved.
3 * Redistribution and modifications are permitted subject to BSD license.
4 */
5#include <asn_internal.h>
6#include <asn_codecs_prim.h>
7#include <NULL.h>
8#include <BOOLEAN.h> /* Implemented in terms of BOOLEAN type */
9
10/*
11 * NULL basic type description.
12 */
Harald Welte41b85d52015-08-31 08:56:53 +020013static const ber_tlv_tag_t asn_DEF_NULL_tags[] = {
Harald Welte92c45f32010-06-12 18:59:38 +020014 (ASN_TAG_CLASS_UNIVERSAL | (5 << 2))
15};
16asn_TYPE_descriptor_t asn_DEF_NULL = {
17 "NULL",
18 "NULL",
19 BOOLEAN_free,
20 NULL_print,
21 asn_generic_no_constraint,
22 BOOLEAN_decode_ber, /* Implemented in terms of BOOLEAN */
23 NULL_encode_der, /* Special handling of DER encoding */
24 NULL_decode_xer,
25 NULL_encode_xer,
26 NULL_decode_uper, /* Unaligned PER decoder */
27 NULL_encode_uper, /* Unaligned PER encoder */
Harald Welte41b85d52015-08-31 08:56:53 +020028 NULL_decode_aper, /* Aligned PER decoder */
29 NULL_encode_aper, /* Aligned PER encoder */
Harald Welte92c45f32010-06-12 18:59:38 +020030 0, /* Use generic outmost tag fetcher */
31 asn_DEF_NULL_tags,
32 sizeof(asn_DEF_NULL_tags) / sizeof(asn_DEF_NULL_tags[0]),
33 asn_DEF_NULL_tags, /* Same as above */
34 sizeof(asn_DEF_NULL_tags) / sizeof(asn_DEF_NULL_tags[0]),
35 0, /* No PER visible constraints */
36 0, 0, /* No members */
37 0 /* No specifics */
38};
39
40asn_enc_rval_t
41NULL_encode_der(asn_TYPE_descriptor_t *td, void *ptr,
42 int tag_mode, ber_tlv_tag_t tag,
43 asn_app_consume_bytes_f *cb, void *app_key) {
44 asn_enc_rval_t erval;
45
46 erval.encoded = der_write_tags(td, 0, tag_mode, 0, tag, cb, app_key);
47 if(erval.encoded == -1) {
48 erval.failed_type = td;
49 erval.structure_ptr = ptr;
50 }
51
52 _ASN_ENCODED_OK(erval);
53}
54
55asn_enc_rval_t
56NULL_encode_xer(asn_TYPE_descriptor_t *td, void *sptr,
57 int ilevel, enum xer_encoder_flags_e flags,
58 asn_app_consume_bytes_f *cb, void *app_key) {
59 asn_enc_rval_t er;
60
61 (void)td;
62 (void)sptr;
63 (void)ilevel;
64 (void)flags;
65 (void)cb;
66 (void)app_key;
67
68 /* XMLNullValue is empty */
69 er.encoded = 0;
70 _ASN_ENCODED_OK(er);
71}
72
73
74static enum xer_pbd_rval
75NULL__xer_body_decode(asn_TYPE_descriptor_t *td, void *sptr, const void *chunk_buf, size_t chunk_size) {
76 (void)td;
77 (void)sptr;
Harald Welte41b85d52015-08-31 08:56:53 +020078 (void)chunk_buf; /* Going to be empty according to the rules below. */
Harald Welte92c45f32010-06-12 18:59:38 +020079
Harald Welte41b85d52015-08-31 08:56:53 +020080 /*
81 * There must be no content in self-terminating <NULL/> tag.
82 */
83 if(chunk_size)
Harald Welte92c45f32010-06-12 18:59:38 +020084 return XPBD_BROKEN_ENCODING;
Harald Welte41b85d52015-08-31 08:56:53 +020085 else
86 return XPBD_BODY_CONSUMED;
Harald Welte92c45f32010-06-12 18:59:38 +020087}
88
89asn_dec_rval_t
90NULL_decode_xer(asn_codec_ctx_t *opt_codec_ctx,
91 asn_TYPE_descriptor_t *td, void **sptr, const char *opt_mname,
92 const void *buf_ptr, size_t size) {
93
94 return xer_decode_primitive(opt_codec_ctx, td,
95 sptr, sizeof(NULL_t), opt_mname, buf_ptr, size,
96 NULL__xer_body_decode);
97}
98
99int
100NULL_print(asn_TYPE_descriptor_t *td, const void *sptr, int ilevel,
101 asn_app_consume_bytes_f *cb, void *app_key) {
102
103 (void)td; /* Unused argument */
104 (void)ilevel; /* Unused argument */
105
106 if(sptr) {
107 return (cb("<present>", 9, app_key) < 0) ? -1 : 0;
108 } else {
109 return (cb("<absent>", 8, app_key) < 0) ? -1 : 0;
110 }
111}
112
113asn_dec_rval_t
114NULL_decode_uper(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td,
115 asn_per_constraints_t *constraints, void **sptr, asn_per_data_t *pd) {
116 asn_dec_rval_t rv;
117
118 (void)opt_codec_ctx;
119 (void)td;
120 (void)constraints;
121 (void)pd;
122
123 if(!*sptr) {
124 *sptr = MALLOC(sizeof(NULL_t));
125 if(*sptr) {
126 *(NULL_t *)*sptr = 0;
127 } else {
128 _ASN_DECODE_FAILED;
129 }
130 }
131
132 /*
133 * NULL type does not have content octets.
134 */
135
136 rv.code = RC_OK;
137 rv.consumed = 0;
138 return rv;
139}
140
Harald Welte41b85d52015-08-31 08:56:53 +0200141asn_dec_rval_t
142NULL_decode_aper(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td,
143 asn_per_constraints_t *constraints, void **sptr, asn_per_data_t *pd) {
144 asn_dec_rval_t rv;
145
146 (void)opt_codec_ctx;
147 (void)td;
148 (void)constraints;
149 (void)pd;
150
151 if(!*sptr) {
152 *sptr = MALLOC(sizeof(NULL_t));
153 if(*sptr) {
154 *(NULL_t *)*sptr = 0;
155 } else {
156 _ASN_DECODE_FAILED;
157 }
158 }
159
160 /*
161 * NULL type does not have content octets.
162 */
163
164 rv.code = RC_OK;
165 rv.consumed = 0;
166 return rv;
167}
168
Harald Welte92c45f32010-06-12 18:59:38 +0200169asn_enc_rval_t
170NULL_encode_uper(asn_TYPE_descriptor_t *td, asn_per_constraints_t *constraints,
171 void *sptr, asn_per_outp_t *po) {
172 asn_enc_rval_t er;
173
174 (void)td;
175 (void)constraints;
176 (void)sptr;
177 (void)po;
178
179 er.encoded = 0;
180 _ASN_ENCODED_OK(er);
181}
Harald Welte41b85d52015-08-31 08:56:53 +0200182
183asn_enc_rval_t
184NULL_encode_aper(asn_TYPE_descriptor_t *td, asn_per_constraints_t *constraints,
185 void *sptr, asn_per_outp_t *po) {
186 asn_enc_rval_t er;
187
188 (void)td;
189 (void)constraints;
190 (void)sptr;
191 (void)po;
192
193 er.encoded = 0;
194 _ASN_ENCODED_OK(er);
195}