-/*-
- * Copyright (c) 2003-2014 Lev Walkin <vlm@lionet.info>.
+/*
+ * Copyright (c) 2003-2019 Lev Walkin <vlm@lionet.info>.
* All rights reserved.
* Redistribution and modifications are permitted subject to BSD license.
*/
*/
enum asn_strtox_result_e
asn_strtoimax_lim(const char *str, const char **end, intmax_t *intp) {
- int sign = 1;
- intmax_t value;
+ int sign = 1;
+ intmax_t value;
-#define ASN1_INTMAX_MAX ((~(uintmax_t)0) >> 1)
- const intmax_t upper_boundary = ASN1_INTMAX_MAX / 10;
- intmax_t last_digit_max = ASN1_INTMAX_MAX % 10;
-#undef ASN1_INTMAX_MAX
+ const intmax_t asn1_intmax_max = ((~(uintmax_t)0) >> 1);
+ const intmax_t upper_boundary = asn1_intmax_max / 10;
+ intmax_t last_digit_max = asn1_intmax_max % 10;
- if(str >= *end) return ASN_STRTOX_ERROR_INVAL;
+ if(str >= *end) return ASN_STRTOX_ERROR_INVAL;
- switch(*str) {
- case '-':
- last_digit_max++;
- sign = -1;
- /* FALL THROUGH */
- case '+':
- str++;
- if(str >= *end) {
- *end = str;
- return ASN_STRTOX_EXPECT_MORE;
- }
- }
+ switch(*str) {
+ case '-':
+ last_digit_max++;
+ sign = -1;
+ /* FALL THROUGH */
+ case '+':
+ str++;
+ if(str >= *end) {
+ *end = str;
+ return ASN_STRTOX_EXPECT_MORE;
+ }
+ }
- for(value = 0; str < (*end); str++) {
- switch(*str) {
- case 0x30: case 0x31: case 0x32: case 0x33: case 0x34:
- case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: {
- int d = *str - '0';
- if(value < upper_boundary) {
- value = value * 10 + d;
- } else if(value == upper_boundary) {
- if(d <= last_digit_max) {
- if(sign > 0) {
- value = value * 10 + d;
- } else {
- sign = 1;
- value = -value * 10 - d;
- }
- } else {
- *end = str;
- return ASN_STRTOX_ERROR_RANGE;
- }
- } else {
- *end = str;
- return ASN_STRTOX_ERROR_RANGE;
- }
- }
- continue;
- default:
- *end = str;
- *intp = sign * value;
- return ASN_STRTOX_EXTRA_DATA;
- }
- }
+ for(value = 0; str < (*end); str++) {
+ if(*str >= 0x30 && *str <= 0x39) {
+ int d = *str - '0';
+ if(value < upper_boundary) {
+ value = value * 10 + d;
+ } else if(value == upper_boundary) {
+ if(d <= last_digit_max) {
+ if(sign > 0) {
+ value = value * 10 + d;
+ } else {
+ sign = 1;
+ value = -value * 10 - d;
+ }
+ str += 1;
+ if(str < *end) {
+ // If digits continue, we're guaranteed out of range.
+ *end = str;
+ if(*str >= 0x30 && *str <= 0x39) {
+ return ASN_STRTOX_ERROR_RANGE;
+ } else {
+ *intp = sign * value;
+ return ASN_STRTOX_EXTRA_DATA;
+ }
+ }
+ break;
+ } else {
+ *end = str;
+ return ASN_STRTOX_ERROR_RANGE;
+ }
+ } else {
+ *end = str;
+ return ASN_STRTOX_ERROR_RANGE;
+ }
+ } else {
+ *end = str;
+ *intp = sign * value;
+ return ASN_STRTOX_EXTRA_DATA;
+ }
+ }
- *end = str;
- *intp = sign * value;
- return ASN_STRTOX_OK;
+ *end = str;
+ *intp = sign * value;
+ return ASN_STRTOX_OK;
}
/*
*/
enum asn_strtox_result_e
asn_strtoumax_lim(const char *str, const char **end, uintmax_t *uintp) {
- uintmax_t value;
+ uintmax_t value;
-#define ASN1_UINTMAX_MAX ((~(uintmax_t)0))
- const uintmax_t upper_boundary = ASN1_UINTMAX_MAX / 10;
- uintmax_t last_digit_max = ASN1_UINTMAX_MAX % 10;
-#undef ASN1_UINTMAX_MAX
+ const uintmax_t asn1_uintmax_max = ((~(uintmax_t)0));
+ const uintmax_t upper_boundary = asn1_uintmax_max / 10;
+ uintmax_t last_digit_max = asn1_uintmax_max % 10;
if(str >= *end) return ASN_STRTOX_ERROR_INVAL;
- switch(*str) {
- case '-':
+ switch(*str) {
+ case '-':
return ASN_STRTOX_ERROR_INVAL;
- case '+':
- str++;
- if(str >= *end) {
- *end = str;
- return ASN_STRTOX_EXPECT_MORE;
- }
- }
+ case '+':
+ str++;
+ if(str >= *end) {
+ *end = str;
+ return ASN_STRTOX_EXPECT_MORE;
+ }
+ }
- for(value = 0; str < (*end); str++) {
- switch(*str) {
- case 0x30: case 0x31: case 0x32: case 0x33: case 0x34:
- case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: {
- unsigned int d = *str - '0';
- if(value < upper_boundary) {
- value = value * 10 + d;
- } else if(value == upper_boundary) {
- if(d <= last_digit_max) {
+ for(value = 0; str < (*end); str++) {
+ if(*str >= 0x30 && *str <= 0x39) {
+ unsigned int d = *str - '0';
+ if(value < upper_boundary) {
+ value = value * 10 + d;
+ } else if(value == upper_boundary) {
+ if(d <= last_digit_max) {
value = value * 10 + d;
+ str += 1;
+ if(str < *end) {
+ // If digits continue, we're guaranteed out of range.
+ *end = str;
+ if(*str >= 0x30 && *str <= 0x39) {
+ return ASN_STRTOX_ERROR_RANGE;
+ } else {
+ *uintp = value;
+ return ASN_STRTOX_EXTRA_DATA;
+ }
+ }
+ break;
} else {
- *end = str;
- return ASN_STRTOX_ERROR_RANGE;
- }
- } else {
- *end = str;
- return ASN_STRTOX_ERROR_RANGE;
- }
- }
- continue;
- default:
- *end = str;
- *uintp = value;
- return ASN_STRTOX_EXTRA_DATA;
- }
- }
+ *end = str;
+ return ASN_STRTOX_ERROR_RANGE;
+ }
+ } else {
+ *end = str;
+ return ASN_STRTOX_ERROR_RANGE;
+ }
+ } else {
+ *end = str;
+ *uintp = value;
+ return ASN_STRTOX_EXTRA_DATA;
+ }
+ }
- *end = str;
- *uintp = value;
- return ASN_STRTOX_OK;
+ *end = str;
+ *uintp = value;
+ return ASN_STRTOX_OK;
}
enum asn_strtox_result_e
-Copyright (c) 2003-2013 Lev Walkin <vlm@lionet.info>
+Copyright (c) 2003-2017 Lev Walkin <vlm@lionet.info> and contributors.
All rights reserved.
Redistribution and use in source and binary forms, with or without
#include "asn1/asn1c/asn_internal.h"
#include "asn1/asn1c/asn_codecs_prim.h"
#include "asn1/asn1c/NULL.h"
-#include "asn1/asn1c/BOOLEAN.h" /* Implemented in terms of BOOLEAN type */
/*
* NULL basic type description.
(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,
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) {
#define ASN_TYPE_NULL_H
#include "asn1/asn1c/asn_application.h"
-#include "asn1/asn1c/BOOLEAN.h"
#ifdef __cplusplus
extern "C" {
#endif
/*
- * The value of the NULL type is meaningless: see BOOLEAN if you want to
- * carry true/false semantics.
+ * The value of the NULL type is meaningless.
+ * Use the BOOLEAN type if you need to carry true/false semantics.
*/
typedef int NULL_t;
extern asn_TYPE_descriptor_t asn_DEF_NULL;
extern asn_TYPE_operation_t asn_OP_NULL;
+asn_struct_free_f NULL_free;
asn_struct_print_f NULL_print;
asn_struct_compare_f NULL_compare;
+ber_type_decoder_f NULL_decode_ber;
der_type_encoder_f NULL_encode_der;
xer_type_decoder_f NULL_decode_xer;
xer_type_encoder_f NULL_encode_xer;
per_type_encoder_f NULL_encode_uper;
asn_random_fill_f NULL_random_fill;
-#define NULL_free BOOLEAN_free
-#define NULL_decode_ber BOOLEAN_decode_ber
#define NULL_constraint asn_generic_no_constraint
#ifdef __cplusplus
if((size >= 1)) {
/* Perform validation of the inner elements */
- return td->encoding_constraints.general_constraints(td, sptr, ctfailcb, app_key);
+ return SEQUENCE_OF_constraint(td, sptr, ctfailcb, app_key);
} else {
ASN__CTFAIL(app_key, td, sptr,
"%s: constraint failed (%s:%d)",
if((size >= 1)) {
/* Perform validation of the inner elements */
- return td->encoding_constraints.general_constraints(td, sptr, ctfailcb, app_key);
+ return SEQUENCE_OF_constraint(td, sptr, ctfailcb, app_key);
} else {
ASN__CTFAIL(app_key, td, sptr,
"%s: constraint failed (%s:%d)",
*/
#ifndef ASN_INTERNAL_H
#define ASN_INTERNAL_H
+#ifndef __EXTENSIONS__
#define __EXTENSIONS__ /* for Sun */
-
+#endif
#include "asn_application.h" /* Application-visible API */
#ifndef __NO_ASSERT_H__ /* Include assert.h only for internal use. */