aboutsummaryrefslogtreecommitdiffstats
path: root/skeletons/NULL.c
diff options
context:
space:
mode:
authorLev Walkin <vlm@lionet.info>2020-07-06 23:04:31 -0700
committerLev Walkin <vlm@lionet.info>2020-07-06 23:26:33 -0700
commitc7abb8e9bbdd42bb1cce97e0a428bdf0b96bffce (patch)
tree4c598c1f5cf94f584ffc0ff64f6cff4024ae729c /skeletons/NULL.c
parentfdb68ce2782423ce38caf84f28441d1b0776e9ee (diff)
Decouple NULL and BOOLEAN
Diffstat (limited to 'skeletons/NULL.c')
-rw-r--r--skeletons/NULL.c64
1 files changed, 61 insertions, 3 deletions
diff --git a/skeletons/NULL.c b/skeletons/NULL.c
index a43d412b..076898e0 100644
--- a/skeletons/NULL.c
+++ b/skeletons/NULL.c
@@ -5,7 +5,6 @@
#include <asn_internal.h>
#include <asn_codecs_prim.h>
#include <NULL.h>
-#include <BOOLEAN.h> /* Implemented in terms of BOOLEAN type */
/*
* NULL basic type description.
@@ -14,10 +13,10 @@ static const ber_tlv_tag_t asn_DEF_NULL_tags[] = {
(ASN_TAG_CLASS_UNIVERSAL | (5 << 2))
};
asn_TYPE_operation_t asn_OP_NULL = {
- BOOLEAN_free,
+ NULL_free,
NULL_print,
NULL_compare,
- BOOLEAN_decode_ber, /* Implemented in terms of BOOLEAN */
+ NULL_decode_ber,
NULL_encode_der, /* Special handling of DER encoding */
NULL_decode_xer,
NULL_encode_xer,
@@ -51,6 +50,65 @@ asn_TYPE_descriptor_t asn_DEF_NULL = {
0 /* No specifics */
};
+void
+NULL_free(const asn_TYPE_descriptor_t *td, void *ptr,
+ enum asn_struct_free_method method) {
+ if(td && ptr) {
+ switch(method) {
+ case ASFM_FREE_EVERYTHING:
+ FREEMEM(ptr);
+ break;
+ case ASFM_FREE_UNDERLYING:
+ break;
+ case ASFM_FREE_UNDERLYING_AND_RESET:
+ memset(ptr, 0, sizeof(NULL_t));
+ break;
+ }
+ }
+}
+
+/*
+ * Decode NULL type.
+ */
+asn_dec_rval_t
+NULL_decode_ber(const asn_codec_ctx_t *opt_codec_ctx,
+ const asn_TYPE_descriptor_t *td, void **bool_value,
+ const void *buf_ptr, size_t size, int tag_mode) {
+ NULL_t *st = (NULL_t *)*bool_value;
+ asn_dec_rval_t rval;
+ ber_tlv_len_t length;
+
+ if(st == NULL) {
+ st = (NULL_t *)(*bool_value = CALLOC(1, sizeof(*st)));
+ if(st == NULL) {
+ rval.code = RC_FAIL;
+ rval.consumed = 0;
+ return rval;
+ }
+ }
+
+ ASN_DEBUG("Decoding %s as NULL (tm=%d)", td->name, tag_mode);
+
+ /*
+ * Check tags.
+ */
+ rval = ber_check_tags(opt_codec_ctx, td, 0, buf_ptr, size, tag_mode, 0,
+ &length, 0);
+ if(rval.code != RC_OK) {
+ return rval;
+ }
+
+ // X.690-201508, #8.8.2, length shall be zero.
+ if(length != 0) {
+ ASN_DEBUG("Decoding %s as NULL failed: too much data", td->name);
+ rval.code = RC_FAIL;
+ rval.consumed = 0;
+ return rval;
+ }
+
+ return rval;
+}
+
asn_enc_rval_t
NULL_encode_der(const asn_TYPE_descriptor_t *td, const void *ptr, int tag_mode,
ber_tlv_tag_t tag, asn_app_consume_bytes_f *cb, void *app_key) {