From: Alberto Leiva Popper Date: Sun, 21 Apr 2024 19:11:45 +0000 (-0600) Subject: ASN.1: Remove the OER and PER encoders and decoders X-Git-Tag: 1.6.2~41 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=2ecb49fc96e7cde340625e177ce2df529eb10398;p=thirdparty%2FFORT-validator.git ASN.1: Remove the OER and PER encoders and decoders Unused code. Been wanting to do this for years. --- diff --git a/src/asn1/asn1c/ANY.c b/src/asn1/asn1c/ANY.c index ba1bc3f5..6def4566 100644 --- a/src/asn1/asn1c/ANY.c +++ b/src/asn1/asn1c/ANY.c @@ -20,19 +20,6 @@ asn_TYPE_operation_t asn_OP_ANY = { OCTET_STRING_encode_der, OCTET_STRING_decode_xer_hex, ANY_encode_xer, -#ifdef ASN_DISABLE_OER_SUPPORT - 0, - 0, -#else - 0, - 0, -#endif /* ASN_DISABLE_OER_SUPPORT */ -#ifdef ASN_DISABLE_PER_SUPPORT - 0, 0, -#else - ANY_decode_uper, - ANY_encode_uper, -#endif /* ASN_DISABLE_PER_SUPPORT */ 0, /* Random fill is not defined for ANY type */ 0 /* Use generic outmost tag fetcher */ }; @@ -179,99 +166,3 @@ static int ANY__consume_bytes(const void *buffer, size_t size, void *key) { return 0; } - -#ifndef ASN_DISABLE_PER_SUPPORT - -asn_dec_rval_t -ANY_decode_uper(const asn_codec_ctx_t *opt_codec_ctx, - const asn_TYPE_descriptor_t *td, - const asn_per_constraints_t *constraints, void **sptr, - asn_per_data_t *pd) { - const asn_OCTET_STRING_specifics_t *specs = - td->specifics ? (const asn_OCTET_STRING_specifics_t *)td->specifics - : &asn_SPC_ANY_specs; - size_t consumed_myself = 0; - int repeat; - ANY_t *st = (ANY_t *)*sptr; - - (void)opt_codec_ctx; - (void)constraints; - - /* - * Allocate the structure. - */ - if(!st) { - st = (ANY_t *)(*sptr = CALLOC(1, specs->struct_size)); - if(!st) RETURN(RC_FAIL); - } - - ASN_DEBUG("PER Decoding ANY type"); - - - st->size = 0; - do { - ssize_t raw_len; - ssize_t len_bytes; - ssize_t len_bits; - void *p; - int ret; - - /* Get the PER length */ - raw_len = uper_get_length(pd, -1, 0, &repeat); - if(raw_len < 0) RETURN(RC_WMORE); - if(raw_len == 0 && st->buf) break; - - ASN_DEBUG("Got PER length len %" ASN_PRI_SIZE ", %s (%s)", raw_len, - repeat ? "repeat" : "once", td->name); - len_bytes = raw_len; - len_bits = len_bytes * 8; - - p = REALLOC(st->buf, st->size + len_bytes + 1); - if(!p) RETURN(RC_FAIL); - st->buf = (uint8_t *)p; - - ret = per_get_many_bits(pd, &st->buf[st->size], 0, len_bits); - if(ret < 0) RETURN(RC_WMORE); - consumed_myself += len_bits; - st->size += len_bytes; - } while(repeat); - st->buf[st->size] = 0; /* nul-terminate */ - - RETURN(RC_OK); -} - -asn_enc_rval_t -ANY_encode_uper(const asn_TYPE_descriptor_t *td, - const asn_per_constraints_t *constraints, const void *sptr, - asn_per_outp_t *po) { - const ANY_t *st = (const ANY_t *)sptr; - asn_enc_rval_t er = {0, 0, 0}; - const uint8_t *buf; - size_t size; - int ret; - - (void)constraints; - - if(!st || (!st->buf && st->size)) ASN__ENCODE_FAILED; - - buf = st->buf; - size = st->size; - do { - int need_eom = 0; - ssize_t may_save = uper_put_length(po, size, &need_eom); - if(may_save < 0) ASN__ENCODE_FAILED; - - ret = per_put_many_bits(po, buf, may_save * 8); - if(ret) ASN__ENCODE_FAILED; - - buf += may_save; - size -= may_save; - assert(!(may_save & 0x07) || !size); - if(need_eom && uper_put_length(po, 0, 0)) - ASN__ENCODE_FAILED; /* End of Message length */ - } while(size); - - ASN__ENCODED_OK(er); -} - -#endif /* ASN_DISABLE_PER_SUPPORT */ diff --git a/src/asn1/asn1c/ANY.h b/src/asn1/asn1c/ANY.h index 62c71030..5136e899 100644 --- a/src/asn1/asn1c/ANY.h +++ b/src/asn1/asn1c/ANY.h @@ -27,8 +27,6 @@ asn_struct_print_f ANY_print; ber_type_decoder_f ANY_decode_ber; der_type_encoder_f ANY_encode_der; xer_type_encoder_f ANY_encode_xer; -per_type_decoder_f ANY_decode_uper; -per_type_encoder_f ANY_encode_uper; #define ANY_free OCTET_STRING_free #define ANY_print OCTET_STRING_print diff --git a/src/asn1/asn1c/ASId.h b/src/asn1/asn1c/ASId.h index f8735d9d..2378d1ff 100644 --- a/src/asn1/asn1c/ASId.h +++ b/src/asn1/asn1c/ASId.h @@ -30,8 +30,6 @@ ber_type_decoder_f ASId_decode_ber; der_type_encoder_f ASId_encode_der; xer_type_decoder_f ASId_decode_xer; xer_type_encoder_f ASId_encode_xer; -oer_type_decoder_f ASId_decode_oer; -oer_type_encoder_f ASId_encode_oer; #ifdef __cplusplus } diff --git a/src/asn1/asn1c/ASIdOrRange.c b/src/asn1/asn1c/ASIdOrRange.c index 9b6076b0..53f96411 100644 --- a/src/asn1/asn1c/ASIdOrRange.c +++ b/src/asn1/asn1c/ASIdOrRange.c @@ -7,9 +7,6 @@ #include "asn1/asn1c/ASIdOrRange.h" -static asn_oer_constraints_t asn_OER_type_ASIdOrRange_constr_1 CC_NOTUSED = { - { 0, 0 }, - -1}; asn_TYPE_member_t asn_MBR_ASIdOrRange_1[] = { { ATF_NOFLAGS, 0, offsetof(struct ASIdOrRange, choice.id), (ASN_TAG_CLASS_UNIVERSAL | (2 << 2)), @@ -41,7 +38,6 @@ asn_CHOICE_specifics_t asn_SPC_ASIdOrRange_specs_1 = { sizeof(((struct ASIdOrRange *)0)->present), asn_MAP_ASIdOrRange_tag2el_1, 2, /* Count of tags in the map */ - 0, 0, -1 /* Extensions start */ }; asn_TYPE_descriptor_t asn_DEF_ASIdOrRange = { @@ -52,7 +48,7 @@ asn_TYPE_descriptor_t asn_DEF_ASIdOrRange = { 0, /* No effective tags (count) */ 0, /* No tags (pointer) */ 0, /* No tags (count) */ - { &asn_OER_type_ASIdOrRange_constr_1, 0, CHOICE_constraint }, + { NULL, 0, CHOICE_constraint }, asn_MBR_ASIdOrRange_1, 2, /* Elements count */ &asn_SPC_ASIdOrRange_specs_1 /* Additional specs */ diff --git a/src/asn1/asn1c/ASIdentifierChoice.c b/src/asn1/asn1c/ASIdentifierChoice.c index 0603aad9..1d4eae4f 100644 --- a/src/asn1/asn1c/ASIdentifierChoice.c +++ b/src/asn1/asn1c/ASIdentifierChoice.c @@ -7,9 +7,6 @@ #include "asn1/asn1c/ASIdentifierChoice.h" -static asn_oer_constraints_t asn_OER_type_ASIdentifierChoice_constr_1 CC_NOTUSED = { - { 0, 0 }, - -1}; static asn_TYPE_member_t asn_MBR_asIdsOrRanges_3[] = { { ATF_POINTER, 0, 0, -1 /* Ambiguous tag (CHOICE?) */, @@ -77,7 +74,6 @@ asn_CHOICE_specifics_t asn_SPC_ASIdentifierChoice_specs_1 = { sizeof(((struct ASIdentifierChoice *)0)->present), asn_MAP_ASIdentifierChoice_tag2el_1, 2, /* Count of tags in the map */ - 0, 0, -1 /* Extensions start */ }; asn_TYPE_descriptor_t asn_DEF_ASIdentifierChoice = { @@ -88,7 +84,7 @@ asn_TYPE_descriptor_t asn_DEF_ASIdentifierChoice = { 0, /* No effective tags (count) */ 0, /* No tags (pointer) */ 0, /* No tags (count) */ - { &asn_OER_type_ASIdentifierChoice_constr_1, 0, CHOICE_constraint }, + { NULL, 0, CHOICE_constraint }, asn_MBR_ASIdentifierChoice_1, 2, /* Elements count */ &asn_SPC_ASIdentifierChoice_specs_1 /* Additional specs */ diff --git a/src/asn1/asn1c/ASIdentifiers.c b/src/asn1/asn1c/ASIdentifiers.c index 06799fd4..b059cd58 100644 --- a/src/asn1/asn1c/ASIdentifiers.c +++ b/src/asn1/asn1c/ASIdentifiers.c @@ -27,7 +27,6 @@ static asn_TYPE_member_t asn_MBR_ASIdentifiers_1[] = { "rdi" }, }; -static const int asn_MAP_ASIdentifiers_oms_1[] = { 0, 1 }; static const ber_tlv_tag_t asn_DEF_ASIdentifiers_tags_1[] = { (ASN_TAG_CLASS_UNIVERSAL | (16 << 2)) }; @@ -40,8 +39,6 @@ static asn_SEQUENCE_specifics_t asn_SPC_ASIdentifiers_specs_1 = { offsetof(struct ASIdentifiers, _asn_ctx), asn_MAP_ASIdentifiers_tag2el_1, 2, /* Count of tags in the map */ - asn_MAP_ASIdentifiers_oms_1, /* Optional members */ - 2, 0, /* Root/Additions */ -1, /* First extension addition */ }; asn_TYPE_descriptor_t asn_DEF_ASIdentifiers = { diff --git a/src/asn1/asn1c/ASRange.c b/src/asn1/asn1c/ASRange.c index 3a14c2a4..8731a145 100644 --- a/src/asn1/asn1c/ASRange.c +++ b/src/asn1/asn1c/ASRange.c @@ -39,7 +39,6 @@ asn_SEQUENCE_specifics_t asn_SPC_ASRange_specs_1 = { offsetof(struct ASRange, _asn_ctx), asn_MAP_ASRange_tag2el_1, 2, /* Count of tags in the map */ - 0, 0, 0, /* Optional elements (not needed) */ -1, /* First extension addition */ }; asn_TYPE_descriptor_t asn_DEF_ASRange = { diff --git a/src/asn1/asn1c/AlgorithmIdentifier.c b/src/asn1/asn1c/AlgorithmIdentifier.c index e3f1fd41..36c3c7a4 100644 --- a/src/asn1/asn1c/AlgorithmIdentifier.c +++ b/src/asn1/asn1c/AlgorithmIdentifier.c @@ -27,7 +27,6 @@ asn_TYPE_member_t asn_MBR_AlgorithmIdentifier_1[] = { "parameters" }, }; -static const int asn_MAP_AlgorithmIdentifier_oms_1[] = { 1 }; static const ber_tlv_tag_t asn_DEF_AlgorithmIdentifier_tags_1[] = { (ASN_TAG_CLASS_UNIVERSAL | (16 << 2)) }; @@ -39,8 +38,6 @@ asn_SEQUENCE_specifics_t asn_SPC_AlgorithmIdentifier_specs_1 = { offsetof(struct AlgorithmIdentifier, _asn_ctx), asn_MAP_AlgorithmIdentifier_tag2el_1, 1, /* Count of tags in the map */ - asn_MAP_AlgorithmIdentifier_oms_1, /* Optional members */ - 1, 0, /* Root/Additions */ -1, /* First extension addition */ }; asn_TYPE_descriptor_t asn_DEF_AlgorithmIdentifier = { diff --git a/src/asn1/asn1c/AttributeType.h b/src/asn1/asn1c/AttributeType.h index 2d8f04c3..e81adcc7 100644 --- a/src/asn1/asn1c/AttributeType.h +++ b/src/asn1/asn1c/AttributeType.h @@ -30,8 +30,6 @@ ber_type_decoder_f AttributeType_decode_ber; der_type_encoder_f AttributeType_encode_der; xer_type_decoder_f AttributeType_decode_xer; xer_type_encoder_f AttributeType_encode_xer; -oer_type_decoder_f AttributeType_decode_oer; -oer_type_encoder_f AttributeType_encode_oer; #ifdef __cplusplus } diff --git a/src/asn1/asn1c/AttributeTypeAndValue.c b/src/asn1/asn1c/AttributeTypeAndValue.c index 8000b3ba..7e56bcf0 100644 --- a/src/asn1/asn1c/AttributeTypeAndValue.c +++ b/src/asn1/asn1c/AttributeTypeAndValue.c @@ -38,7 +38,6 @@ asn_SEQUENCE_specifics_t asn_SPC_AttributeTypeAndValue_specs_1 = { offsetof(struct AttributeTypeAndValue, _asn_ctx), asn_MAP_AttributeTypeAndValue_tag2el_1, 1, /* Count of tags in the map */ - 0, 0, 0, /* Optional elements (not needed) */ -1, /* First extension addition */ }; asn_TYPE_descriptor_t asn_DEF_AttributeTypeAndValue = { diff --git a/src/asn1/asn1c/AttributeValue.h b/src/asn1/asn1c/AttributeValue.h index 6a5a4bf3..060faa18 100644 --- a/src/asn1/asn1c/AttributeValue.h +++ b/src/asn1/asn1c/AttributeValue.h @@ -30,8 +30,6 @@ ber_type_decoder_f AttributeValue_decode_ber; der_type_encoder_f AttributeValue_encode_der; xer_type_decoder_f AttributeValue_decode_xer; xer_type_encoder_f AttributeValue_encode_xer; -oer_type_decoder_f AttributeValue_decode_oer; -oer_type_encoder_f AttributeValue_encode_oer; #ifdef __cplusplus } diff --git a/src/asn1/asn1c/BIT_STRING.c b/src/asn1/asn1c/BIT_STRING.c index 4e0637cd..99bded5e 100644 --- a/src/asn1/asn1c/BIT_STRING.c +++ b/src/asn1/asn1c/BIT_STRING.c @@ -28,20 +28,6 @@ asn_TYPE_operation_t asn_OP_BIT_STRING = { OCTET_STRING_encode_der, /* Implemented in terms of OCTET STRING */ OCTET_STRING_decode_xer_binary, BIT_STRING_encode_xer, -#ifdef ASN_DISABLE_OER_SUPPORT - 0, - 0, -#else - BIT_STRING_decode_oer, - BIT_STRING_encode_oer, -#endif /* ASN_DISABLE_OER_SUPPORT */ -#ifdef ASN_DISABLE_PER_SUPPORT - 0, - 0, -#else - BIT_STRING_decode_uper, /* Unaligned PER decoder */ - BIT_STRING_encode_uper, /* Unaligned PER encoder */ -#endif /* ASN_DISABLE_PER_SUPPORT */ BIT_STRING_random_fill, 0 /* Use generic outmost tag fetcher */ }; @@ -303,247 +289,6 @@ BIT_STRING_compare(const asn_TYPE_descriptor_t *td, const void *aptr, } } -#ifndef ASN_DISABLE_PER_SUPPORT - -#undef RETURN -#define RETURN(_code) \ - do { \ - asn_dec_rval_t tmprval; \ - tmprval.code = _code; \ - tmprval.consumed = consumed_myself; \ - return tmprval; \ - } while(0) - -static asn_per_constraint_t asn_DEF_BIT_STRING_constraint_size = { - APC_SEMI_CONSTRAINED, -1, -1, 0, 0}; - -asn_dec_rval_t -BIT_STRING_decode_uper(const asn_codec_ctx_t *opt_codec_ctx, - const asn_TYPE_descriptor_t *td, - const asn_per_constraints_t *constraints, void **sptr, - asn_per_data_t *pd) { - const asn_OCTET_STRING_specifics_t *specs = td->specifics - ? (const asn_OCTET_STRING_specifics_t *)td->specifics - : &asn_SPC_BIT_STRING_specs; - const asn_per_constraints_t *pc = - constraints ? constraints : td->encoding_constraints.per_constraints; - const asn_per_constraint_t *csiz; - asn_dec_rval_t rval = { RC_OK, 0 }; - BIT_STRING_t *st = (BIT_STRING_t *)*sptr; - ssize_t consumed_myself = 0; - int repeat; - - (void)opt_codec_ctx; - - if(pc) { - csiz = &pc->size; - } else { - csiz = &asn_DEF_BIT_STRING_constraint_size; - } - - if(specs->subvariant != ASN_OSUBV_BIT) { - ASN_DEBUG("Subvariant %d is not BIT OSUBV_BIT", specs->subvariant); - RETURN(RC_FAIL); - } - - /* - * Allocate the string. - */ - if(!st) { - st = (BIT_STRING_t *)(*sptr = CALLOC(1, specs->struct_size)); - if(!st) RETURN(RC_FAIL); - } - - ASN_DEBUG("PER Decoding %s size %ld .. %ld bits %d", - csiz->flags & APC_EXTENSIBLE ? "extensible" : "non-extensible", - csiz->lower_bound, csiz->upper_bound, csiz->effective_bits); - - if(csiz->flags & APC_EXTENSIBLE) { - int inext = per_get_few_bits(pd, 1); - if(inext < 0) RETURN(RC_WMORE); - if(inext) { - csiz = &asn_DEF_BIT_STRING_constraint_size; - } - } - - if(csiz->effective_bits >= 0) { - FREEMEM(st->buf); - st->size = (csiz->upper_bound + 7) >> 3; - st->buf = (uint8_t *)MALLOC(st->size + 1); - if(!st->buf) { st->size = 0; RETURN(RC_FAIL); } - } - - /* X.691, #16.5: zero-length encoding */ - /* X.691, #16.6: short fixed length encoding (up to 2 octets) */ - /* X.691, #16.7: long fixed length encoding (up to 64K octets) */ - if(csiz->effective_bits == 0) { - int ret; - ASN_DEBUG("Encoding BIT STRING size %ld", csiz->upper_bound); - ret = per_get_many_bits(pd, st->buf, 0, csiz->upper_bound); - if(ret < 0) RETURN(RC_WMORE); - consumed_myself += csiz->upper_bound; - st->buf[st->size] = 0; - st->bits_unused = (8 - (csiz->upper_bound & 0x7)) & 0x7; - RETURN(RC_OK); - } - - st->size = 0; - do { - ssize_t raw_len; - ssize_t len_bytes; - ssize_t len_bits; - void *p; - int ret; - - /* Get the PER length */ - raw_len = uper_get_length(pd, csiz->effective_bits, csiz->lower_bound, - &repeat); - if(raw_len < 0) RETURN(RC_WMORE); - if(raw_len == 0 && st->buf) break; - - ASN_DEBUG("Got PER length eb %ld, len %ld, %s (%s)", - (long)csiz->effective_bits, (long)raw_len, - repeat ? "repeat" : "once", td->name); - len_bits = raw_len; - len_bytes = (len_bits + 7) >> 3; - if(len_bits & 0x7) st->bits_unused = 8 - (len_bits & 0x7); - /* len_bits be multiple of 16K if repeat is set */ - p = REALLOC(st->buf, st->size + len_bytes + 1); - if(!p) RETURN(RC_FAIL); - st->buf = (uint8_t *)p; - - ret = per_get_many_bits(pd, &st->buf[st->size], 0, len_bits); - if(ret < 0) RETURN(RC_WMORE); - st->size += len_bytes; - } while(repeat); - st->buf[st->size] = 0; /* nul-terminate */ - - return rval; -} - -asn_enc_rval_t -BIT_STRING_encode_uper(const asn_TYPE_descriptor_t *td, - const asn_per_constraints_t *constraints, - const void *sptr, asn_per_outp_t *po) { - const asn_OCTET_STRING_specifics_t *specs = - td->specifics ? (const asn_OCTET_STRING_specifics_t *)td->specifics - : &asn_SPC_BIT_STRING_specs; - const asn_per_constraints_t *pc = - constraints ? constraints : td->encoding_constraints.per_constraints; - const asn_per_constraint_t *csiz; - const BIT_STRING_t *st = (const BIT_STRING_t *)sptr; - BIT_STRING_t compact_bstr; /* Do not modify this directly! */ - asn_enc_rval_t er = { 0, 0, 0 }; - int inext = 0; /* Lies not within extension root */ - size_t size_in_bits; - const uint8_t *buf; - int ret; - int ct_extensible; - - if(!st || (!st->buf && st->size)) - ASN__ENCODE_FAILED; - - if(specs->subvariant == ASN_OSUBV_BIT) { - if((st->size == 0 && st->bits_unused) || (st->bits_unused & ~7)) - ASN__ENCODE_FAILED; - } else { - ASN__ENCODE_FAILED; - } - - if(pc) { - csiz = &pc->size; - } else { - csiz = &asn_DEF_BIT_STRING_constraint_size; - } - ct_extensible = csiz->flags & APC_EXTENSIBLE; - - /* Figure out the size without the trailing bits */ - st = BIT_STRING__compactify(st, &compact_bstr); - size_in_bits = 8 * st->size - st->bits_unused; - - ASN_DEBUG( - "Encoding %s into %" ASN_PRI_SIZE " bits" - " (%ld..%ld, effective %d)%s", - td->name, size_in_bits, csiz->lower_bound, csiz->upper_bound, - csiz->effective_bits, ct_extensible ? " EXT" : ""); - - /* Figure out whether size lies within PER visible constraint */ - - if(csiz->effective_bits >= 0) { - if((ssize_t)size_in_bits > csiz->upper_bound) { - if(ct_extensible) { - csiz = &asn_DEF_BIT_STRING_constraint_size; - inext = 1; - } else { - ASN__ENCODE_FAILED; - } - } - } else { - inext = 0; - } - - if(ct_extensible) { - /* Declare whether length is [not] within extension root */ - if(per_put_few_bits(po, inext, 1)) - ASN__ENCODE_FAILED; - } - - if(csiz->effective_bits >= 0 && !inext) { - int add_trailer = (ssize_t)size_in_bits < csiz->lower_bound; - ASN_DEBUG( - "Encoding %" ASN_PRI_SIZE " bytes (%ld), length (in %d bits) trailer %d; actual " - "value %" ASN_PRI_SSIZE "", - st->size, size_in_bits - csiz->lower_bound, csiz->effective_bits, - add_trailer, - add_trailer ? 0 : (ssize_t)size_in_bits - csiz->lower_bound); - ret = per_put_few_bits( - po, add_trailer ? 0 : (ssize_t)size_in_bits - csiz->lower_bound, - csiz->effective_bits); - if(ret) ASN__ENCODE_FAILED; - ret = per_put_many_bits(po, st->buf, size_in_bits); - if(ret) ASN__ENCODE_FAILED; - if(add_trailer) { - static const uint8_t zeros[16]; - size_t trailing_zero_bits = csiz->lower_bound - size_in_bits; - while(trailing_zero_bits > 0) { - if(trailing_zero_bits > 8 * sizeof(zeros)) { - ret = per_put_many_bits(po, zeros, 8 * sizeof(zeros)); - trailing_zero_bits -= 8 * sizeof(zeros); - } else { - ret = per_put_many_bits(po, zeros, trailing_zero_bits); - trailing_zero_bits = 0; - } - if(ret) ASN__ENCODE_FAILED; - } - } - ASN__ENCODED_OK(er); - } - - ASN_DEBUG("Encoding %" ASN_PRI_SIZE " bytes", st->size); - - buf = st->buf; - do { - int need_eom = 0; - ssize_t maySave = uper_put_length(po, size_in_bits, &need_eom); - if(maySave < 0) ASN__ENCODE_FAILED; - - ASN_DEBUG("Encoding %" ASN_PRI_SSIZE " of %" ASN_PRI_SIZE "", maySave, size_in_bits); - - ret = per_put_many_bits(po, buf, maySave); - if(ret) ASN__ENCODE_FAILED; - - buf += maySave >> 3; - size_in_bits -= maySave; - assert(!(maySave & 0x07) || !size_in_bits); - if(need_eom && uper_put_length(po, 0, 0)) - ASN__ENCODE_FAILED; /* End of Message length */ - } while(size_in_bits); - - ASN__ENCODED_OK(er); -} - -#endif /* ASN_DISABLE_PER_SUPPORT */ - asn_random_fill_result_t BIT_STRING_random_fill(const asn_TYPE_descriptor_t *td, void **sptr, const asn_encoding_constraints_t *constraints, @@ -577,46 +322,7 @@ BIT_STRING_random_fill(const asn_TYPE_descriptor_t *td, void **sptr, /* Figure out how far we should go */ rnd_bits = lengths[asn_random_between( 0, sizeof(lengths) / sizeof(lengths[0]) - 1)]; - if(!constraints || !constraints->per_constraints) - constraints = &td->encoding_constraints; - if(constraints->per_constraints) { - const asn_per_constraint_t *pc = &constraints->per_constraints->size; - if(pc->flags & APC_CONSTRAINED) { - long suggested_upper_bound = pc->upper_bound < (ssize_t)max_length - ? pc->upper_bound - : (ssize_t)max_length; - if(max_length < (size_t)pc->lower_bound) { - return result_skipped; - } - if(pc->flags & APC_EXTENSIBLE) { - switch(asn_random_between(0, 5)) { - case 0: - if(pc->lower_bound > 0) { - rnd_bits = pc->lower_bound - 1; - break; - } - /* Fall through */ - case 1: - rnd_bits = pc->upper_bound + 1; - break; - case 2: - /* Keep rnd_bits from the table */ - if(rnd_bits < max_length) { - break; - } - /* Fall through */ - default: - rnd_bits = asn_random_between(pc->lower_bound, - suggested_upper_bound); - } - } else { - rnd_bits = - asn_random_between(pc->lower_bound, suggested_upper_bound); - } - } else { - rnd_bits = asn_random_between(0, max_length - 1); - } - } else if(rnd_bits >= max_length) { + if(rnd_bits >= max_length) { rnd_bits = asn_random_between(0, max_length - 1); } diff --git a/src/asn1/asn1c/BIT_STRING.h b/src/asn1/asn1c/BIT_STRING.h index 2245aeba..60f03cd3 100644 --- a/src/asn1/asn1c/BIT_STRING.h +++ b/src/asn1/asn1c/BIT_STRING.h @@ -28,10 +28,6 @@ asn_struct_print_f BIT_STRING_print; /* Human-readable output */ asn_struct_compare_f BIT_STRING_compare; asn_constr_check_f BIT_STRING_constraint; xer_type_encoder_f BIT_STRING_encode_xer; -oer_type_decoder_f BIT_STRING_decode_oer; -oer_type_encoder_f BIT_STRING_encode_oer; -per_type_decoder_f BIT_STRING_decode_uper; -per_type_encoder_f BIT_STRING_encode_uper; asn_random_fill_f BIT_STRING_random_fill; #define BIT_STRING_free OCTET_STRING_free diff --git a/src/asn1/asn1c/BIT_STRING_oer.c b/src/asn1/asn1c/BIT_STRING_oer.c deleted file mode 100644 index 5767d333..00000000 --- a/src/asn1/asn1c/BIT_STRING_oer.c +++ /dev/null @@ -1,173 +0,0 @@ -/* - * Copyright (c) 2017 Lev Walkin . - * All rights reserved. - * Redistribution and modifications are permitted subject to BSD license. - */ -#ifndef ASN_DISABLE_OER_SUPPORT - -#include "asn1/asn1c/asn_internal.h" -#include "asn1/asn1c/BIT_STRING.h" - -asn_dec_rval_t -BIT_STRING_decode_oer(const asn_codec_ctx_t *opt_codec_ctx, - const asn_TYPE_descriptor_t *td, - const asn_oer_constraints_t *constraints, void **sptr, - const void *ptr, size_t size) { - BIT_STRING_t *st = (BIT_STRING_t *)*sptr; - const asn_oer_constraints_t *cts = - constraints ? constraints : td->encoding_constraints.oer_constraints; - ssize_t ct_size = cts ? cts->size : -1; - asn_dec_rval_t rval = {RC_OK, 0}; - size_t expected_length = 0; - - (void)opt_codec_ctx; - - if(!st) { - st = (BIT_STRING_t *)(*sptr = CALLOC(1, sizeof(*st))); - if(!st) ASN__DECODE_FAILED; - } - - if(ct_size >= 0) { - expected_length = (ct_size + 7) >> 3; - st->bits_unused = (8 - (ct_size & 7)) & 7; - } else { - /* - * X.696 (08/2015) #13.3.1 - * Encode length determinant as _number of octets_, but only - * if upper bound is not equal to lower bound. - */ - ssize_t len_len = oer_fetch_length(ptr, size, &expected_length); - if(len_len > 0) { - ptr = (const char *)ptr + len_len; - size -= len_len; - } else if(len_len == 0) { - ASN__DECODE_STARVED; - } else if(len_len < 0) { - ASN__DECODE_FAILED; - } - - if(expected_length < 1) { - ASN__DECODE_FAILED; - } else if(expected_length > size) { - ASN__DECODE_STARVED; - } - - st->bits_unused = ((const uint8_t *)ptr)[0]; - if(st->bits_unused & ~7) { - ASN_DEBUG("%s: unused bits outside of 0..7 range", td->name); - ASN__DECODE_FAILED; - } - ptr = (const char *)ptr + 1; - size--; - expected_length--; - rval.consumed = len_len + 1; - } - - if(size < expected_length) { - ASN__DECODE_STARVED; - } else { - uint8_t *buf = MALLOC(expected_length + 1); - if(buf == NULL) { - ASN__DECODE_FAILED; - } else { - memcpy(buf, ptr, expected_length); - buf[expected_length] = '\0'; - } - FREEMEM(st->buf); - st->buf = buf; - st->size = expected_length; - if(expected_length > 0) { - buf[expected_length - 1] &= (0xff << st->bits_unused); - } - - rval.consumed += expected_length; - return rval; - } -} - -/* - * Encode as Canonical OER. - */ -asn_enc_rval_t -BIT_STRING_encode_oer(const asn_TYPE_descriptor_t *td, - const asn_oer_constraints_t *constraints, - const void *sptr, asn_app_consume_bytes_f *cb, - void *app_key) { - const BIT_STRING_t *st = (const BIT_STRING_t *)sptr; - asn_enc_rval_t erval = {0, 0, 0}; - const asn_oer_constraints_t *cts = - constraints ? constraints : td->encoding_constraints.oer_constraints; - ssize_t ct_size = cts ? cts->size : -1; - size_t trailing_zeros = 0; - int fix_last_byte = 0; - - if(!st) ASN__ENCODE_FAILED; - - if(st->bits_unused & ~7) { - ASN_DEBUG("BIT STRING unused bits %d out of 0..7 range", - st->bits_unused); - ASN__ENCODE_FAILED; - } - if(st->bits_unused && !(st->size && st->buf)) { - ASN_DEBUG("BIT STRING %s size 0 can't support unused bits %d", td->name, - st->bits_unused); - ASN__ENCODE_FAILED; - } - - if(ct_size >= 0) { - size_t ct_bytes = (ct_size + 7) >> 3; - if(st->size > ct_bytes) { - ASN_DEBUG("More bits in BIT STRING %s (%" ASN_PRI_SSIZE ") than constrained %" ASN_PRI_SSIZE "", - td->name, 8 * st->size - st->bits_unused, ct_size); - ASN__ENCODE_FAILED; - } - trailing_zeros = ct_bytes - st->size; /* Allow larger constraint */ - } else { - uint8_t ub = st->bits_unused & 7; - ssize_t len_len = oer_serialize_length(1 + st->size, cb, app_key); - if(len_len < 0) ASN__ENCODE_FAILED; - if(cb(&ub, 1, app_key) < 0) { - ASN__ENCODE_FAILED; - } - erval.encoded += len_len + 1; - } - - if(st->bits_unused) { - if(st->buf[st->size - 1] & (0xff << st->bits_unused)) { - fix_last_byte = 1; - } - } - - if(cb(st->buf, st->size - fix_last_byte, app_key) < 0) { - ASN__ENCODE_FAILED; - } - - if(fix_last_byte) { - uint8_t b = st->buf[st->size - 1] & (0xff << st->bits_unused); - if(cb(&b, 1, app_key) < 0) { - ASN__ENCODE_FAILED; - } - } - - erval.encoded += st->size; - - if(trailing_zeros) { - static uint8_t zeros[16]; - while(trailing_zeros > 0) { - int ret; - if(trailing_zeros < sizeof(zeros)) { - ret = cb(zeros, trailing_zeros, app_key); - erval.encoded += trailing_zeros; - } else { - ret = cb(zeros, sizeof(zeros), app_key); - erval.encoded += sizeof(zeros); - } - if(ret < 0) ASN__ENCODE_FAILED; - } - } - - return erval; -} - - -#endif /* ASN_DISABLE_OER_SUPPORT */ diff --git a/src/asn1/asn1c/BOOLEAN.c b/src/asn1/asn1c/BOOLEAN.c index 3b87bf5c..dd053782 100644 --- a/src/asn1/asn1c/BOOLEAN.c +++ b/src/asn1/asn1c/BOOLEAN.c @@ -20,20 +20,6 @@ asn_TYPE_operation_t asn_OP_BOOLEAN = { BOOLEAN_encode_der, BOOLEAN_decode_xer, BOOLEAN_encode_xer, -#ifdef ASN_DISABLE_OER_SUPPORT - 0, - 0, -#else - BOOLEAN_decode_oer, - BOOLEAN_encode_oer, -#endif /* ASN_DISABLE_OER_SUPPORT */ -#ifdef ASN_DISABLE_PER_SUPPORT - 0, - 0, -#else - BOOLEAN_decode_uper, /* Unaligned PER decoder */ - BOOLEAN_encode_uper, /* Unaligned PER encoder */ -#endif /* ASN_DISABLE_PER_SUPPORT */ BOOLEAN_random_fill, 0 /* Use generic outmost tag fetcher */ }; @@ -257,114 +243,6 @@ BOOLEAN_free(const asn_TYPE_descriptor_t *td, void *ptr, } } -#ifndef ASN_DISABLE_PER_SUPPORT - -asn_dec_rval_t -BOOLEAN_decode_uper(const asn_codec_ctx_t *opt_codec_ctx, - const asn_TYPE_descriptor_t *td, - const asn_per_constraints_t *constraints, void **sptr, - asn_per_data_t *pd) { - asn_dec_rval_t rv; - BOOLEAN_t *st = (BOOLEAN_t *)*sptr; - - (void)opt_codec_ctx; - (void)td; - (void)constraints; - - if(!st) { - st = (BOOLEAN_t *)(*sptr = MALLOC(sizeof(*st))); - if(!st) ASN__DECODE_FAILED; - } - - /* - * Extract a single bit - */ - switch(per_get_few_bits(pd, 1)) { - case 1: *st = 1; break; - case 0: *st = 0; break; - case -1: default: ASN__DECODE_STARVED; - } - - ASN_DEBUG("%s decoded as %s", td->name, *st ? "TRUE" : "FALSE"); - - rv.code = RC_OK; - rv.consumed = 1; - return rv; -} - - -asn_enc_rval_t -BOOLEAN_encode_uper(const asn_TYPE_descriptor_t *td, - const asn_per_constraints_t *constraints, const void *sptr, - asn_per_outp_t *po) { - const BOOLEAN_t *st = (const BOOLEAN_t *)sptr; - asn_enc_rval_t er = { 0, 0, 0 }; - - (void)constraints; - - if(!st) ASN__ENCODE_FAILED; - - if(per_put_few_bits(po, *st ? 1 : 0, 1)) - ASN__ENCODE_FAILED; - - ASN__ENCODED_OK(er); -} - -#endif /* ASN_DISABLE_PER_SUPPORT */ - -#ifndef ASN_DISABLE_OER_SUPPORT - -/* - * Encode as Canonical OER. - */ -asn_enc_rval_t -BOOLEAN_encode_oer(const asn_TYPE_descriptor_t *td, - const asn_oer_constraints_t *constraints, const void *sptr, - asn_app_consume_bytes_f *cb, void *app_key) { - asn_enc_rval_t er = { 1, 0, 0 }; - const BOOLEAN_t *st = sptr; - uint8_t bool_value = *st ? 0xff : 0; /* 0xff mandated by OER */ - - (void)td; - (void)constraints; /* Constraints are unused in OER */ - - if(cb(&bool_value, 1, app_key) < 0) { - ASN__ENCODE_FAILED; - } else { - ASN__ENCODED_OK(er); - } -} - -asn_dec_rval_t -BOOLEAN_decode_oer(const asn_codec_ctx_t *opt_codec_ctx, - const asn_TYPE_descriptor_t *td, - const asn_oer_constraints_t *constraints, void **sptr, - const void *ptr, size_t size) { - asn_dec_rval_t ok = {RC_OK, 1}; - BOOLEAN_t *st; - - (void)opt_codec_ctx; - (void)td; - (void)constraints; /* Constraints are unused in OER */ - - if(size < 1) { - ASN__DECODE_STARVED; - } - - if(!(st = *sptr)) { - st = (BOOLEAN_t *)(*sptr = CALLOC(1, sizeof(*st))); - if(!st) ASN__DECODE_FAILED; - } - - *st = *(const uint8_t *)ptr; - - return ok; -} - - - -#endif - int BOOLEAN_compare(const asn_TYPE_descriptor_t *td, const void *aptr, const void *bptr) { @@ -406,16 +284,6 @@ BOOLEAN_random_fill(const asn_TYPE_descriptor_t *td, void **sptr, } } - if(!constraints || !constraints->per_constraints) - constraints = &td->encoding_constraints; - if(constraints->per_constraints) { - const asn_per_constraint_t *pc = &constraints->per_constraints->value; - if(pc->flags & APC_CONSTRAINED) { - *st = asn_random_between(pc->lower_bound, pc->upper_bound); - return result_ok; - } - } - /* Simulate booleans that are sloppily set and biased. */ switch(asn_random_between(0, 7)) { case 0: diff --git a/src/asn1/asn1c/BOOLEAN.h b/src/asn1/asn1c/BOOLEAN.h index 972da8d4..ece1ae5e 100644 --- a/src/asn1/asn1c/BOOLEAN.h +++ b/src/asn1/asn1c/BOOLEAN.h @@ -26,10 +26,6 @@ asn_struct_print_f BOOLEAN_print; asn_struct_compare_f BOOLEAN_compare; ber_type_decoder_f BOOLEAN_decode_ber; der_type_encoder_f BOOLEAN_encode_der; -oer_type_decoder_f BOOLEAN_decode_oer; -oer_type_encoder_f BOOLEAN_encode_oer; -per_type_decoder_f BOOLEAN_decode_uper; -per_type_encoder_f BOOLEAN_encode_uper; xer_type_decoder_f BOOLEAN_decode_xer; xer_type_encoder_f BOOLEAN_encode_xer; asn_random_fill_f BOOLEAN_random_fill; diff --git a/src/asn1/asn1c/BinarySigningTime.c b/src/asn1/asn1c/BinarySigningTime.c index 821e8139..7b93b310 100644 --- a/src/asn1/asn1c/BinarySigningTime.c +++ b/src/asn1/asn1c/BinarySigningTime.c @@ -38,9 +38,6 @@ BinarySigningTime_constraint(const asn_TYPE_descriptor_t *td, const void *sptr, * This type is implemented using BinaryTime, * so here we adjust the DEF accordingly. */ -static asn_oer_constraints_t asn_OER_type_BinarySigningTime_constr_1 CC_NOTUSED = { - { 0, 1 } /* (0..MAX) */, - -1}; static const ber_tlv_tag_t asn_DEF_BinarySigningTime_tags_1[] = { (ASN_TAG_CLASS_UNIVERSAL | (2 << 2)) }; @@ -54,7 +51,7 @@ asn_TYPE_descriptor_t asn_DEF_BinarySigningTime = { asn_DEF_BinarySigningTime_tags_1, /* Same as above */ sizeof(asn_DEF_BinarySigningTime_tags_1) /sizeof(asn_DEF_BinarySigningTime_tags_1[0]), /* 1 */ - { &asn_OER_type_BinarySigningTime_constr_1, 0, BinarySigningTime_constraint }, + { NULL, 0, BinarySigningTime_constraint }, 0, 0, /* No members */ 0 /* No specifics */ }; diff --git a/src/asn1/asn1c/BinarySigningTime.h b/src/asn1/asn1c/BinarySigningTime.h index 36403542..a04bf3d1 100644 --- a/src/asn1/asn1c/BinarySigningTime.h +++ b/src/asn1/asn1c/BinarySigningTime.h @@ -30,8 +30,6 @@ ber_type_decoder_f BinarySigningTime_decode_ber; der_type_encoder_f BinarySigningTime_encode_der; xer_type_decoder_f BinarySigningTime_decode_xer; xer_type_encoder_f BinarySigningTime_encode_xer; -oer_type_decoder_f BinarySigningTime_decode_oer; -oer_type_encoder_f BinarySigningTime_encode_oer; #ifdef __cplusplus } diff --git a/src/asn1/asn1c/BinaryTime.c b/src/asn1/asn1c/BinaryTime.c index d79e9938..16fd2bcd 100644 --- a/src/asn1/asn1c/BinaryTime.c +++ b/src/asn1/asn1c/BinaryTime.c @@ -38,9 +38,6 @@ BinaryTime_constraint(const asn_TYPE_descriptor_t *td, const void *sptr, * This type is implemented using INTEGER, * so here we adjust the DEF accordingly. */ -static asn_oer_constraints_t asn_OER_type_BinaryTime_constr_1 CC_NOTUSED = { - { 0, 1 } /* (0..MAX) */, - -1}; static const ber_tlv_tag_t asn_DEF_BinaryTime_tags_1[] = { (ASN_TAG_CLASS_UNIVERSAL | (2 << 2)) }; @@ -54,7 +51,7 @@ asn_TYPE_descriptor_t asn_DEF_BinaryTime = { asn_DEF_BinaryTime_tags_1, /* Same as above */ sizeof(asn_DEF_BinaryTime_tags_1) /sizeof(asn_DEF_BinaryTime_tags_1[0]), /* 1 */ - { &asn_OER_type_BinaryTime_constr_1, 0, BinaryTime_constraint }, + { NULL, 0, BinaryTime_constraint }, 0, 0, /* No members */ 0 /* No specifics */ }; diff --git a/src/asn1/asn1c/BinaryTime.h b/src/asn1/asn1c/BinaryTime.h index 11408191..cc15dabc 100644 --- a/src/asn1/asn1c/BinaryTime.h +++ b/src/asn1/asn1c/BinaryTime.h @@ -30,8 +30,6 @@ ber_type_decoder_f BinaryTime_decode_ber; der_type_encoder_f BinaryTime_encode_der; xer_type_decoder_f BinaryTime_decode_xer; xer_type_encoder_f BinaryTime_encode_xer; -oer_type_decoder_f BinaryTime_decode_oer; -oer_type_encoder_f BinaryTime_encode_oer; #ifdef __cplusplus } diff --git a/src/asn1/asn1c/CMSAttribute.c b/src/asn1/asn1c/CMSAttribute.c index c72afd0f..e66ee687 100644 --- a/src/asn1/asn1c/CMSAttribute.c +++ b/src/asn1/asn1c/CMSAttribute.c @@ -75,7 +75,6 @@ asn_SEQUENCE_specifics_t asn_SPC_CMSAttribute_specs_1 = { offsetof(struct CMSAttribute, _asn_ctx), asn_MAP_CMSAttribute_tag2el_1, 2, /* Count of tags in the map */ - 0, 0, 0, /* Optional elements (not needed) */ -1, /* First extension addition */ }; asn_TYPE_descriptor_t asn_DEF_CMSAttribute = { diff --git a/src/asn1/asn1c/CMSAttributeValue.h b/src/asn1/asn1c/CMSAttributeValue.h index 126ea1ba..176b4417 100644 --- a/src/asn1/asn1c/CMSAttributeValue.h +++ b/src/asn1/asn1c/CMSAttributeValue.h @@ -30,8 +30,6 @@ ber_type_decoder_f CMSAttributeValue_decode_ber; der_type_encoder_f CMSAttributeValue_encode_der; xer_type_decoder_f CMSAttributeValue_decode_xer; xer_type_encoder_f CMSAttributeValue_encode_xer; -oer_type_decoder_f CMSAttributeValue_decode_oer; -oer_type_encoder_f CMSAttributeValue_encode_oer; #ifdef __cplusplus } diff --git a/src/asn1/asn1c/CMSSubjectKeyIdentifier.h b/src/asn1/asn1c/CMSSubjectKeyIdentifier.h index ffd3b0dd..ad567591 100644 --- a/src/asn1/asn1c/CMSSubjectKeyIdentifier.h +++ b/src/asn1/asn1c/CMSSubjectKeyIdentifier.h @@ -30,8 +30,6 @@ ber_type_decoder_f CMSSubjectKeyIdentifier_decode_ber; der_type_encoder_f CMSSubjectKeyIdentifier_encode_der; xer_type_decoder_f CMSSubjectKeyIdentifier_decode_xer; xer_type_encoder_f CMSSubjectKeyIdentifier_encode_xer; -oer_type_decoder_f CMSSubjectKeyIdentifier_decode_oer; -oer_type_encoder_f CMSSubjectKeyIdentifier_encode_oer; #ifdef __cplusplus } diff --git a/src/asn1/asn1c/CMSVersion.h b/src/asn1/asn1c/CMSVersion.h index f479155c..8454a9a9 100644 --- a/src/asn1/asn1c/CMSVersion.h +++ b/src/asn1/asn1c/CMSVersion.h @@ -40,8 +40,6 @@ ber_type_decoder_f CMSVersion_decode_ber; der_type_encoder_f CMSVersion_encode_der; xer_type_decoder_f CMSVersion_decode_xer; xer_type_encoder_f CMSVersion_encode_xer; -oer_type_decoder_f CMSVersion_decode_oer; -oer_type_encoder_f CMSVersion_encode_oer; #ifdef __cplusplus } diff --git a/src/asn1/asn1c/CertificateList.c b/src/asn1/asn1c/CertificateList.c index f25a7fcf..6b653399 100644 --- a/src/asn1/asn1c/CertificateList.c +++ b/src/asn1/asn1c/CertificateList.c @@ -49,7 +49,6 @@ asn_SEQUENCE_specifics_t asn_SPC_CertificateList_specs_1 = { offsetof(struct CertificateList, _asn_ctx), asn_MAP_CertificateList_tag2el_1, 3, /* Count of tags in the map */ - 0, 0, 0, /* Optional elements (not needed) */ -1, /* First extension addition */ }; asn_TYPE_descriptor_t asn_DEF_CertificateList = { diff --git a/src/asn1/asn1c/CertificateSerialNumber.h b/src/asn1/asn1c/CertificateSerialNumber.h index ec65178c..d08729c8 100644 --- a/src/asn1/asn1c/CertificateSerialNumber.h +++ b/src/asn1/asn1c/CertificateSerialNumber.h @@ -30,8 +30,6 @@ ber_type_decoder_f CertificateSerialNumber_decode_ber; der_type_encoder_f CertificateSerialNumber_encode_der; xer_type_decoder_f CertificateSerialNumber_decode_xer; xer_type_encoder_f CertificateSerialNumber_encode_xer; -oer_type_decoder_f CertificateSerialNumber_decode_oer; -oer_type_encoder_f CertificateSerialNumber_encode_oer; #ifdef __cplusplus } diff --git a/src/asn1/asn1c/ContentInfo.c b/src/asn1/asn1c/ContentInfo.c index 8216b1f5..c522bebb 100644 --- a/src/asn1/asn1c/ContentInfo.c +++ b/src/asn1/asn1c/ContentInfo.c @@ -39,7 +39,6 @@ static asn_SEQUENCE_specifics_t asn_SPC_ContentInfo_specs_1 = { offsetof(struct ContentInfo, _asn_ctx), asn_MAP_ContentInfo_tag2el_1, 2, /* Count of tags in the map */ - 0, 0, 0, /* Optional elements (not needed) */ -1, /* First extension addition */ }; asn_TYPE_descriptor_t asn_DEF_ContentInfo = { diff --git a/src/asn1/asn1c/ContentType.h b/src/asn1/asn1c/ContentType.h index abb8c479..06868fa9 100644 --- a/src/asn1/asn1c/ContentType.h +++ b/src/asn1/asn1c/ContentType.h @@ -30,8 +30,6 @@ ber_type_decoder_f ContentType_decode_ber; der_type_encoder_f ContentType_encode_der; xer_type_decoder_f ContentType_decode_xer; xer_type_encoder_f ContentType_encode_xer; -oer_type_decoder_f ContentType_decode_oer; -oer_type_encoder_f ContentType_encode_oer; #ifdef __cplusplus } diff --git a/src/asn1/asn1c/ContentTypePKCS7.h b/src/asn1/asn1c/ContentTypePKCS7.h index becf8603..27b44e80 100644 --- a/src/asn1/asn1c/ContentTypePKCS7.h +++ b/src/asn1/asn1c/ContentTypePKCS7.h @@ -30,8 +30,6 @@ ber_type_decoder_f ContentTypePKCS7_decode_ber; der_type_encoder_f ContentTypePKCS7_encode_der; xer_type_decoder_f ContentTypePKCS7_decode_xer; xer_type_encoder_f ContentTypePKCS7_encode_xer; -oer_type_decoder_f ContentTypePKCS7_decode_oer; -oer_type_encoder_f ContentTypePKCS7_encode_oer; #ifdef __cplusplus } diff --git a/src/asn1/asn1c/Countersignature.h b/src/asn1/asn1c/Countersignature.h index bb8358ac..9007f973 100644 --- a/src/asn1/asn1c/Countersignature.h +++ b/src/asn1/asn1c/Countersignature.h @@ -30,8 +30,6 @@ ber_type_decoder_f Countersignature_decode_ber; der_type_encoder_f Countersignature_encode_der; xer_type_decoder_f Countersignature_decode_xer; xer_type_encoder_f Countersignature_encode_xer; -oer_type_decoder_f Countersignature_decode_oer; -oer_type_encoder_f Countersignature_encode_oer; #ifdef __cplusplus } diff --git a/src/asn1/asn1c/DigestAlgorithmIdentifier.h b/src/asn1/asn1c/DigestAlgorithmIdentifier.h index e520c190..56f505ff 100644 --- a/src/asn1/asn1c/DigestAlgorithmIdentifier.h +++ b/src/asn1/asn1c/DigestAlgorithmIdentifier.h @@ -30,8 +30,6 @@ ber_type_decoder_f DigestAlgorithmIdentifier_decode_ber; der_type_encoder_f DigestAlgorithmIdentifier_encode_der; xer_type_decoder_f DigestAlgorithmIdentifier_decode_xer; xer_type_encoder_f DigestAlgorithmIdentifier_encode_xer; -oer_type_decoder_f DigestAlgorithmIdentifier_decode_oer; -oer_type_encoder_f DigestAlgorithmIdentifier_encode_oer; #ifdef __cplusplus } diff --git a/src/asn1/asn1c/DistinguishedName.h b/src/asn1/asn1c/DistinguishedName.h index c1138ced..56c9776e 100644 --- a/src/asn1/asn1c/DistinguishedName.h +++ b/src/asn1/asn1c/DistinguishedName.h @@ -30,8 +30,6 @@ ber_type_decoder_f DistinguishedName_decode_ber; der_type_encoder_f DistinguishedName_encode_der; xer_type_decoder_f DistinguishedName_decode_xer; xer_type_encoder_f DistinguishedName_encode_xer; -oer_type_decoder_f DistinguishedName_decode_oer; -oer_type_encoder_f DistinguishedName_encode_oer; #ifdef __cplusplus } diff --git a/src/asn1/asn1c/EncapsulatedContentInfo.c b/src/asn1/asn1c/EncapsulatedContentInfo.c index 3f116901..6de83cae 100644 --- a/src/asn1/asn1c/EncapsulatedContentInfo.c +++ b/src/asn1/asn1c/EncapsulatedContentInfo.c @@ -27,7 +27,6 @@ asn_TYPE_member_t asn_MBR_EncapsulatedContentInfo_1[] = { "eContent" }, }; -static const int asn_MAP_EncapsulatedContentInfo_oms_1[] = { 1 }; static const ber_tlv_tag_t asn_DEF_EncapsulatedContentInfo_tags_1[] = { (ASN_TAG_CLASS_UNIVERSAL | (16 << 2)) }; @@ -40,8 +39,6 @@ asn_SEQUENCE_specifics_t asn_SPC_EncapsulatedContentInfo_specs_1 = { offsetof(struct EncapsulatedContentInfo, _asn_ctx), asn_MAP_EncapsulatedContentInfo_tag2el_1, 2, /* Count of tags in the map */ - asn_MAP_EncapsulatedContentInfo_oms_1, /* Optional members */ - 1, 0, /* Root/Additions */ -1, /* First extension addition */ }; asn_TYPE_descriptor_t asn_DEF_EncapsulatedContentInfo = { diff --git a/src/asn1/asn1c/EncapsulatedContentInfoPKCS7.c b/src/asn1/asn1c/EncapsulatedContentInfoPKCS7.c index d0294e8e..60b9a727 100644 --- a/src/asn1/asn1c/EncapsulatedContentInfoPKCS7.c +++ b/src/asn1/asn1c/EncapsulatedContentInfoPKCS7.c @@ -27,7 +27,6 @@ asn_TYPE_member_t asn_MBR_EncapsulatedContentInfoPKCS7_1[] = { "eContent" }, }; -static const int asn_MAP_EncapsulatedContentInfoPKCS7_oms_1[] = { 1 }; static const ber_tlv_tag_t asn_DEF_EncapsulatedContentInfoPKCS7_tags_1[] = { (ASN_TAG_CLASS_UNIVERSAL | (16 << 2)) }; @@ -40,8 +39,6 @@ asn_SEQUENCE_specifics_t asn_SPC_EncapsulatedContentInfoPKCS7_specs_1 = { offsetof(struct EncapsulatedContentInfoPKCS7, _asn_ctx), asn_MAP_EncapsulatedContentInfoPKCS7_tag2el_1, 2, /* Count of tags in the map */ - asn_MAP_EncapsulatedContentInfoPKCS7_oms_1, /* Optional members */ - 1, 0, /* Root/Additions */ -1, /* First extension addition */ }; asn_TYPE_descriptor_t asn_DEF_EncapsulatedContentInfoPKCS7 = { diff --git a/src/asn1/asn1c/Extension.c b/src/asn1/asn1c/Extension.c index 4d448cba..5588ed75 100644 --- a/src/asn1/asn1c/Extension.c +++ b/src/asn1/asn1c/Extension.c @@ -59,7 +59,6 @@ asn_TYPE_member_t asn_MBR_Extension_1[] = { "extnValue" }, }; -static const int asn_MAP_Extension_oms_1[] = { 1 }; static const ber_tlv_tag_t asn_DEF_Extension_tags_1[] = { (ASN_TAG_CLASS_UNIVERSAL | (16 << 2)) }; @@ -73,8 +72,6 @@ asn_SEQUENCE_specifics_t asn_SPC_Extension_specs_1 = { offsetof(struct Extension, _asn_ctx), asn_MAP_Extension_tag2el_1, 3, /* Count of tags in the map */ - asn_MAP_Extension_oms_1, /* Optional members */ - 1, 0, /* Root/Additions */ -1, /* First extension addition */ }; asn_TYPE_descriptor_t asn_DEF_Extension = { diff --git a/src/asn1/asn1c/Extensions.c b/src/asn1/asn1c/Extensions.c index 751a645f..f9926802 100644 --- a/src/asn1/asn1c/Extensions.c +++ b/src/asn1/asn1c/Extensions.c @@ -7,9 +7,6 @@ #include "asn1/asn1c/Extensions.h" -static asn_oer_constraints_t asn_OER_type_Extensions_constr_1 CC_NOTUSED = { - { 0, 0 }, - -1 /* (SIZE(1..MAX)) */}; asn_TYPE_member_t asn_MBR_Extensions_1[] = { { ATF_POINTER, 0, 0, (ASN_TAG_CLASS_UNIVERSAL | (16 << 2)), @@ -39,7 +36,7 @@ asn_TYPE_descriptor_t asn_DEF_Extensions = { asn_DEF_Extensions_tags_1, /* Same as above */ sizeof(asn_DEF_Extensions_tags_1) /sizeof(asn_DEF_Extensions_tags_1[0]), /* 1 */ - { &asn_OER_type_Extensions_constr_1, 0, SEQUENCE_OF_constraint }, + { NULL, 0, SEQUENCE_OF_constraint }, asn_MBR_Extensions_1, 1, /* Single element */ &asn_SPC_Extensions_specs_1 /* Additional specs */ diff --git a/src/asn1/asn1c/FileAndHash.c b/src/asn1/asn1c/FileAndHash.c index 4ee1ce8c..89367798 100644 --- a/src/asn1/asn1c/FileAndHash.c +++ b/src/asn1/asn1c/FileAndHash.c @@ -39,7 +39,6 @@ asn_SEQUENCE_specifics_t asn_SPC_FileAndHash_specs_1 = { offsetof(struct FileAndHash, _asn_ctx), asn_MAP_FileAndHash_tag2el_1, 2, /* Count of tags in the map */ - 0, 0, 0, /* Optional elements (not needed) */ -1, /* First extension addition */ }; asn_TYPE_descriptor_t asn_DEF_FileAndHash = { diff --git a/src/asn1/asn1c/GeneralizedTime.c b/src/asn1/asn1c/GeneralizedTime.c index 123557d6..ec7dceef 100644 --- a/src/asn1/asn1c/GeneralizedTime.c +++ b/src/asn1/asn1c/GeneralizedTime.c @@ -52,11 +52,6 @@ static const ber_tlv_tag_t asn_DEF_GeneralizedTime_tags[] = { (ASN_TAG_CLASS_UNIVERSAL | (26 << 2)), /* [UNIVERSAL 26] IMPLICIT ...*/ (ASN_TAG_CLASS_UNIVERSAL | (4 << 2)) /* ... OCTET STRING */ }; -static asn_per_constraints_t asn_DEF_GeneralizedTime_per_constraints = { - { APC_CONSTRAINED, 7, 7, 0x20, 0x7e }, /* Value */ - { APC_SEMI_CONSTRAINED, -1, -1, 0, 0 }, /* Size */ - 0, 0 -}; asn_TYPE_operation_t asn_OP_GeneralizedTime = { OCTET_STRING_free, GeneralizedTime_print, @@ -65,20 +60,6 @@ asn_TYPE_operation_t asn_OP_GeneralizedTime = { GeneralizedTime_encode_der, OCTET_STRING_decode_xer_utf8, GeneralizedTime_encode_xer, -#ifdef ASN_DISABLE_OER_SUPPORT - 0, - 0, -#else - OCTET_STRING_decode_oer, - OCTET_STRING_encode_oer, -#endif /* ASN_DISABLE_OER_SUPPORT */ -#ifdef ASN_DISABLE_PER_SUPPORT - 0, - 0, -#else - OCTET_STRING_decode_uper, - OCTET_STRING_encode_uper, -#endif /* ASN_DISABLE_PER_SUPPORT */ GeneralizedTime_random_fill, 0 /* Use generic outmost tag fetcher */ }; @@ -92,7 +73,7 @@ asn_TYPE_descriptor_t asn_DEF_GeneralizedTime = { asn_DEF_GeneralizedTime_tags, sizeof(asn_DEF_GeneralizedTime_tags) / sizeof(asn_DEF_GeneralizedTime_tags[0]), - { 0, &asn_DEF_GeneralizedTime_per_constraints, GeneralizedTime_constraint }, + { 0, NULL, GeneralizedTime_constraint }, 0, 0, /* No members */ 0 /* No specifics */ }; diff --git a/src/asn1/asn1c/GeneralizedTime.h b/src/asn1/asn1c/GeneralizedTime.h index be517c41..a60f8f5d 100644 --- a/src/asn1/asn1c/GeneralizedTime.h +++ b/src/asn1/asn1c/GeneralizedTime.h @@ -28,8 +28,6 @@ asn_random_fill_f GeneralizedTime_random_fill; #define GeneralizedTime_free OCTET_STRING_free #define GeneralizedTime_decode_ber OCTET_STRING_decode_ber #define GeneralizedTime_decode_xer OCTET_STRING_decode_xer_utf8 -#define GeneralizedTime_decode_uper OCTET_STRING_decode_uper -#define GeneralizedTime_encode_uper OCTET_STRING_encode_uper /*********************** * Some handy helpers. * diff --git a/src/asn1/asn1c/IA5String.c b/src/asn1/asn1c/IA5String.c index e2fa2f43..43a95370 100644 --- a/src/asn1/asn1c/IA5String.c +++ b/src/asn1/asn1c/IA5String.c @@ -12,11 +12,6 @@ static const ber_tlv_tag_t asn_DEF_IA5String_tags[] = { (ASN_TAG_CLASS_UNIVERSAL | (22 << 2)), /* [UNIVERSAL 22] IMPLICIT ...*/ (ASN_TAG_CLASS_UNIVERSAL | (4 << 2)) /* ... OCTET STRING */ }; -static asn_per_constraints_t asn_DEF_IA5String_per_constraints = { - { APC_CONSTRAINED, 7, 7, 0, 0x7f }, /* Value */ - { APC_SEMI_CONSTRAINED, -1, -1, 0, 0 }, /* Size */ - 0, 0 -}; asn_TYPE_operation_t asn_OP_IA5String = { OCTET_STRING_free, OCTET_STRING_print_utf8, /* ASCII subset */ @@ -25,20 +20,6 @@ asn_TYPE_operation_t asn_OP_IA5String = { OCTET_STRING_encode_der, OCTET_STRING_decode_xer_utf8, OCTET_STRING_encode_xer_utf8, -#ifdef ASN_DISABLE_OER_SUPPORT - 0, - 0, -#else - OCTET_STRING_decode_oer, - OCTET_STRING_encode_oer, -#endif /* ASN_DISABLE_OER_SUPPORT */ -#ifdef ASN_DISABLE_PER_SUPPORT - 0, - 0, -#else - OCTET_STRING_decode_uper, - OCTET_STRING_encode_uper, -#endif /* ASN_DISABLE_PER_SUPPORT */ OCTET_STRING_random_fill, 0 /* Use generic outmost tag fetcher */ }; @@ -52,7 +33,7 @@ asn_TYPE_descriptor_t asn_DEF_IA5String = { asn_DEF_IA5String_tags, sizeof(asn_DEF_IA5String_tags) / sizeof(asn_DEF_IA5String_tags[0]), - { 0, &asn_DEF_IA5String_per_constraints, IA5String_constraint }, + { 0, NULL, IA5String_constraint }, 0, 0, /* No members */ 0 /* No specifics */ }; diff --git a/src/asn1/asn1c/IA5String.h b/src/asn1/asn1c/IA5String.h index 59817f23..00ee20e7 100644 --- a/src/asn1/asn1c/IA5String.h +++ b/src/asn1/asn1c/IA5String.h @@ -28,8 +28,6 @@ asn_constr_check_f IA5String_constraint; #define IA5String_encode_der OCTET_STRING_encode_der #define IA5String_decode_xer OCTET_STRING_decode_xer_utf8 #define IA5String_encode_xer OCTET_STRING_encode_xer_utf8 -#define IA5String_decode_uper OCTET_STRING_decode_uper -#define IA5String_encode_uper OCTET_STRING_encode_uper #ifdef __cplusplus } diff --git a/src/asn1/asn1c/INTEGER.c b/src/asn1/asn1c/INTEGER.c index 1922e307..860ed337 100644 --- a/src/asn1/asn1c/INTEGER.c +++ b/src/asn1/asn1c/INTEGER.c @@ -23,20 +23,6 @@ asn_TYPE_operation_t asn_OP_INTEGER = { INTEGER_encode_der, INTEGER_decode_xer, INTEGER_encode_xer, -#ifdef ASN_DISABLE_OER_SUPPORT - 0, - 0, -#else - INTEGER_decode_oer, /* OER decoder */ - INTEGER_encode_oer, /* Canonical OER encoder */ -#endif /* ASN_DISABLE_OER_SUPPORT */ -#ifdef ASN_DISABLE_PER_SUPPORT - 0, - 0, -#else - INTEGER_decode_uper, /* Unaligned PER decoder */ - INTEGER_encode_uper, /* Unaligned PER encoder */ -#endif /* ASN_DISABLE_PER_SUPPORT */ INTEGER_random_fill, 0 /* Use generic outmost tag fetcher */ }; @@ -578,228 +564,6 @@ INTEGER_encode_xer(const asn_TYPE_descriptor_t *td, const void *sptr, ASN__ENCODED_OK(er); } -#ifndef ASN_DISABLE_PER_SUPPORT - -asn_dec_rval_t -INTEGER_decode_uper(const asn_codec_ctx_t *opt_codec_ctx, - const asn_TYPE_descriptor_t *td, - const asn_per_constraints_t *constraints, void **sptr, - asn_per_data_t *pd) { - const asn_INTEGER_specifics_t *specs = - (const asn_INTEGER_specifics_t *)td->specifics; - asn_dec_rval_t rval = { RC_OK, 0 }; - INTEGER_t *st = (INTEGER_t *)*sptr; - const asn_per_constraint_t *ct; - int repeat; - - (void)opt_codec_ctx; - - if(!st) { - st = (INTEGER_t *)(*sptr = CALLOC(1, sizeof(*st))); - if(!st) ASN__DECODE_FAILED; - } - - if(!constraints) constraints = td->encoding_constraints.per_constraints; - ct = constraints ? &constraints->value : 0; - - if(ct && ct->flags & APC_EXTENSIBLE) { - int inext = per_get_few_bits(pd, 1); - if(inext < 0) ASN__DECODE_STARVED; - if(inext) ct = 0; - } - - FREEMEM(st->buf); - st->buf = 0; - st->size = 0; - if(ct) { - if(ct->flags & APC_SEMI_CONSTRAINED) { - st->buf = (uint8_t *)CALLOC(1, 2); - if(!st->buf) ASN__DECODE_FAILED; - st->size = 1; - } else if(ct->flags & APC_CONSTRAINED && ct->range_bits >= 0) { - size_t size = (ct->range_bits + 7) >> 3; - st->buf = (uint8_t *)MALLOC(1 + size + 1); - if(!st->buf) ASN__DECODE_FAILED; - st->size = size; - } - } - - /* X.691-2008/11, #13.2.2, constrained whole number */ - if(ct && ct->flags != APC_UNCONSTRAINED) { - /* #11.5.6 */ - ASN_DEBUG("Integer with range %d bits", ct->range_bits); - if(ct->range_bits >= 0) { - if((size_t)ct->range_bits > 8 * sizeof(unsigned long)) - ASN__DECODE_FAILED; - - if(specs && specs->field_unsigned) { - unsigned long uvalue = 0; - if(uper_get_constrained_whole_number(pd, - &uvalue, ct->range_bits)) - ASN__DECODE_STARVED; - ASN_DEBUG("Got value %lu + low %ld", - uvalue, ct->lower_bound); - uvalue += ct->lower_bound; - if(asn_ulong2INTEGER(st, uvalue)) - ASN__DECODE_FAILED; - } else { - unsigned long uvalue = 0; - long svalue; - if(uper_get_constrained_whole_number(pd, - &uvalue, ct->range_bits)) - ASN__DECODE_STARVED; - ASN_DEBUG("Got value %lu + low %ld", - uvalue, ct->lower_bound); - if(per_long_range_unrebase(uvalue, ct->lower_bound, - ct->upper_bound, &svalue) - || asn_long2INTEGER(st, svalue)) { - ASN__DECODE_FAILED; - } - } - return rval; - } - } else { - ASN_DEBUG("Decoding unconstrained integer %s", td->name); - } - - /* X.691, #12.2.3, #12.2.4 */ - do { - ssize_t len = 0; - void *p = NULL; - int ret = 0; - - /* Get the PER length */ - len = uper_get_length(pd, -1, 0, &repeat); - if(len < 0) ASN__DECODE_STARVED; - - p = REALLOC(st->buf, st->size + len + 1); - if(!p) ASN__DECODE_FAILED; - st->buf = (uint8_t *)p; - - ret = per_get_many_bits(pd, &st->buf[st->size], 0, 8 * len); - if(ret < 0) ASN__DECODE_STARVED; - st->size += len; - } while(repeat); - st->buf[st->size] = 0; /* JIC */ - - /* #12.2.3 */ - if(ct && ct->lower_bound) { - /* - * TODO (asn1c) replace by in-place arithmetics. - */ - long value = 0; - if(asn_INTEGER2long(st, &value)) - ASN__DECODE_FAILED; - if(asn_imax2INTEGER(st, value + ct->lower_bound)) - ASN__DECODE_FAILED; - } - - return rval; -} - -asn_enc_rval_t -INTEGER_encode_uper(const asn_TYPE_descriptor_t *td, - const asn_per_constraints_t *constraints, const void *sptr, - asn_per_outp_t *po) { - const asn_INTEGER_specifics_t *specs = - (const asn_INTEGER_specifics_t *)td->specifics; - asn_enc_rval_t er; - const INTEGER_t *st = (const INTEGER_t *)sptr; - const uint8_t *buf; - const uint8_t *end; - const asn_per_constraint_t *ct; - long value = 0; - - if(!st || st->size == 0) ASN__ENCODE_FAILED; - - if(!constraints) constraints = td->encoding_constraints.per_constraints; - ct = constraints ? &constraints->value : 0; - - er.encoded = 0; - - if(ct) { - int inext = 0; - if(specs && specs->field_unsigned) { - unsigned long uval; - if(asn_INTEGER2ulong(st, &uval)) - ASN__ENCODE_FAILED; - /* Check proper range */ - if(ct->flags & APC_SEMI_CONSTRAINED) { - if(uval < (unsigned long)ct->lower_bound) - inext = 1; - } else if(ct->range_bits >= 0) { - if(uval < (unsigned long)ct->lower_bound - || uval > (unsigned long)ct->upper_bound) - inext = 1; - } - ASN_DEBUG("Value %lu (%02x/%" ASN_PRI_SIZE ") lb %lu ub %lu %s", - uval, st->buf[0], st->size, - ct->lower_bound, ct->upper_bound, - inext ? "ext" : "fix"); - value = uval; - } else { - if(asn_INTEGER2long(st, &value)) - ASN__ENCODE_FAILED; - /* Check proper range */ - if(ct->flags & APC_SEMI_CONSTRAINED) { - if(value < ct->lower_bound) - inext = 1; - } else if(ct->range_bits >= 0) { - if(value < ct->lower_bound - || value > ct->upper_bound) - inext = 1; - } - ASN_DEBUG("Value %ld (%02x/%" ASN_PRI_SIZE ") lb %ld ub %ld %s", - value, st->buf[0], st->size, - ct->lower_bound, ct->upper_bound, - inext ? "ext" : "fix"); - } - if(ct->flags & APC_EXTENSIBLE) { - if(per_put_few_bits(po, inext, 1)) - ASN__ENCODE_FAILED; - if(inext) ct = 0; - } else if(inext) { - ASN__ENCODE_FAILED; - } - } - - - /* X.691-11/2008, #13.2.2, test if constrained whole number */ - if(ct && ct->range_bits >= 0) { - unsigned long v; - /* #11.5.6 -> #11.3 */ - ASN_DEBUG("Encoding integer %ld (%lu) with range %d bits", - value, value - ct->lower_bound, ct->range_bits); - if(per_long_range_rebase(value, ct->lower_bound, ct->upper_bound, &v)) { - ASN__ENCODE_FAILED; - } - if(uper_put_constrained_whole_number_u(po, v, ct->range_bits)) - ASN__ENCODE_FAILED; - ASN__ENCODED_OK(er); - } - - if(ct && ct->lower_bound) { - ASN_DEBUG("Adjust lower bound to %ld", ct->lower_bound); - /* TODO (asn1c) adjust lower bound */ - ASN__ENCODE_FAILED; - } - - for(buf = st->buf, end = st->buf + st->size; buf < end;) { - int need_eom = 0; - ssize_t mayEncode = uper_put_length(po, end - buf, &need_eom); - if(mayEncode < 0) - ASN__ENCODE_FAILED; - if(per_put_many_bits(po, buf, 8 * mayEncode)) - ASN__ENCODE_FAILED; - buf += mayEncode; - if(need_eom && uper_put_length(po, 0, 0)) ASN__ENCODE_FAILED; - } - - ASN__ENCODED_OK(er); -} - -#endif /* ASN_DISABLE_PER_SUPPORT */ - static intmax_t asn__integer_convert(const uint8_t *b, const uint8_t *end) { uintmax_t value; @@ -1317,8 +1081,6 @@ INTEGER_random_fill(const asn_TYPE_descriptor_t *td, void **sptr, assert(emap_len > 0); value = emap[asn_random_between(0, emap_len - 1)].nat_value; } else { - const asn_per_constraints_t *ct; - static const long variants[] = { -65536, -65535, -65534, -32769, -32768, -32767, -16385, -16384, -16383, -257, -256, -255, -254, -129, -128, -127, @@ -1333,15 +1095,6 @@ INTEGER_random_fill(const asn_TYPE_descriptor_t *td, void **sptr, value = variants[asn_random_between( 0, sizeof(variants) / sizeof(variants[0]) - 1)]; } - - if(!constraints) constraints = &td->encoding_constraints; - ct = constraints ? constraints->per_constraints : 0; - if(ct && (ct->value.flags & APC_CONSTRAINED)) { - if(value < ct->value.lower_bound || value > ct->value.upper_bound) { - value = asn_random_between(ct->value.lower_bound, - ct->value.upper_bound); - } - } } if(asn_imax2INTEGER(st, value)) { diff --git a/src/asn1/asn1c/INTEGER.h b/src/asn1/asn1c/INTEGER.h index 40cc8992..8c48cba4 100644 --- a/src/asn1/asn1c/INTEGER.h +++ b/src/asn1/asn1c/INTEGER.h @@ -43,10 +43,6 @@ asn_struct_compare_f INTEGER_compare; der_type_encoder_f INTEGER_encode_der; xer_type_decoder_f INTEGER_decode_xer; xer_type_encoder_f INTEGER_encode_xer; -oer_type_decoder_f INTEGER_decode_oer; -oer_type_encoder_f INTEGER_encode_oer; -per_type_decoder_f INTEGER_decode_uper; -per_type_encoder_f INTEGER_encode_uper; asn_random_fill_f INTEGER_random_fill; /*********************************** diff --git a/src/asn1/asn1c/INTEGER_oer.c b/src/asn1/asn1c/INTEGER_oer.c deleted file mode 100644 index e0466563..00000000 --- a/src/asn1/asn1c/INTEGER_oer.c +++ /dev/null @@ -1,178 +0,0 @@ -/* - * Copyright (c) 2017 Lev Walkin . - * All rights reserved. - * Redistribution and modifications are permitted subject to BSD license. - */ -#ifndef ASN_DISABLE_OER_SUPPORT - -#include "asn1/asn1c/asn_internal.h" -#include "asn1/asn1c/INTEGER.h" - -asn_dec_rval_t -INTEGER_decode_oer(const asn_codec_ctx_t *opt_codec_ctx, - const asn_TYPE_descriptor_t *td, - const asn_oer_constraints_t *constraints, void **sptr, - const void *ptr, size_t size) { - const asn_INTEGER_specifics_t *specs = - (const asn_INTEGER_specifics_t *)td->specifics; - asn_dec_rval_t rval = {RC_OK, 0}; - INTEGER_t *st = (INTEGER_t *)*sptr; - struct asn_oer_constraint_number_s ct = {0, 0}; - size_t req_bytes; - - (void)opt_codec_ctx; - (void)specs; - - if(!st) { - st = (INTEGER_t *)(*sptr = CALLOC(1, sizeof(*st))); - if(!st) ASN__DECODE_FAILED; - } - - FREEMEM(st->buf); - st->buf = 0; - st->size = 0; - - if(!constraints) constraints = td->encoding_constraints.oer_constraints; - if(constraints) ct = constraints->value; - - if(ct.width) { - req_bytes = ct.width; - } else { - /* No lower bound and no upper bound, effectively */ - - ssize_t consumed = oer_fetch_length(ptr, size, &req_bytes); - if(consumed == 0) { - ASN__DECODE_STARVED; - } else if(consumed == -1) { - ASN__DECODE_FAILED; - } - rval.consumed += consumed; - ptr = (const char *)ptr + consumed; - size -= consumed; - } - - if(req_bytes > size) { - ASN__DECODE_STARVED; - } - - if(ct.positive) { - /* X.969 08/2015 10.2(a) */ - unsigned msb; /* Most significant bit */ - size_t useful_size; - - /* Check most significant bit */ - msb = *(const uint8_t *)ptr >> 7; /* yields 0 or 1 */ - useful_size = msb + req_bytes; - st->buf = (uint8_t *)MALLOC(useful_size + 1); - if(!st->buf) { - ASN__DECODE_FAILED; - } - - /* - * Record a large unsigned in a way not to confuse it - * with signed value. - */ - st->buf[0] = '\0'; - memcpy(st->buf + msb, ptr, req_bytes); - st->buf[useful_size] = '\0'; /* Just in case, 0-terminate */ - st->size = useful_size; - - rval.consumed += req_bytes; - return rval; - } else { - /* X.969 08/2015 10.2(b) */ - st->buf = (uint8_t *)MALLOC(req_bytes + 1); - if(!st->buf) { - ASN__DECODE_FAILED; - } - - memcpy(st->buf, ptr, req_bytes); - st->buf[req_bytes] = '\0'; /* Just in case, 0-terminate */ - st->size = req_bytes; - - rval.consumed += req_bytes; - return rval; - } -} - -/* - * Encode as Canonical OER. - */ -asn_enc_rval_t -INTEGER_encode_oer(const asn_TYPE_descriptor_t *td, - const asn_oer_constraints_t *constraints, const void *sptr, - asn_app_consume_bytes_f *cb, void *app_key) { - const INTEGER_t *st = sptr; - asn_enc_rval_t er; - struct asn_oer_constraint_number_s ct = {0, 0}; - const uint8_t *buf; - const uint8_t *end; - size_t useful_bytes; - size_t req_bytes = 0; - int sign = 0; - - if(!st || st->size == 0) ASN__ENCODE_FAILED; - - if(!constraints) constraints = td->encoding_constraints.oer_constraints; - if(constraints) ct = constraints->value; - - er.encoded = 0; - - buf = st->buf; - end = buf + st->size; - - sign = (buf && buf < end) ? buf[0] & 0x80 : 0; - - /* Ignore 9 leading zeroes or ones */ - if(ct.positive) { - if(sign) { - /* The value given is a signed value. Can't proceed. */ - ASN__ENCODE_FAILED; - } - /* Remove leading zeros. */ - for(; buf + 1 < end; buf++) { - if(buf[0] != 0x0) break; - } - } else { - for(; buf + 1 < end; buf++) { - if(buf[0] == 0x0 && (buf[1] & 0x80) == 0) { - continue; - } else if(buf[0] == 0xff && (buf[1] & 0x80) != 0) { - continue; - } - break; - } - } - - useful_bytes = end - buf; - if(ct.width) { - req_bytes = ct.width; - } else { - ssize_t r = oer_serialize_length(useful_bytes, cb, app_key); - if(r < 0) { - ASN__ENCODE_FAILED; - } - er.encoded += r; - req_bytes = useful_bytes; - } - - if(req_bytes < useful_bytes) { - ASN__ENCODE_FAILED; - } - - er.encoded += req_bytes; - - for(; req_bytes > useful_bytes; req_bytes--) { - if(cb(sign?"\xff":"\0", 1, app_key) < 0) { - ASN__ENCODE_FAILED; - } - } - - if(cb(buf, useful_bytes, app_key) < 0) { - ASN__ENCODE_FAILED; - } - - ASN__ENCODED_OK(er); -} - -#endif /* ASN_DISABLE_OER_SUPPORT */ diff --git a/src/asn1/asn1c/IPAddress.h b/src/asn1/asn1c/IPAddress.h index cc623e01..b7696e19 100644 --- a/src/asn1/asn1c/IPAddress.h +++ b/src/asn1/asn1c/IPAddress.h @@ -30,8 +30,6 @@ ber_type_decoder_f IPAddress_decode_ber; der_type_encoder_f IPAddress_encode_der; xer_type_decoder_f IPAddress_decode_xer; xer_type_encoder_f IPAddress_encode_xer; -oer_type_decoder_f IPAddress_decode_oer; -oer_type_encoder_f IPAddress_encode_oer; #ifdef __cplusplus } diff --git a/src/asn1/asn1c/IPAddressChoice.c b/src/asn1/asn1c/IPAddressChoice.c index 67283e3c..7dda5862 100644 --- a/src/asn1/asn1c/IPAddressChoice.c +++ b/src/asn1/asn1c/IPAddressChoice.c @@ -7,9 +7,6 @@ #include "asn1/asn1c/IPAddressChoice.h" -static asn_oer_constraints_t asn_OER_type_IPAddressChoice_constr_1 CC_NOTUSED = { - { 0, 0 }, - -1}; static asn_TYPE_member_t asn_MBR_addressesOrRanges_3[] = { { ATF_POINTER, 0, 0, -1 /* Ambiguous tag (CHOICE?) */, @@ -77,7 +74,6 @@ asn_CHOICE_specifics_t asn_SPC_IPAddressChoice_specs_1 = { sizeof(((struct IPAddressChoice *)0)->present), asn_MAP_IPAddressChoice_tag2el_1, 2, /* Count of tags in the map */ - 0, 0, -1 /* Extensions start */ }; asn_TYPE_descriptor_t asn_DEF_IPAddressChoice = { @@ -88,7 +84,7 @@ asn_TYPE_descriptor_t asn_DEF_IPAddressChoice = { 0, /* No effective tags (count) */ 0, /* No tags (pointer) */ 0, /* No tags (count) */ - { &asn_OER_type_IPAddressChoice_constr_1, 0, CHOICE_constraint }, + { NULL, 0, CHOICE_constraint }, asn_MBR_IPAddressChoice_1, 2, /* Elements count */ &asn_SPC_IPAddressChoice_specs_1 /* Additional specs */ diff --git a/src/asn1/asn1c/IPAddressFamily.c b/src/asn1/asn1c/IPAddressFamily.c index c85c9cb5..165d4c5d 100644 --- a/src/asn1/asn1c/IPAddressFamily.c +++ b/src/asn1/asn1c/IPAddressFamily.c @@ -33,16 +33,13 @@ memb_addressFamily_constraint_1(const asn_TYPE_descriptor_t *td, const void *spt } } -static asn_oer_constraints_t asn_OER_memb_addressFamily_constr_2 CC_NOTUSED = { - { 0, 0 }, - -1 /* (SIZE(2..3)) */}; asn_TYPE_member_t asn_MBR_IPAddressFamily_1[] = { { ATF_NOFLAGS, 0, offsetof(struct IPAddressFamily, addressFamily), (ASN_TAG_CLASS_UNIVERSAL | (4 << 2)), 0, &asn_DEF_OCTET_STRING, 0, - { &asn_OER_memb_addressFamily_constr_2, 0, memb_addressFamily_constraint_1 }, + { NULL, 0, memb_addressFamily_constraint_1 }, 0, 0, /* No default value */ "addressFamily" }, @@ -69,7 +66,6 @@ asn_SEQUENCE_specifics_t asn_SPC_IPAddressFamily_specs_1 = { offsetof(struct IPAddressFamily, _asn_ctx), asn_MAP_IPAddressFamily_tag2el_1, 3, /* Count of tags in the map */ - 0, 0, 0, /* Optional elements (not needed) */ -1, /* First extension addition */ }; asn_TYPE_descriptor_t asn_DEF_IPAddressFamily = { diff --git a/src/asn1/asn1c/IPAddressOrRange.c b/src/asn1/asn1c/IPAddressOrRange.c index 4ae00612..7ba3e63d 100644 --- a/src/asn1/asn1c/IPAddressOrRange.c +++ b/src/asn1/asn1c/IPAddressOrRange.c @@ -7,9 +7,6 @@ #include "asn1/asn1c/IPAddressOrRange.h" -static asn_oer_constraints_t asn_OER_type_IPAddressOrRange_constr_1 CC_NOTUSED = { - { 0, 0 }, - -1}; asn_TYPE_member_t asn_MBR_IPAddressOrRange_1[] = { { ATF_NOFLAGS, 0, offsetof(struct IPAddressOrRange, choice.addressPrefix), (ASN_TAG_CLASS_UNIVERSAL | (3 << 2)), @@ -41,7 +38,6 @@ asn_CHOICE_specifics_t asn_SPC_IPAddressOrRange_specs_1 = { sizeof(((struct IPAddressOrRange *)0)->present), asn_MAP_IPAddressOrRange_tag2el_1, 2, /* Count of tags in the map */ - 0, 0, -1 /* Extensions start */ }; asn_TYPE_descriptor_t asn_DEF_IPAddressOrRange = { @@ -52,7 +48,7 @@ asn_TYPE_descriptor_t asn_DEF_IPAddressOrRange = { 0, /* No effective tags (count) */ 0, /* No tags (pointer) */ 0, /* No tags (count) */ - { &asn_OER_type_IPAddressOrRange_constr_1, 0, CHOICE_constraint }, + { NULL, 0, CHOICE_constraint }, asn_MBR_IPAddressOrRange_1, 2, /* Elements count */ &asn_SPC_IPAddressOrRange_specs_1 /* Additional specs */ diff --git a/src/asn1/asn1c/IPAddressRange.c b/src/asn1/asn1c/IPAddressRange.c index 97d776cc..46063f9e 100644 --- a/src/asn1/asn1c/IPAddressRange.c +++ b/src/asn1/asn1c/IPAddressRange.c @@ -39,7 +39,6 @@ asn_SEQUENCE_specifics_t asn_SPC_IPAddressRange_specs_1 = { offsetof(struct IPAddressRange, _asn_ctx), asn_MAP_IPAddressRange_tag2el_1, 2, /* Count of tags in the map */ - 0, 0, 0, /* Optional elements (not needed) */ -1, /* First extension addition */ }; asn_TYPE_descriptor_t asn_DEF_IPAddressRange = { diff --git a/src/asn1/asn1c/IssuerAndSerialNumber.c b/src/asn1/asn1c/IssuerAndSerialNumber.c index 6850278f..0b9dbd4a 100644 --- a/src/asn1/asn1c/IssuerAndSerialNumber.c +++ b/src/asn1/asn1c/IssuerAndSerialNumber.c @@ -39,7 +39,6 @@ asn_SEQUENCE_specifics_t asn_SPC_IssuerAndSerialNumber_specs_1 = { offsetof(struct IssuerAndSerialNumber, _asn_ctx), asn_MAP_IssuerAndSerialNumber_tag2el_1, 2, /* Count of tags in the map */ - 0, 0, 0, /* Optional elements (not needed) */ -1, /* First extension addition */ }; asn_TYPE_descriptor_t asn_DEF_IssuerAndSerialNumber = { diff --git a/src/asn1/asn1c/Makefile.include b/src/asn1/asn1c/Makefile.include index ffe856d5..ab011da6 100644 --- a/src/asn1/asn1c/Makefile.include +++ b/src/asn1/asn1c/Makefile.include @@ -164,8 +164,6 @@ ASN_MODULE_HDRS+=asn1/asn1c/asn_internal.h ASN_MODULE_SRCS+=asn1/asn1c/asn_internal.c ASN_MODULE_HDRS+=asn1/asn1c/asn_random_fill.h ASN_MODULE_SRCS+=asn1/asn1c/asn_random_fill.c -ASN_MODULE_HDRS+=asn1/asn1c/asn_bit_data.h -ASN_MODULE_SRCS+=asn1/asn1c/asn_bit_data.c ASN_MODULE_SRCS+=asn1/asn1c/OCTET_STRING.c ASN_MODULE_HDRS+=asn1/asn1c/BIT_STRING.h ASN_MODULE_SRCS+=asn1/asn1c/BIT_STRING.c @@ -188,27 +186,4 @@ ASN_MODULE_SRCS+=asn1/asn1c/xer_support.c ASN_MODULE_HDRS+=asn1/asn1c/xer_decoder.h ASN_MODULE_SRCS+=asn1/asn1c/xer_decoder.c ASN_MODULE_HDRS+=asn1/asn1c/xer_encoder.h -ASN_MODULE_SRCS+=asn1/asn1c/xer_encoder.c -ASN_MODULE_HDRS+=asn1/asn1c/per_support.h -ASN_MODULE_SRCS+=asn1/asn1c/per_support.c -ASN_MODULE_HDRS+=asn1/asn1c/per_decoder.h -ASN_MODULE_SRCS+=asn1/asn1c/per_decoder.c -ASN_MODULE_HDRS+=asn1/asn1c/per_encoder.h -ASN_MODULE_SRCS+=asn1/asn1c/per_encoder.c -ASN_MODULE_HDRS+=asn1/asn1c/per_opentype.h -ASN_MODULE_SRCS+=asn1/asn1c/per_opentype.c -ASN_MODULE_HDRS+=asn1/asn1c/oer_decoder.h -ASN_MODULE_HDRS+=asn1/asn1c/oer_encoder.h -ASN_MODULE_HDRS+=asn1/asn1c/oer_support.h -ASN_MODULE_SRCS+=asn1/asn1c/oer_decoder.c -ASN_MODULE_SRCS+=asn1/asn1c/oer_encoder.c -ASN_MODULE_SRCS+=asn1/asn1c/oer_support.c -ASN_MODULE_SRCS+=asn1/asn1c/OPEN_TYPE_oer.c -ASN_MODULE_SRCS+=asn1/asn1c/INTEGER_oer.c -ASN_MODULE_SRCS+=asn1/asn1c/BIT_STRING_oer.c -ASN_MODULE_SRCS+=asn1/asn1c/OCTET_STRING_oer.c -ASN_MODULE_SRCS+=asn1/asn1c/constr_CHOICE_oer.c -ASN_MODULE_SRCS+=asn1/asn1c/constr_SEQUENCE_oer.c -ASN_MODULE_SRCS+=asn1/asn1c/constr_SET_OF_oer.c - -ASN_MODULE_CFLAGS=-DASN_DISABLE_PER_SUPPORT +ASN_MODULE_SRCS+=asn1/asn1c/xer_encoder.c \ No newline at end of file diff --git a/src/asn1/asn1c/Manifest.c b/src/asn1/asn1c/Manifest.c index be63c346..0d591121 100644 --- a/src/asn1/asn1c/Manifest.c +++ b/src/asn1/asn1c/Manifest.c @@ -53,15 +53,6 @@ memb_fileList_constraint_1(const asn_TYPE_descriptor_t *td, const void *sptr, return td->encoding_constraints.general_constraints(td, sptr, ctfailcb, app_key); } -static asn_oer_constraints_t asn_OER_type_fileList_constr_7 CC_NOTUSED = { - { 0, 0 }, - -1 /* (SIZE(0..MAX)) */}; -static asn_oer_constraints_t asn_OER_memb_manifestNumber_constr_3 CC_NOTUSED = { - { 0, 1 } /* (0..MAX) */, - -1}; -static asn_oer_constraints_t asn_OER_memb_fileList_constr_7 CC_NOTUSED = { - { 0, 0 }, - -1 /* (SIZE(0..MAX)) */}; static int asn_DFL_2_cmp_0(const void *sptr) { const INTEGER_t *st = sptr; @@ -116,7 +107,7 @@ asn_TYPE_descriptor_t asn_DEF_fileList_7 = { asn_DEF_fileList_tags_7, /* Same as above */ sizeof(asn_DEF_fileList_tags_7) /sizeof(asn_DEF_fileList_tags_7[0]), /* 1 */ - { &asn_OER_type_fileList_constr_7, 0, SEQUENCE_OF_constraint }, + { NULL, 0, SEQUENCE_OF_constraint }, asn_MBR_fileList_7, 1, /* Single element */ &asn_SPC_fileList_specs_7 /* Additional specs */ @@ -138,7 +129,7 @@ static asn_TYPE_member_t asn_MBR_Manifest_1[] = { 0, &asn_DEF_INTEGER, 0, - { &asn_OER_memb_manifestNumber_constr_3, 0, memb_manifestNumber_constraint_1 }, + { NULL, 0, memb_manifestNumber_constraint_1 }, 0, 0, /* No default value */ "manifestNumber" }, @@ -174,12 +165,11 @@ static asn_TYPE_member_t asn_MBR_Manifest_1[] = { 0, &asn_DEF_fileList_7, 0, - { &asn_OER_memb_fileList_constr_7, 0, memb_fileList_constraint_1 }, + { NULL, 0, memb_fileList_constraint_1 }, 0, 0, /* No default value */ "fileList" }, }; -static const int asn_MAP_Manifest_oms_1[] = { 0 }; static const ber_tlv_tag_t asn_DEF_Manifest_tags_1[] = { (ASN_TAG_CLASS_UNIVERSAL | (16 << 2)) }; @@ -196,8 +186,6 @@ static asn_SEQUENCE_specifics_t asn_SPC_Manifest_specs_1 = { offsetof(struct Manifest, _asn_ctx), asn_MAP_Manifest_tag2el_1, 6, /* Count of tags in the map */ - asn_MAP_Manifest_oms_1, /* Optional members */ - 1, 0, /* Root/Additions */ -1, /* First extension addition */ }; asn_TYPE_descriptor_t asn_DEF_Manifest = { diff --git a/src/asn1/asn1c/MessageDigest.h b/src/asn1/asn1c/MessageDigest.h index a4ae8151..2d55b85e 100644 --- a/src/asn1/asn1c/MessageDigest.h +++ b/src/asn1/asn1c/MessageDigest.h @@ -30,8 +30,6 @@ ber_type_decoder_f MessageDigest_decode_ber; der_type_encoder_f MessageDigest_encode_der; xer_type_decoder_f MessageDigest_decode_xer; xer_type_encoder_f MessageDigest_encode_xer; -oer_type_decoder_f MessageDigest_decode_oer; -oer_type_encoder_f MessageDigest_encode_oer; #ifdef __cplusplus } diff --git a/src/asn1/asn1c/NULL.c b/src/asn1/asn1c/NULL.c index 1aa7bb28..bf5e9850 100644 --- a/src/asn1/asn1c/NULL.c +++ b/src/asn1/asn1c/NULL.c @@ -20,20 +20,6 @@ asn_TYPE_operation_t asn_OP_NULL = { NULL_encode_der, /* Special handling of DER encoding */ NULL_decode_xer, NULL_encode_xer, -#ifdef ASN_DISABLE_OER_SUPPORT - 0, - 0, -#else - NULL_decode_oer, - NULL_encode_oer, -#endif /* ASN_DISABLE_OER_SUPPORT */ -#ifdef ASN_DISABLE_PER_SUPPORT - 0, - 0, -#else - NULL_decode_uper, /* Unaligned PER decoder */ - NULL_encode_uper, /* Unaligned PER encoder */ -#endif /* ASN_DISABLE_PER_SUPPORT */ NULL_random_fill, 0 /* Use generic outmost tag fetcher */ }; @@ -188,100 +174,6 @@ NULL_print(const asn_TYPE_descriptor_t *td, const void *sptr, int ilevel, } } -#ifndef ASN_DISABLE_OER_SUPPORT - -asn_dec_rval_t -NULL_decode_oer(const asn_codec_ctx_t *opt_codec_ctx, - const asn_TYPE_descriptor_t *td, - const asn_oer_constraints_t *constraints, void **sptr, - const void *ptr, size_t size) { - asn_dec_rval_t rv = {RC_OK, 0}; - (void)opt_codec_ctx; - (void)td; - (void)constraints; - (void)ptr; - (void)size; - - if(!*sptr) { - *sptr = MALLOC(sizeof(NULL_t)); - if(*sptr) { - *(NULL_t *)*sptr = 0; - } else { - ASN__DECODE_FAILED; - } - } - - return rv; -} - -asn_enc_rval_t -NULL_encode_oer(const asn_TYPE_descriptor_t *td, - const asn_oer_constraints_t *constraints, const void *sptr, - asn_app_consume_bytes_f *cb, void *app_key) { - asn_enc_rval_t er; - - (void)td; - (void)sptr; - (void)constraints; - (void)cb; - (void)app_key; - - er.encoded = 0; /* Encoding in 0 bytes. */ - - ASN__ENCODED_OK(er); -} - -#endif /* ASN_DISABLE_OER_SUPPORT */ - -#ifndef ASN_DISABLE_PER_SUPPORT - -asn_dec_rval_t -NULL_decode_uper(const asn_codec_ctx_t *opt_codec_ctx, - const asn_TYPE_descriptor_t *td, - const asn_per_constraints_t *constraints, void **sptr, - asn_per_data_t *pd) { - asn_dec_rval_t rv; - - (void)opt_codec_ctx; - (void)td; - (void)constraints; - (void)pd; - - if(!*sptr) { - *sptr = MALLOC(sizeof(NULL_t)); - if(*sptr) { - *(NULL_t *)*sptr = 0; - } else { - ASN__DECODE_FAILED; - } - } - - /* - * NULL type does not have content octets. - */ - - rv.code = RC_OK; - rv.consumed = 0; - return rv; -} - -asn_enc_rval_t -NULL_encode_uper(const asn_TYPE_descriptor_t *td, - const asn_per_constraints_t *constraints, const void *sptr, - asn_per_outp_t *po) { - asn_enc_rval_t er; - - (void)td; - (void)constraints; - (void)sptr; - (void)po; - - er.encoded = 0; - ASN__ENCODED_OK(er); -} - -#endif /* ASN_DISABLE_PER_SUPPORT */ - asn_random_fill_result_t NULL_random_fill(const asn_TYPE_descriptor_t *td, void **sptr, const asn_encoding_constraints_t *constr, diff --git a/src/asn1/asn1c/NULL.h b/src/asn1/asn1c/NULL.h index 6153e2d4..460a2289 100644 --- a/src/asn1/asn1c/NULL.h +++ b/src/asn1/asn1c/NULL.h @@ -27,10 +27,6 @@ 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; -oer_type_decoder_f NULL_decode_oer; -oer_type_encoder_f NULL_encode_oer; -per_type_decoder_f NULL_decode_uper; -per_type_encoder_f NULL_encode_uper; asn_random_fill_f NULL_random_fill; #define NULL_constraint asn_generic_no_constraint diff --git a/src/asn1/asn1c/Name.c b/src/asn1/asn1c/Name.c index e8525d8f..38a0daa0 100644 --- a/src/asn1/asn1c/Name.c +++ b/src/asn1/asn1c/Name.c @@ -7,9 +7,6 @@ #include "asn1/asn1c/Name.h" -static asn_oer_constraints_t asn_OER_type_Name_constr_1 CC_NOTUSED = { - { 0, 0 }, - -1}; asn_TYPE_member_t asn_MBR_Name_1[] = { { ATF_NOFLAGS, 0, offsetof(struct Name, choice.rdnSequence), (ASN_TAG_CLASS_UNIVERSAL | (16 << 2)), @@ -31,7 +28,6 @@ asn_CHOICE_specifics_t asn_SPC_Name_specs_1 = { sizeof(((struct Name *)0)->present), asn_MAP_Name_tag2el_1, 1, /* Count of tags in the map */ - 0, 0, -1 /* Extensions start */ }; asn_TYPE_descriptor_t asn_DEF_Name = { @@ -42,7 +38,7 @@ asn_TYPE_descriptor_t asn_DEF_Name = { 0, /* No effective tags (count) */ 0, /* No tags (pointer) */ 0, /* No tags (count) */ - { &asn_OER_type_Name_constr_1, 0, CHOICE_constraint }, + { NULL, 0, CHOICE_constraint }, asn_MBR_Name_1, 1, /* Elements count */ &asn_SPC_Name_specs_1 /* Additional specs */ diff --git a/src/asn1/asn1c/OBJECT_IDENTIFIER.c b/src/asn1/asn1c/OBJECT_IDENTIFIER.c index a94b81f9..ac2abf37 100644 --- a/src/asn1/asn1c/OBJECT_IDENTIFIER.c +++ b/src/asn1/asn1c/OBJECT_IDENTIFIER.c @@ -24,20 +24,6 @@ asn_TYPE_operation_t asn_OP_OBJECT_IDENTIFIER = { der_encode_primitive, OBJECT_IDENTIFIER_decode_xer, OBJECT_IDENTIFIER_encode_xer, -#ifdef ASN_DISABLE_OER_SUPPORT - 0, - 0, -#else - OBJECT_IDENTIFIER_decode_oer, - OBJECT_IDENTIFIER_encode_oer, -#endif /* ASN_DISABLE_OER_SUPPORT */ -#ifdef ASN_DISABLE_PER_SUPPORT - 0, - 0, -#else - OCTET_STRING_decode_uper, - OCTET_STRING_encode_uper, -#endif /* ASN_DISABLE_PER_SUPPORT */ OBJECT_IDENTIFIER_random_fill, 0 /* Use generic outmost tag fetcher */ }; diff --git a/src/asn1/asn1c/OBJECT_IDENTIFIER.h b/src/asn1/asn1c/OBJECT_IDENTIFIER.h index c5cf94b5..bbcb1573 100644 --- a/src/asn1/asn1c/OBJECT_IDENTIFIER.h +++ b/src/asn1/asn1c/OBJECT_IDENTIFIER.h @@ -32,10 +32,6 @@ asn_random_fill_f OBJECT_IDENTIFIER_random_fill; #define OBJECT_IDENTIFIER_compare OCTET_STRING_compare #define OBJECT_IDENTIFIER_decode_ber ber_decode_primitive #define OBJECT_IDENTIFIER_encode_der der_encode_primitive -#define OBJECT_IDENTIFIER_decode_oer oer_decode_primitive -#define OBJECT_IDENTIFIER_encode_oer oer_encode_primitive -#define OBJECT_IDENTIFIER_decode_uper OCTET_STRING_decode_uper -#define OBJECT_IDENTIFIER_encode_uper OCTET_STRING_encode_uper /********************************** * Some handy conversion routines * diff --git a/src/asn1/asn1c/OCTET_STRING.c b/src/asn1/asn1c/OCTET_STRING.c index ffbf40b5..6ae6e230 100644 --- a/src/asn1/asn1c/OCTET_STRING.c +++ b/src/asn1/asn1c/OCTET_STRING.c @@ -29,20 +29,6 @@ asn_TYPE_operation_t asn_OP_OCTET_STRING = { OCTET_STRING_encode_der, OCTET_STRING_decode_xer_hex, OCTET_STRING_encode_xer, -#ifdef ASN_DISABLE_OER_SUPPORT - 0, - 0, -#else - OCTET_STRING_decode_oer, - OCTET_STRING_encode_oer, -#endif /* ASN_DISABLE_OER_SUPPORT */ -#ifdef ASN_DISABLE_PER_SUPPORT - 0, - 0, -#else - OCTET_STRING_decode_uper, /* Unaligned PER decoder */ - OCTET_STRING_encode_uper, /* Unaligned PER encoder */ -#endif /* ASN_DISABLE_PER_SUPPORT */ OCTET_STRING_random_fill, 0 /* Use generic outmost tag fetcher */ }; @@ -1210,442 +1196,6 @@ OCTET_STRING_decode_xer_utf8(const asn_codec_ctx_t *opt_codec_ctx, OCTET_STRING__convert_entrefs); } -#ifndef ASN_DISABLE_PER_SUPPORT - -static int -OCTET_STRING_per_get_characters(asn_per_data_t *po, uint8_t *buf, - size_t units, unsigned int bpc, unsigned int unit_bits, - long lb, long ub, const asn_per_constraints_t *pc) { - uint8_t *end = buf + units * bpc; - - ASN_DEBUG("Expanding %d characters into (%ld..%ld):%d", - (int)units, lb, ub, unit_bits); - - /* X.691: 27.5.4 */ - if((unsigned long)ub <= ((unsigned long)2 << (unit_bits - 1))) { - /* Decode without translation */ - lb = 0; - } else if(pc && pc->code2value) { - if(unit_bits > 16) - return 1; /* FATAL: can't have constrained - * UniversalString with more than - * 16 million code points */ - for(; buf < end; buf += bpc) { - int value; - int code = per_get_few_bits(po, unit_bits); - if(code < 0) return -1; /* WMORE */ - value = pc->code2value(code); - if(value < 0) { - ASN_DEBUG("Code %d (0x%02x) is" - " not in map (%ld..%ld)", - code, code, lb, ub); - return 1; /* FATAL */ - } - switch(bpc) { - case 1: *buf = value; break; - case 2: buf[0] = value >> 8; buf[1] = value; break; - case 4: buf[0] = value >> 24; buf[1] = value >> 16; - buf[2] = value >> 8; buf[3] = value; break; - } - } - return 0; - } - - /* Shortcut the no-op copying to the aligned structure */ - if(lb == 0 && (unit_bits == 8 * bpc)) { - return per_get_many_bits(po, buf, 0, unit_bits * units); - } - - for(; buf < end; buf += bpc) { - int32_t code = per_get_few_bits(po, unit_bits); - int32_t ch = code + lb; - if(code < 0) return -1; /* WMORE */ - if(ch > ub) { - ASN_DEBUG("Code %d is out of range (%ld..%ld)", - ch, lb, ub); - return 1; /* FATAL */ - } - switch(bpc) { - case 1: *buf = ch; break; - case 2: buf[0] = ch >> 8; buf[1] = ch; break; - case 4: buf[0] = ch >> 24; buf[1] = ch >> 16; - buf[2] = ch >> 8; buf[3] = ch; break; - } - } - - return 0; -} - -static int -OCTET_STRING_per_put_characters(asn_per_outp_t *po, const uint8_t *buf, - size_t units, unsigned int bpc, unsigned int unit_bits, - long lb, long ub, const asn_per_constraints_t *pc) { - const uint8_t *end = buf + units * bpc; - - ASN_DEBUG("Squeezing %d characters into (%ld..%ld):%d (%d bpc)", - (int)units, lb, ub, unit_bits, bpc); - - /* X.691: 27.5.4 */ - if((unsigned long)ub <= ((unsigned long)2 << (unit_bits - 1))) { - /* Encode as is */ - lb = 0; - } else if(pc && pc->value2code) { - for(; buf < end; buf += bpc) { - int code; - uint32_t value; - switch(bpc) { - case 1: value = *(const uint8_t *)buf; break; - case 2: value = (buf[0] << 8) | buf[1]; break; - case 4: value = (buf[0] << 24) | (buf[1] << 16) - | (buf[2] << 8) | buf[3]; break; - default: return -1; - } - code = pc->value2code(value); - if(code < 0) { - ASN_DEBUG("Character %d (0x%02x) is" - " not in map (%ld..%ld)", - *buf, *buf, lb, ub); - return -1; - } - if(per_put_few_bits(po, code, unit_bits)) - return -1; - } - } - - /* Shortcut the no-op copying to the aligned structure */ - if(lb == 0 && (unit_bits == 8 * bpc)) { - return per_put_many_bits(po, buf, unit_bits * units); - } - - for(ub -= lb; buf < end; buf += bpc) { - int ch; - uint32_t value; - switch(bpc) { - case 1: - value = *(const uint8_t *)buf; - break; - case 2: - value = (buf[0] << 8) | buf[1]; - break; - case 4: - value = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]; - break; - default: - return -1; - } - ch = value - lb; - if(ch < 0 || ch > ub) { - ASN_DEBUG("Character %d (0x%02x) is out of range (%ld..%ld)", *buf, - value, lb, ub + lb); - return -1; - } - if(per_put_few_bits(po, ch, unit_bits)) return -1; - } - - return 0; -} - -static asn_per_constraints_t asn_DEF_OCTET_STRING_constraints = { - { APC_CONSTRAINED, 8, 8, 0, 255 }, - { APC_SEMI_CONSTRAINED, -1, -1, 0, 0 }, - 0, 0 -}; - -asn_dec_rval_t -OCTET_STRING_decode_uper(const asn_codec_ctx_t *opt_codec_ctx, - const asn_TYPE_descriptor_t *td, - const asn_per_constraints_t *constraints, void **sptr, - asn_per_data_t *pd) { - const asn_OCTET_STRING_specifics_t *specs = td->specifics - ? (const asn_OCTET_STRING_specifics_t *)td->specifics - : &asn_SPC_OCTET_STRING_specs; - const asn_per_constraints_t *pc = - constraints ? constraints : td->encoding_constraints.per_constraints; - const asn_per_constraint_t *cval; - const asn_per_constraint_t *csiz; - asn_dec_rval_t rval = { RC_OK, 0 }; - OCTET_STRING_t *st = (OCTET_STRING_t *)*sptr; - ssize_t consumed_myself = 0; - int repeat; - enum { - OS__BPC_CHAR = 1, - OS__BPC_U16 = 2, - OS__BPC_U32 = 4 - } bpc; /* Bytes per character */ - unsigned int unit_bits; - unsigned int canonical_unit_bits; - - (void)opt_codec_ctx; - - if(pc) { - cval = &pc->value; - csiz = &pc->size; - } else { - cval = &asn_DEF_OCTET_STRING_constraints.value; - csiz = &asn_DEF_OCTET_STRING_constraints.size; - } - - switch(specs->subvariant) { - default: - case ASN_OSUBV_ANY: - case ASN_OSUBV_BIT: - ASN_DEBUG("Unrecognized subvariant %d", specs->subvariant); - RETURN(RC_FAIL); - break; - case ASN_OSUBV_STR: - canonical_unit_bits = unit_bits = 8; - if(cval->flags & APC_CONSTRAINED) - unit_bits = cval->range_bits; - bpc = OS__BPC_CHAR; - break; - case ASN_OSUBV_U16: - canonical_unit_bits = unit_bits = 16; - if(cval->flags & APC_CONSTRAINED) - unit_bits = cval->range_bits; - bpc = OS__BPC_U16; - break; - case ASN_OSUBV_U32: - canonical_unit_bits = unit_bits = 32; - if(cval->flags & APC_CONSTRAINED) - unit_bits = cval->range_bits; - bpc = OS__BPC_U32; - break; - } - - /* - * Allocate the string. - */ - if(!st) { - st = (OCTET_STRING_t *)(*sptr = CALLOC(1, specs->struct_size)); - if(!st) RETURN(RC_FAIL); - } - - ASN_DEBUG("PER Decoding %s size %ld .. %ld bits %d", - csiz->flags & APC_EXTENSIBLE ? "extensible" : "non-extensible", - csiz->lower_bound, csiz->upper_bound, csiz->effective_bits); - - if(csiz->flags & APC_EXTENSIBLE) { - int inext = per_get_few_bits(pd, 1); - if(inext < 0) RETURN(RC_WMORE); - if(inext) { - csiz = &asn_DEF_OCTET_STRING_constraints.size; - unit_bits = canonical_unit_bits; - } - } - - if(csiz->effective_bits >= 0) { - FREEMEM(st->buf); - if(bpc) { - st->size = csiz->upper_bound * bpc; - } else { - st->size = (csiz->upper_bound + 7) >> 3; - } - st->buf = (uint8_t *)MALLOC(st->size + 1); - if(!st->buf) { st->size = 0; RETURN(RC_FAIL); } - } - - /* X.691, #16.5: zero-length encoding */ - /* X.691, #16.6: short fixed length encoding (up to 2 octets) */ - /* X.691, #16.7: long fixed length encoding (up to 64K octets) */ - if(csiz->effective_bits == 0) { - int ret; - if(bpc) { - ASN_DEBUG("Encoding OCTET STRING size %ld", - csiz->upper_bound); - ret = OCTET_STRING_per_get_characters(pd, st->buf, - csiz->upper_bound, bpc, unit_bits, - cval->lower_bound, cval->upper_bound, pc); - if(ret > 0) RETURN(RC_FAIL); - } else { - ASN_DEBUG("Encoding BIT STRING size %ld", - csiz->upper_bound); - ret = per_get_many_bits(pd, st->buf, 0, - unit_bits * csiz->upper_bound); - } - if(ret < 0) RETURN(RC_WMORE); - consumed_myself += unit_bits * csiz->upper_bound; - st->buf[st->size] = 0; - RETURN(RC_OK); - } - - st->size = 0; - do { - ssize_t raw_len; - ssize_t len_bytes; - void *p; - int ret; - - /* Get the PER length */ - raw_len = uper_get_length(pd, csiz->effective_bits, csiz->lower_bound, - &repeat); - if(raw_len < 0) RETURN(RC_WMORE); - if(raw_len == 0 && st->buf) break; - - ASN_DEBUG("Got PER length eb %ld, len %ld, %s (%s)", - (long)csiz->effective_bits, (long)raw_len, - repeat ? "repeat" : "once", td->name); - len_bytes = raw_len * bpc; - p = REALLOC(st->buf, st->size + len_bytes + 1); - if(!p) RETURN(RC_FAIL); - st->buf = (uint8_t *)p; - - ret = OCTET_STRING_per_get_characters(pd, &st->buf[st->size], raw_len, - bpc, unit_bits, cval->lower_bound, - cval->upper_bound, pc); - if(ret > 0) RETURN(RC_FAIL); - if(ret < 0) RETURN(RC_WMORE); - st->size += len_bytes; - } while(repeat); - st->buf[st->size] = 0; /* nul-terminate */ - - return rval; -} - -asn_enc_rval_t -OCTET_STRING_encode_uper(const asn_TYPE_descriptor_t *td, - const asn_per_constraints_t *constraints, - const void *sptr, asn_per_outp_t *po) { - const asn_OCTET_STRING_specifics_t *specs = td->specifics - ? (const asn_OCTET_STRING_specifics_t *)td->specifics - : &asn_SPC_OCTET_STRING_specs; - const asn_per_constraints_t *pc = constraints ? constraints - : td->encoding_constraints.per_constraints; - const asn_per_constraint_t *cval; - const asn_per_constraint_t *csiz; - const OCTET_STRING_t *st = (const OCTET_STRING_t *)sptr; - asn_enc_rval_t er = { 0, 0, 0 }; - int inext = 0; /* Lies not within extension root */ - unsigned int unit_bits; - unsigned int canonical_unit_bits; - size_t size_in_units; - const uint8_t *buf; - int ret; - enum { - OS__BPC_CHAR = 1, - OS__BPC_U16 = 2, - OS__BPC_U32 = 4 - } bpc; /* Bytes per character */ - int ct_extensible; - - if(!st || (!st->buf && st->size)) - ASN__ENCODE_FAILED; - - if(pc) { - cval = &pc->value; - csiz = &pc->size; - } else { - cval = &asn_DEF_OCTET_STRING_constraints.value; - csiz = &asn_DEF_OCTET_STRING_constraints.size; - } - ct_extensible = csiz->flags & APC_EXTENSIBLE; - - switch(specs->subvariant) { - default: - case ASN_OSUBV_ANY: - case ASN_OSUBV_BIT: - ASN__ENCODE_FAILED; - case ASN_OSUBV_STR: - canonical_unit_bits = unit_bits = 8; - if(cval->flags & APC_CONSTRAINED) - unit_bits = cval->range_bits; - bpc = OS__BPC_CHAR; - size_in_units = st->size; - break; - case ASN_OSUBV_U16: - canonical_unit_bits = unit_bits = 16; - if(cval->flags & APC_CONSTRAINED) - unit_bits = cval->range_bits; - bpc = OS__BPC_U16; - size_in_units = st->size >> 1; - if(st->size & 1) { - ASN_DEBUG("%s string size is not modulo 2", td->name); - ASN__ENCODE_FAILED; - } - break; - case ASN_OSUBV_U32: - canonical_unit_bits = unit_bits = 32; - if(cval->flags & APC_CONSTRAINED) - unit_bits = cval->range_bits; - bpc = OS__BPC_U32; - size_in_units = st->size >> 2; - if(st->size & 3) { - ASN_DEBUG("%s string size is not modulo 4", td->name); - ASN__ENCODE_FAILED; - } - break; - } - - ASN_DEBUG("Encoding %s into %" ASN_PRI_SIZE " units of %d bits" - " (%ld..%ld, effective %d)%s", - td->name, size_in_units, unit_bits, - csiz->lower_bound, csiz->upper_bound, - csiz->effective_bits, ct_extensible ? " EXT" : ""); - - /* Figure out whether size lies within PER visible constraint */ - - if(csiz->effective_bits >= 0) { - if((ssize_t)size_in_units < csiz->lower_bound - || (ssize_t)size_in_units > csiz->upper_bound) { - if(ct_extensible) { - csiz = &asn_DEF_OCTET_STRING_constraints.size; - unit_bits = canonical_unit_bits; - inext = 1; - } else { - ASN__ENCODE_FAILED; - } - } - } else { - inext = 0; - } - - if(ct_extensible) { - /* Declare whether length is [not] within extension root */ - if(per_put_few_bits(po, inext, 1)) - ASN__ENCODE_FAILED; - } - - if(csiz->effective_bits >= 0 && !inext) { - ASN_DEBUG("Encoding %" ASN_PRI_SIZE " bytes (%ld), length in %d bits", st->size, - size_in_units - csiz->lower_bound, csiz->effective_bits); - ret = per_put_few_bits(po, size_in_units - csiz->lower_bound, - csiz->effective_bits); - if(ret) ASN__ENCODE_FAILED; - ret = OCTET_STRING_per_put_characters(po, st->buf, size_in_units, bpc, - unit_bits, cval->lower_bound, - cval->upper_bound, pc); - if(ret) ASN__ENCODE_FAILED; - ASN__ENCODED_OK(er); - } - - ASN_DEBUG("Encoding %" ASN_PRI_SIZE " bytes", st->size); - - buf = st->buf; - ASN_DEBUG("Encoding %" ASN_PRI_SIZE " in units", size_in_units); - do { - int need_eom = 0; - ssize_t may_save = uper_put_length(po, size_in_units, &need_eom); - if(may_save < 0) ASN__ENCODE_FAILED; - - ASN_DEBUG("Encoding %" ASN_PRI_SSIZE " of %" ASN_PRI_SIZE "%s", may_save, size_in_units, - need_eom ? ",+EOM" : ""); - - ret = OCTET_STRING_per_put_characters(po, buf, may_save, bpc, unit_bits, - cval->lower_bound, - cval->upper_bound, pc); - if(ret) ASN__ENCODE_FAILED; - - buf += may_save * bpc; - size_in_units -= may_save; - assert(!(may_save & 0x07) || !size_in_units); - if(need_eom && uper_put_length(po, 0, 0)) - ASN__ENCODE_FAILED; /* End of Message length */ - } while(size_in_units); - - ASN__ENCODED_OK(er); -} - -#endif /* ASN_DISABLE_PER_SUPPORT */ - int OCTET_STRING_print(const asn_TYPE_descriptor_t *td, const void *sptr, int ilevel, asn_app_consume_bytes_f *cb, void *app_key) { @@ -1887,46 +1437,7 @@ OCTET_STRING_random_length_constrained( rnd_len = lengths[asn_random_between( 0, sizeof(lengths) / sizeof(lengths[0]) - 1)]; - if(!constraints || !constraints->per_constraints) - constraints = &td->encoding_constraints; - if(constraints->per_constraints) { - const asn_per_constraint_t *pc = &constraints->per_constraints->size; - if(pc->flags & APC_CONSTRAINED) { - long suggested_upper_bound = pc->upper_bound < (ssize_t)max_length - ? pc->upper_bound - : (ssize_t)max_length; - if(max_length <= (size_t)pc->lower_bound) { - return pc->lower_bound; - } - if(pc->flags & APC_EXTENSIBLE) { - switch(asn_random_between(0, 5)) { - case 0: - if(pc->lower_bound > 0) { - rnd_len = pc->lower_bound - 1; - break; - } - /* Fall through */ - case 1: - rnd_len = pc->upper_bound + 1; - break; - case 2: - /* Keep rnd_len from the table */ - if(rnd_len <= max_length) { - break; - } - /* Fall through */ - default: - rnd_len = asn_random_between(pc->lower_bound, - suggested_upper_bound); - } - } else { - rnd_len = - asn_random_between(pc->lower_bound, suggested_upper_bound); - } - } else { - rnd_len = asn_random_between(0, max_length); - } - } else if(rnd_len > max_length) { + if(rnd_len > max_length) { rnd_len = asn_random_between(0, max_length); } @@ -1978,17 +1489,8 @@ OCTET_STRING_random_fill(const asn_TYPE_descriptor_t *td, void **sptr, break; } - if(!constraints || !constraints->per_constraints) + if(!constraints) constraints = &td->encoding_constraints; - if(constraints->per_constraints) { - const asn_per_constraint_t *pc = &constraints->per_constraints->value; - if(pc->flags & APC_SEMI_CONSTRAINED) { - clb = pc->lower_bound; - } else if(pc->flags & APC_CONSTRAINED) { - clb = pc->lower_bound; - cub = pc->upper_bound; - } - } rnd_len = OCTET_STRING_random_length_constrained(td, constraints, max_length); diff --git a/src/asn1/asn1c/OCTET_STRING.h b/src/asn1/asn1c/OCTET_STRING.h index 15d8f645..2b5ce0a1 100644 --- a/src/asn1/asn1c/OCTET_STRING.h +++ b/src/asn1/asn1c/OCTET_STRING.h @@ -40,10 +40,6 @@ xer_type_decoder_f OCTET_STRING_decode_xer_binary; /* 01010111010 */ xer_type_decoder_f OCTET_STRING_decode_xer_utf8; /* ASCII/UTF-8 */ xer_type_encoder_f OCTET_STRING_encode_xer; xer_type_encoder_f OCTET_STRING_encode_xer_utf8; -oer_type_decoder_f OCTET_STRING_decode_oer; -oer_type_encoder_f OCTET_STRING_encode_oer; -per_type_decoder_f OCTET_STRING_decode_uper; -per_type_encoder_f OCTET_STRING_encode_uper; asn_random_fill_f OCTET_STRING_random_fill; #define OCTET_STRING_constraint asn_generic_no_constraint diff --git a/src/asn1/asn1c/OCTET_STRING_oer.c b/src/asn1/asn1c/OCTET_STRING_oer.c deleted file mode 100644 index 7f917c90..00000000 --- a/src/asn1/asn1c/OCTET_STRING_oer.c +++ /dev/null @@ -1,170 +0,0 @@ -/* - * Copyright (c) 2017 Lev Walkin . - * All rights reserved. - * Redistribution and modifications are permitted subject to BSD license. - */ -#ifndef ASN_DISABLE_OER_SUPPORT - -#include "asn1/asn1c/asn_internal.h" -#include "asn1/asn1c/OCTET_STRING.h" - -asn_dec_rval_t -OCTET_STRING_decode_oer(const asn_codec_ctx_t *opt_codec_ctx, - const asn_TYPE_descriptor_t *td, - const asn_oer_constraints_t *constraints, void **sptr, - const void *ptr, size_t size) { - const asn_OCTET_STRING_specifics_t *specs = - td->specifics ? (const asn_OCTET_STRING_specifics_t *)td->specifics - : &asn_SPC_OCTET_STRING_specs; - OCTET_STRING_t *st = (OCTET_STRING_t *)*sptr; - const asn_oer_constraints_t *cts = - constraints ? constraints : td->encoding_constraints.oer_constraints; - ssize_t ct_size = cts ? cts->size : -1; - asn_dec_rval_t rval = {RC_OK, 0}; - size_t expected_length = 0; - - size_t unit_bytes; - switch(specs->subvariant) { - default: - case ASN_OSUBV_BIT: - ASN_DEBUG("Invalid use of OCTET STRING to decode BIT STRING"); - ASN__DECODE_FAILED; - case ASN_OSUBV_ANY: - /* Fall through */ - case ASN_OSUBV_STR: - unit_bytes = 1; - break; - case ASN_OSUBV_U16: - unit_bytes = 2; - break; - case ASN_OSUBV_U32: - unit_bytes = 4; - break; - } - - (void)opt_codec_ctx; - - if(!st) { - st = (OCTET_STRING_t *)(*sptr = CALLOC(1, specs->struct_size)); - if(!st) ASN__DECODE_FAILED; - } - - if(ct_size >= 0) { - expected_length = unit_bytes * ct_size; - } else { - /* - * X.696 (08/2015) #27.2 - * Encode length determinant as _number of octets_, but only - * if upper bound is not equal to lower bound. - */ - ssize_t len_len = oer_fetch_length(ptr, size, &expected_length); - if(len_len > 0) { - rval.consumed = len_len; - ptr = (const char *)ptr + len_len; - size -= len_len; - } else if(len_len == 0) { - ASN__DECODE_STARVED; - } else if(len_len < 0) { - ASN__DECODE_FAILED; - } - - if(expected_length % unit_bytes != 0) { - ASN_DEBUG( - "Data size %" ASN_PRI_SIZE " bytes is not consistent with multiplier %" ASN_PRI_SIZE "", - expected_length, unit_bytes); - ASN__DECODE_FAILED; - } - } - - if(size < expected_length) { - ASN__DECODE_STARVED; - } else { - uint8_t *buf = MALLOC(expected_length + 1); - if(buf == NULL) { - ASN__DECODE_FAILED; - } else { - memcpy(buf, ptr, expected_length); - buf[expected_length] = '\0'; - } - FREEMEM(st->buf); - st->buf = buf; - st->size = expected_length; - - rval.consumed += expected_length; - return rval; - } -} - -/* - * Encode as Canonical OER. - */ -asn_enc_rval_t -OCTET_STRING_encode_oer(const asn_TYPE_descriptor_t *td, - const asn_oer_constraints_t *constraints, - const void *sptr, asn_app_consume_bytes_f *cb, - void *app_key) { - const asn_OCTET_STRING_specifics_t *specs = - td->specifics ? (const asn_OCTET_STRING_specifics_t *)td->specifics - : &asn_SPC_OCTET_STRING_specs; - const OCTET_STRING_t *st = (const OCTET_STRING_t *)sptr; - const asn_oer_constraints_t *cts = - constraints ? constraints : td->encoding_constraints.oer_constraints; - ssize_t ct_size = cts ? cts->size : -1; - asn_enc_rval_t er = {0, 0, 0}; - - if(!st) ASN__ENCODE_FAILED; - - ASN_DEBUG("Encoding %s %" ASN_PRI_SIZE " as OCTET STRING", td ? td->name : "", st->size); - - if(ct_size >= 0) { - /* - * Check that available data matches the constraint - */ - size_t unit_bytes; - switch(specs->subvariant) { - default: - case ASN_OSUBV_BIT: - ASN_DEBUG("Invalid use of OCTET STRING to encode BIT STRING"); - ASN__ENCODE_FAILED; - case ASN_OSUBV_ANY: - /* Fall through */ - case ASN_OSUBV_STR: - unit_bytes = 1; - break; - case ASN_OSUBV_U16: - unit_bytes = 2; - break; - case ASN_OSUBV_U32: - unit_bytes = 4; - break; - } - - if(st->size != unit_bytes * (size_t)ct_size) { - ASN_DEBUG( - "Trying to encode %s (%" ASN_PRI_SIZE " bytes) which doesn't fit SIZE " - "constraint (%" ASN_PRI_SIZE ")", - td->name, st->size, ct_size); - ASN__ENCODE_FAILED; - } - } else { - /* - * X.696 (08/2015) #27.2 - * Encode length determinant as _number of octets_, but only - * if upper bound is not equal to lower bound. - */ - ssize_t ret = oer_serialize_length(st->size, cb, app_key); - if(ret < 0) { - ASN__ENCODE_FAILED; - } - er.encoded += ret; - } - - er.encoded += st->size; - if(cb(st->buf, st->size, app_key) < 0) { - ASN__ENCODE_FAILED; - } else { - ASN__ENCODED_OK(er); - } -} - -#endif /* ASN_DISABLE_OER_SUPPORT */ diff --git a/src/asn1/asn1c/OPEN_TYPE.c b/src/asn1/asn1c/OPEN_TYPE.c index 7dbe8351..72e188bb 100644 --- a/src/asn1/asn1c/OPEN_TYPE.c +++ b/src/asn1/asn1c/OPEN_TYPE.c @@ -5,7 +5,6 @@ #include "asn1/asn1c/asn_internal.h" #include "asn1/asn1c/OPEN_TYPE.h" #include "asn1/asn1c/constr_CHOICE.h" -#include "asn1/asn1c/per_opentype.h" #include asn_TYPE_operation_t asn_OP_OPEN_TYPE = { @@ -16,13 +15,6 @@ asn_TYPE_operation_t asn_OP_OPEN_TYPE = { OPEN_TYPE_encode_der, OPEN_TYPE_decode_xer, OPEN_TYPE_encode_xer, - 0, 0, /* No OER support, use "-gen-OER" to enable */ -#ifdef ASN_DISABLE_PER_SUPPORT - 0, 0, -#else - OPEN_TYPE_decode_uper, - OPEN_TYPE_encode_uper, -#endif 0, /* Random fill is not supported for open type */ 0, /* Use generic outmost tag fetcher */ }; @@ -281,122 +273,3 @@ OPEN_TYPE_xer_get(const asn_codec_ctx_t *opt_codec_ctx, return rv; } - - -#ifndef ASN_DISABLE_PER_SUPPORT - -asn_dec_rval_t -OPEN_TYPE_uper_get(const asn_codec_ctx_t *opt_codec_ctx, - const asn_TYPE_descriptor_t *td, void *sptr, - const asn_TYPE_member_t *elm, asn_per_data_t *pd) { - asn_type_selector_result_t selected; - void *memb_ptr; /* Pointer to the member */ - void **memb_ptr2; /* Pointer to that pointer */ - void *inner_value; - asn_dec_rval_t rv; - - if(!(elm->flags & ATF_OPEN_TYPE)) { - ASN__DECODE_FAILED; - } - - if(!elm->type_selector) { - ASN_DEBUG("Type selector is not defined for Open Type %s->%s->%s", - td->name, elm->name, elm->type->name); - ASN__DECODE_FAILED; - } - - selected = elm->type_selector(td, sptr); - if(!selected.presence_index) { - ASN__DECODE_FAILED; - } - - /* Fetch the pointer to this member */ - assert(elm->flags == ATF_OPEN_TYPE); - if(elm->flags & ATF_POINTER) { - memb_ptr2 = (void **)((char *)sptr + elm->memb_offset); - } else { - memb_ptr = (char *)sptr + elm->memb_offset; - memb_ptr2 = &memb_ptr; - } - if(*memb_ptr2 != NULL) { - /* Make sure we reset the structure first before encoding */ - if(CHOICE_variant_set_presence(elm->type, *memb_ptr2, 0) - != 0) { - ASN__DECODE_FAILED; - } - } - - inner_value = - (char *)*memb_ptr2 - + elm->type->elements[selected.presence_index - 1].memb_offset; - - rv = uper_open_type_get(opt_codec_ctx, selected.type_descriptor, NULL, - &inner_value, pd); - switch(rv.code) { - case RC_OK: - if(CHOICE_variant_set_presence(elm->type, *memb_ptr2, - selected.presence_index) - == 0) { - break; - } else { - rv.code = RC_FAIL; - } - /* Fall through */ - case RC_WMORE: - case RC_FAIL: - if(*memb_ptr2) { - const asn_CHOICE_specifics_t *specs = - selected.type_descriptor->specifics; - if(elm->flags & ATF_POINTER) { - ASN_STRUCT_FREE(*selected.type_descriptor, inner_value); - *memb_ptr2 = NULL; - } else { - ASN_STRUCT_FREE_CONTENTS_ONLY(*selected.type_descriptor, - inner_value); - memset(*memb_ptr2, 0, specs->struct_size); - } - } - } - return rv; -} - -asn_enc_rval_t -OPEN_TYPE_encode_uper(const asn_TYPE_descriptor_t *td, - const asn_per_constraints_t *constraints, - const void *sptr, asn_per_outp_t *po) { - const void *memb_ptr; /* Pointer to the member */ - asn_TYPE_member_t *elm; /* CHOICE's element */ - asn_enc_rval_t er; - unsigned present; - - (void)constraints; - - present = CHOICE_variant_get_presence(td, sptr); - if(present == 0 || present > td->elements_count) { - ASN__ENCODE_FAILED; - } else { - present--; - } - - ASN_DEBUG("Encoding %s OPEN TYPE element %d", td->name, present); - - elm = &td->elements[present]; - if(elm->flags & ATF_POINTER) { - /* Member is a pointer to another structure */ - memb_ptr = - *(const void *const *)((const char *)sptr + elm->memb_offset); - if(!memb_ptr) ASN__ENCODE_FAILED; - } else { - memb_ptr = (const char *)sptr + elm->memb_offset; - } - - if(uper_open_type_put(elm->type, NULL, memb_ptr, po) < 0) { - ASN__ENCODE_FAILED; - } - - er.encoded = 0; - ASN__ENCODED_OK(er); -} - - -#endif /* ASN_DISABLE_PER_SUPPORT */ diff --git a/src/asn1/asn1c/OPEN_TYPE.h b/src/asn1/asn1c/OPEN_TYPE.h index bd42a416..20724616 100644 --- a/src/asn1/asn1c/OPEN_TYPE.h +++ b/src/asn1/asn1c/OPEN_TYPE.h @@ -19,7 +19,6 @@ extern "C" { #define OPEN_TYPE_encode_der CHOICE_encode_der #define OPEN_TYPE_decode_xer NULL #define OPEN_TYPE_encode_xer CHOICE_encode_xer -#define OPEN_TYPE_decode_uper NULL extern asn_TYPE_operation_t asn_OP_OPEN_TYPE; @@ -39,23 +38,6 @@ asn_dec_rval_t OPEN_TYPE_xer_get(const asn_codec_ctx_t *opt_codec_ctx, const asn_TYPE_member_t *element, const void *ptr, size_t size); -asn_dec_rval_t OPEN_TYPE_oer_get(const asn_codec_ctx_t *opt_codec_ctx, - const asn_TYPE_descriptor_t *parent_type, - void *parent_structure, - asn_TYPE_member_t *element, const void *ptr, - size_t size); - -asn_dec_rval_t OPEN_TYPE_uper_get(const asn_codec_ctx_t *opt_codec_ctx, - const asn_TYPE_descriptor_t *parent_type, - void *parent_structure, - const asn_TYPE_member_t *element, - asn_per_data_t *pd); - -asn_enc_rval_t OPEN_TYPE_encode_uper( - const asn_TYPE_descriptor_t *type_descriptor, - const asn_per_constraints_t *constraints, const void *struct_ptr, - asn_per_outp_t *per_output); - #ifdef __cplusplus } #endif diff --git a/src/asn1/asn1c/OPEN_TYPE_oer.c b/src/asn1/asn1c/OPEN_TYPE_oer.c deleted file mode 100644 index 3d6deb86..00000000 --- a/src/asn1/asn1c/OPEN_TYPE_oer.c +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (c) 2017 Lev Walkin . All rights reserved. - * Redistribution and modifications are permitted subject to BSD license. - */ -#include "asn1/asn1c/asn_internal.h" -#include "asn1/asn1c/OPEN_TYPE.h" -#include "asn1/asn1c/constr_CHOICE.h" - -asn_dec_rval_t -OPEN_TYPE_oer_get(const asn_codec_ctx_t *opt_codec_ctx, - const asn_TYPE_descriptor_t *td, void *sptr, - asn_TYPE_member_t *elm, const void *ptr, size_t size) { - asn_type_selector_result_t selected; - void *memb_ptr; /* Pointer to the member */ - void **memb_ptr2; /* Pointer to that pointer */ - void *inner_value; - asn_dec_rval_t rv; - size_t ot_ret; - - - if(!(elm->flags & ATF_OPEN_TYPE)) { - ASN__DECODE_FAILED; - } - - if(!elm->type_selector) { - ASN_DEBUG("Type selector is not defined for Open Type %s->%s->%s", - td->name, elm->name, elm->type->name); - ASN__DECODE_FAILED; - } - - selected = elm->type_selector(td, sptr); - if(!selected.presence_index) { - ASN__DECODE_FAILED; - } - - /* Fetch the pointer to this member */ - if(elm->flags & ATF_POINTER) { - memb_ptr2 = (void **)((char *)sptr + elm->memb_offset); - } else { - memb_ptr = (char *)sptr + elm->memb_offset; - memb_ptr2 = &memb_ptr; - } - if(*memb_ptr2 != NULL) { - /* Make sure we reset the structure first before encoding */ - if(CHOICE_variant_set_presence(elm->type, *memb_ptr2, 0) != 0) { - ASN__DECODE_FAILED; - } - } - - inner_value = - (char *)*memb_ptr2 - + elm->type->elements[selected.presence_index - 1].memb_offset; - - ot_ret = oer_open_type_get(opt_codec_ctx, selected.type_descriptor, NULL, - &inner_value, ptr, size); - switch(ot_ret) { - default: - if(CHOICE_variant_set_presence(elm->type, *memb_ptr2, - selected.presence_index) - == 0) { - rv.code = RC_OK; - rv.consumed = ot_ret; - return rv; - } else { - /* Oh, now a full-blown failure failure */ - } - /* Fall through */ - case -1: - rv.code = RC_FAIL; - rv.consumed = ot_ret; - break; - case 0: - rv.code = RC_WMORE; - rv.consumed = 0; - break; - } - - if(*memb_ptr2) { - const asn_CHOICE_specifics_t *specs = - selected.type_descriptor->specifics; - if(elm->flags & ATF_POINTER) { - ASN_STRUCT_FREE(*selected.type_descriptor, inner_value); - *memb_ptr2 = NULL; - } else { - ASN_STRUCT_FREE_CONTENTS_ONLY(*selected.type_descriptor, - inner_value); - memset(*memb_ptr2, 0, specs->struct_size); - } - } - return rv; -} diff --git a/src/asn1/asn1c/OtherRevocationInfoFormat.c b/src/asn1/asn1c/OtherRevocationInfoFormat.c index 93de37e8..50f5917c 100644 --- a/src/asn1/asn1c/OtherRevocationInfoFormat.c +++ b/src/asn1/asn1c/OtherRevocationInfoFormat.c @@ -38,7 +38,6 @@ asn_SEQUENCE_specifics_t asn_SPC_OtherRevocationInfoFormat_specs_1 = { offsetof(struct OtherRevocationInfoFormat, _asn_ctx), asn_MAP_OtherRevocationInfoFormat_tag2el_1, 1, /* Count of tags in the map */ - 0, 0, 0, /* Optional elements (not needed) */ -1, /* First extension addition */ }; asn_TYPE_descriptor_t asn_DEF_OtherRevocationInfoFormat = { diff --git a/src/asn1/asn1c/ROAIPAddress.c b/src/asn1/asn1c/ROAIPAddress.c index 55ba20a4..48aed1ce 100644 --- a/src/asn1/asn1c/ROAIPAddress.c +++ b/src/asn1/asn1c/ROAIPAddress.c @@ -27,7 +27,6 @@ asn_TYPE_member_t asn_MBR_ROAIPAddress_1[] = { "maxLength" }, }; -static const int asn_MAP_ROAIPAddress_oms_1[] = { 1 }; static const ber_tlv_tag_t asn_DEF_ROAIPAddress_tags_1[] = { (ASN_TAG_CLASS_UNIVERSAL | (16 << 2)) }; @@ -40,8 +39,6 @@ asn_SEQUENCE_specifics_t asn_SPC_ROAIPAddress_specs_1 = { offsetof(struct ROAIPAddress, _asn_ctx), asn_MAP_ROAIPAddress_tag2el_1, 2, /* Count of tags in the map */ - asn_MAP_ROAIPAddress_oms_1, /* Optional members */ - 1, 0, /* Root/Additions */ -1, /* First extension addition */ }; asn_TYPE_descriptor_t asn_DEF_ROAIPAddress = { diff --git a/src/asn1/asn1c/ROAIPAddressFamily.c b/src/asn1/asn1c/ROAIPAddressFamily.c index 43f3a575..80d165c3 100644 --- a/src/asn1/asn1c/ROAIPAddressFamily.c +++ b/src/asn1/asn1c/ROAIPAddressFamily.c @@ -59,15 +59,6 @@ memb_addresses_constraint_1(const asn_TYPE_descriptor_t *td, const void *sptr, } } -static asn_oer_constraints_t asn_OER_type_addresses_constr_3 CC_NOTUSED = { - { 0, 0 }, - -1 /* (SIZE(1..MAX)) */}; -static asn_oer_constraints_t asn_OER_memb_addressFamily_constr_2 CC_NOTUSED = { - { 0, 0 }, - -1 /* (SIZE(2..3)) */}; -static asn_oer_constraints_t asn_OER_memb_addresses_constr_3 CC_NOTUSED = { - { 0, 0 }, - -1 /* (SIZE(1..MAX)) */}; static asn_TYPE_member_t asn_MBR_addresses_3[] = { { ATF_POINTER, 0, 0, (ASN_TAG_CLASS_UNIVERSAL | (16 << 2)), @@ -98,7 +89,7 @@ asn_TYPE_descriptor_t asn_DEF_addresses_3 = { asn_DEF_addresses_tags_3, /* Same as above */ sizeof(asn_DEF_addresses_tags_3) /sizeof(asn_DEF_addresses_tags_3[0]), /* 1 */ - { &asn_OER_type_addresses_constr_3, 0, SEQUENCE_OF_constraint }, + { NULL, 0, SEQUENCE_OF_constraint }, asn_MBR_addresses_3, 1, /* Single element */ &asn_SPC_addresses_specs_3 /* Additional specs */ @@ -110,7 +101,7 @@ asn_TYPE_member_t asn_MBR_ROAIPAddressFamily_1[] = { 0, &asn_DEF_OCTET_STRING, 0, - { &asn_OER_memb_addressFamily_constr_2, 0, memb_addressFamily_constraint_1 }, + { NULL, 0, memb_addressFamily_constraint_1 }, 0, 0, /* No default value */ "addressFamily" }, @@ -119,7 +110,7 @@ asn_TYPE_member_t asn_MBR_ROAIPAddressFamily_1[] = { 0, &asn_DEF_addresses_3, 0, - { &asn_OER_memb_addresses_constr_3, 0, memb_addresses_constraint_1 }, + { NULL, 0, memb_addresses_constraint_1 }, 0, 0, /* No default value */ "addresses" }, @@ -136,7 +127,6 @@ asn_SEQUENCE_specifics_t asn_SPC_ROAIPAddressFamily_specs_1 = { offsetof(struct ROAIPAddressFamily, _asn_ctx), asn_MAP_ROAIPAddressFamily_tag2el_1, 2, /* Count of tags in the map */ - 0, 0, 0, /* Optional elements (not needed) */ -1, /* First extension addition */ }; asn_TYPE_descriptor_t asn_DEF_ROAIPAddressFamily = { diff --git a/src/asn1/asn1c/RelativeDistinguishedName.c b/src/asn1/asn1c/RelativeDistinguishedName.c index 14fb68ce..924b570b 100644 --- a/src/asn1/asn1c/RelativeDistinguishedName.c +++ b/src/asn1/asn1c/RelativeDistinguishedName.c @@ -7,9 +7,6 @@ #include "asn1/asn1c/RelativeDistinguishedName.h" -static asn_oer_constraints_t asn_OER_type_RelativeDistinguishedName_constr_1 CC_NOTUSED = { - { 0, 0 }, - -1 /* (SIZE(1..MAX)) */}; asn_TYPE_member_t asn_MBR_RelativeDistinguishedName_1[] = { { ATF_POINTER, 0, 0, (ASN_TAG_CLASS_UNIVERSAL | (16 << 2)), @@ -39,7 +36,7 @@ asn_TYPE_descriptor_t asn_DEF_RelativeDistinguishedName = { asn_DEF_RelativeDistinguishedName_tags_1, /* Same as above */ sizeof(asn_DEF_RelativeDistinguishedName_tags_1) /sizeof(asn_DEF_RelativeDistinguishedName_tags_1[0]), /* 1 */ - { &asn_OER_type_RelativeDistinguishedName_constr_1, 0, SET_OF_constraint }, + { NULL, 0, SET_OF_constraint }, asn_MBR_RelativeDistinguishedName_1, 1, /* Single element */ &asn_SPC_RelativeDistinguishedName_specs_1 /* Additional specs */ diff --git a/src/asn1/asn1c/RevocationInfoChoice.c b/src/asn1/asn1c/RevocationInfoChoice.c index 163289be..a30a974f 100644 --- a/src/asn1/asn1c/RevocationInfoChoice.c +++ b/src/asn1/asn1c/RevocationInfoChoice.c @@ -7,9 +7,6 @@ #include "asn1/asn1c/RevocationInfoChoice.h" -static asn_oer_constraints_t asn_OER_type_RevocationInfoChoice_constr_1 CC_NOTUSED = { - { 0, 0 }, - -1}; asn_TYPE_member_t asn_MBR_RevocationInfoChoice_1[] = { { ATF_NOFLAGS, 0, offsetof(struct RevocationInfoChoice, choice.crl), (ASN_TAG_CLASS_UNIVERSAL | (16 << 2)), @@ -41,7 +38,6 @@ asn_CHOICE_specifics_t asn_SPC_RevocationInfoChoice_specs_1 = { sizeof(((struct RevocationInfoChoice *)0)->present), asn_MAP_RevocationInfoChoice_tag2el_1, 2, /* Count of tags in the map */ - 0, 0, -1 /* Extensions start */ }; asn_TYPE_descriptor_t asn_DEF_RevocationInfoChoice = { @@ -52,7 +48,7 @@ asn_TYPE_descriptor_t asn_DEF_RevocationInfoChoice = { 0, /* No effective tags (count) */ 0, /* No tags (pointer) */ 0, /* No tags (count) */ - { &asn_OER_type_RevocationInfoChoice_constr_1, 0, CHOICE_constraint }, + { NULL, 0, CHOICE_constraint }, asn_MBR_RevocationInfoChoice_1, 2, /* Elements count */ &asn_SPC_RevocationInfoChoice_specs_1 /* Additional specs */ diff --git a/src/asn1/asn1c/RouteOriginAttestation.c b/src/asn1/asn1c/RouteOriginAttestation.c index 37361155..7871f584 100644 --- a/src/asn1/asn1c/RouteOriginAttestation.c +++ b/src/asn1/asn1c/RouteOriginAttestation.c @@ -33,12 +33,6 @@ memb_ipAddrBlocks_constraint_1(const asn_TYPE_descriptor_t *td, const void *sptr } } -static asn_oer_constraints_t asn_OER_type_ipAddrBlocks_constr_4 CC_NOTUSED = { - { 0, 0 }, - -1 /* (SIZE(1..MAX)) */}; -static asn_oer_constraints_t asn_OER_memb_ipAddrBlocks_constr_4 CC_NOTUSED = { - { 0, 0 }, - -1 /* (SIZE(1..MAX)) */}; static int asn_DFL_2_cmp_0(const void *sptr) { const INTEGER_t *st = sptr; @@ -93,7 +87,7 @@ asn_TYPE_descriptor_t asn_DEF_ipAddrBlocks_4 = { asn_DEF_ipAddrBlocks_tags_4, /* Same as above */ sizeof(asn_DEF_ipAddrBlocks_tags_4) /sizeof(asn_DEF_ipAddrBlocks_tags_4[0]), /* 1 */ - { &asn_OER_type_ipAddrBlocks_constr_4, 0, SEQUENCE_OF_constraint }, + { NULL, 0, SEQUENCE_OF_constraint }, asn_MBR_ipAddrBlocks_4, 1, /* Single element */ &asn_SPC_ipAddrBlocks_specs_4 /* Additional specs */ @@ -124,12 +118,11 @@ static asn_TYPE_member_t asn_MBR_RouteOriginAttestation_1[] = { 0, &asn_DEF_ipAddrBlocks_4, 0, - { &asn_OER_memb_ipAddrBlocks_constr_4, 0, memb_ipAddrBlocks_constraint_1 }, + { NULL, 0, memb_ipAddrBlocks_constraint_1 }, 0, 0, /* No default value */ "ipAddrBlocks" }, }; -static const int asn_MAP_RouteOriginAttestation_oms_1[] = { 0 }; static const ber_tlv_tag_t asn_DEF_RouteOriginAttestation_tags_1[] = { (ASN_TAG_CLASS_UNIVERSAL | (16 << 2)) }; @@ -143,8 +136,6 @@ static asn_SEQUENCE_specifics_t asn_SPC_RouteOriginAttestation_specs_1 = { offsetof(struct RouteOriginAttestation, _asn_ctx), asn_MAP_RouteOriginAttestation_tag2el_1, 3, /* Count of tags in the map */ - asn_MAP_RouteOriginAttestation_oms_1, /* Optional members */ - 1, 0, /* Root/Additions */ -1, /* First extension addition */ }; asn_TYPE_descriptor_t asn_DEF_RouteOriginAttestation = { diff --git a/src/asn1/asn1c/SignatureAlgorithmIdentifier.h b/src/asn1/asn1c/SignatureAlgorithmIdentifier.h index cc15f45b..3a54a056 100644 --- a/src/asn1/asn1c/SignatureAlgorithmIdentifier.h +++ b/src/asn1/asn1c/SignatureAlgorithmIdentifier.h @@ -30,8 +30,6 @@ ber_type_decoder_f SignatureAlgorithmIdentifier_decode_ber; der_type_encoder_f SignatureAlgorithmIdentifier_encode_der; xer_type_decoder_f SignatureAlgorithmIdentifier_decode_xer; xer_type_encoder_f SignatureAlgorithmIdentifier_encode_xer; -oer_type_decoder_f SignatureAlgorithmIdentifier_decode_oer; -oer_type_encoder_f SignatureAlgorithmIdentifier_encode_oer; #ifdef __cplusplus } diff --git a/src/asn1/asn1c/SignatureValue.h b/src/asn1/asn1c/SignatureValue.h index 01689a93..332d2325 100644 --- a/src/asn1/asn1c/SignatureValue.h +++ b/src/asn1/asn1c/SignatureValue.h @@ -30,8 +30,6 @@ ber_type_decoder_f SignatureValue_decode_ber; der_type_encoder_f SignatureValue_encode_der; xer_type_decoder_f SignatureValue_decode_xer; xer_type_encoder_f SignatureValue_encode_xer; -oer_type_decoder_f SignatureValue_decode_oer; -oer_type_encoder_f SignatureValue_encode_oer; #ifdef __cplusplus } diff --git a/src/asn1/asn1c/SignedAttributes.c b/src/asn1/asn1c/SignedAttributes.c index 2a9ff2b6..ef8f9f6c 100644 --- a/src/asn1/asn1c/SignedAttributes.c +++ b/src/asn1/asn1c/SignedAttributes.c @@ -7,9 +7,6 @@ #include "asn1/asn1c/SignedAttributes.h" -static asn_oer_constraints_t asn_OER_type_SignedAttributes_constr_1 CC_NOTUSED = { - { 0, 0 }, - -1 /* (SIZE(1..MAX)) */}; asn_TYPE_member_t asn_MBR_SignedAttributes_1[] = { { ATF_POINTER, 0, 0, (ASN_TAG_CLASS_UNIVERSAL | (16 << 2)), @@ -39,7 +36,7 @@ asn_TYPE_descriptor_t asn_DEF_SignedAttributes = { asn_DEF_SignedAttributes_tags_1, /* Same as above */ sizeof(asn_DEF_SignedAttributes_tags_1) /sizeof(asn_DEF_SignedAttributes_tags_1[0]), /* 1 */ - { &asn_OER_type_SignedAttributes_constr_1, 0, SET_OF_constraint }, + { NULL, 0, SET_OF_constraint }, asn_MBR_SignedAttributes_1, 1, /* Single element */ &asn_SPC_SignedAttributes_specs_1 /* Additional specs */ diff --git a/src/asn1/asn1c/SignedData.c b/src/asn1/asn1c/SignedData.c index 17be176a..40ba0a40 100644 --- a/src/asn1/asn1c/SignedData.c +++ b/src/asn1/asn1c/SignedData.c @@ -63,7 +63,6 @@ static asn_TYPE_member_t asn_MBR_SignedData_1[] = { "signerInfos" }, }; -static const int asn_MAP_SignedData_oms_1[] = { 3, 4 }; static const ber_tlv_tag_t asn_DEF_SignedData_tags_1[] = { (ASN_TAG_CLASS_UNIVERSAL | (16 << 2)) }; @@ -80,8 +79,6 @@ static asn_SEQUENCE_specifics_t asn_SPC_SignedData_specs_1 = { offsetof(struct SignedData, _asn_ctx), asn_MAP_SignedData_tag2el_1, 6, /* Count of tags in the map */ - asn_MAP_SignedData_oms_1, /* Optional members */ - 2, 0, /* Root/Additions */ -1, /* First extension addition */ }; asn_TYPE_descriptor_t asn_DEF_SignedData = { diff --git a/src/asn1/asn1c/SignedDataPKCS7.c b/src/asn1/asn1c/SignedDataPKCS7.c index e642b46c..0bad7226 100644 --- a/src/asn1/asn1c/SignedDataPKCS7.c +++ b/src/asn1/asn1c/SignedDataPKCS7.c @@ -63,7 +63,6 @@ static asn_TYPE_member_t asn_MBR_SignedDataPKCS7_1[] = { "signerInfos" }, }; -static const int asn_MAP_SignedDataPKCS7_oms_1[] = { 3, 4 }; static const ber_tlv_tag_t asn_DEF_SignedDataPKCS7_tags_1[] = { (ASN_TAG_CLASS_UNIVERSAL | (16 << 2)) }; @@ -80,8 +79,6 @@ static asn_SEQUENCE_specifics_t asn_SPC_SignedDataPKCS7_specs_1 = { offsetof(struct SignedDataPKCS7, _asn_ctx), asn_MAP_SignedDataPKCS7_tag2el_1, 6, /* Count of tags in the map */ - asn_MAP_SignedDataPKCS7_oms_1, /* Optional members */ - 2, 0, /* Root/Additions */ -1, /* First extension addition */ }; asn_TYPE_descriptor_t asn_DEF_SignedDataPKCS7 = { diff --git a/src/asn1/asn1c/SignerIdentifier.c b/src/asn1/asn1c/SignerIdentifier.c index 24a41ea1..cc07d791 100644 --- a/src/asn1/asn1c/SignerIdentifier.c +++ b/src/asn1/asn1c/SignerIdentifier.c @@ -7,9 +7,6 @@ #include "asn1/asn1c/SignerIdentifier.h" -static asn_oer_constraints_t asn_OER_type_SignerIdentifier_constr_1 CC_NOTUSED = { - { 0, 0 }, - -1}; asn_TYPE_member_t asn_MBR_SignerIdentifier_1[] = { { ATF_NOFLAGS, 0, offsetof(struct SignerIdentifier, choice.issuerAndSerialNumber), (ASN_TAG_CLASS_UNIVERSAL | (16 << 2)), @@ -41,7 +38,6 @@ asn_CHOICE_specifics_t asn_SPC_SignerIdentifier_specs_1 = { sizeof(((struct SignerIdentifier *)0)->present), asn_MAP_SignerIdentifier_tag2el_1, 2, /* Count of tags in the map */ - 0, 0, -1 /* Extensions start */ }; asn_TYPE_descriptor_t asn_DEF_SignerIdentifier = { @@ -52,7 +48,7 @@ asn_TYPE_descriptor_t asn_DEF_SignerIdentifier = { 0, /* No effective tags (count) */ 0, /* No tags (pointer) */ 0, /* No tags (count) */ - { &asn_OER_type_SignerIdentifier_constr_1, 0, CHOICE_constraint }, + { NULL, 0, CHOICE_constraint }, asn_MBR_SignerIdentifier_1, 2, /* Elements count */ &asn_SPC_SignerIdentifier_specs_1 /* Additional specs */ diff --git a/src/asn1/asn1c/SignerInfo.c b/src/asn1/asn1c/SignerInfo.c index 621246f7..c5fc63e4 100644 --- a/src/asn1/asn1c/SignerInfo.c +++ b/src/asn1/asn1c/SignerInfo.c @@ -72,7 +72,6 @@ asn_TYPE_member_t asn_MBR_SignerInfo_1[] = { "unsignedAttrs" }, }; -static const int asn_MAP_SignerInfo_oms_1[] = { 3, 6 }; static const ber_tlv_tag_t asn_DEF_SignerInfo_tags_1[] = { (ASN_TAG_CLASS_UNIVERSAL | (16 << 2)) }; @@ -91,8 +90,6 @@ asn_SEQUENCE_specifics_t asn_SPC_SignerInfo_specs_1 = { offsetof(struct SignerInfo, _asn_ctx), asn_MAP_SignerInfo_tag2el_1, 8, /* Count of tags in the map */ - asn_MAP_SignerInfo_oms_1, /* Optional members */ - 2, 0, /* Root/Additions */ -1, /* First extension addition */ }; asn_TYPE_descriptor_t asn_DEF_SignerInfo = { diff --git a/src/asn1/asn1c/SigningTime.c b/src/asn1/asn1c/SigningTime.c index d7adb8e8..0b64cebd 100644 --- a/src/asn1/asn1c/SigningTime.c +++ b/src/asn1/asn1c/SigningTime.c @@ -11,9 +11,6 @@ * This type is implemented using Time, * so here we adjust the DEF accordingly. */ -static asn_oer_constraints_t asn_OER_type_SigningTime_constr_1 CC_NOTUSED = { - { 0, 0 }, - -1}; asn_TYPE_descriptor_t asn_DEF_SigningTime = { "SigningTime", "SigningTime", diff --git a/src/asn1/asn1c/SigningTime.h b/src/asn1/asn1c/SigningTime.h index eab03ad8..839567b3 100644 --- a/src/asn1/asn1c/SigningTime.h +++ b/src/asn1/asn1c/SigningTime.h @@ -30,8 +30,6 @@ ber_type_decoder_f SigningTime_decode_ber; der_type_encoder_f SigningTime_encode_der; xer_type_decoder_f SigningTime_decode_xer; xer_type_encoder_f SigningTime_encode_xer; -oer_type_decoder_f SigningTime_decode_oer; -oer_type_encoder_f SigningTime_encode_oer; #ifdef __cplusplus } diff --git a/src/asn1/asn1c/TBSCertList.c b/src/asn1/asn1c/TBSCertList.c index 4bbccd15..b913ae03 100644 --- a/src/asn1/asn1c/TBSCertList.c +++ b/src/asn1/asn1c/TBSCertList.c @@ -36,7 +36,6 @@ static asn_TYPE_member_t asn_MBR_Member_8[] = { "crlEntryExtensions" }, }; -static const int asn_MAP_Member_oms_8[] = { 2 }; static const ber_tlv_tag_t asn_DEF_Member_tags_8[] = { (ASN_TAG_CLASS_UNIVERSAL | (16 << 2)) }; @@ -51,8 +50,6 @@ static asn_SEQUENCE_specifics_t asn_SPC_Member_specs_8 = { offsetof(struct TBSCertList__revokedCertificates__Member, _asn_ctx), asn_MAP_Member_tag2el_8, 4, /* Count of tags in the map */ - asn_MAP_Member_oms_8, /* Optional members */ - 1, 0, /* Root/Additions */ -1, /* First extension addition */ }; static /* Use -fall-defs-global to expose */ @@ -173,7 +170,6 @@ asn_TYPE_member_t asn_MBR_TBSCertList_1[] = { "crlExtensions" }, }; -static const int asn_MAP_TBSCertList_oms_1[] = { 0, 4, 5, 6 }; static const ber_tlv_tag_t asn_DEF_TBSCertList_tags_1[] = { (ASN_TAG_CLASS_UNIVERSAL | (16 << 2)) }; @@ -193,8 +189,6 @@ asn_SEQUENCE_specifics_t asn_SPC_TBSCertList_specs_1 = { offsetof(struct TBSCertList, _asn_ctx), asn_MAP_TBSCertList_tag2el_1, 9, /* Count of tags in the map */ - asn_MAP_TBSCertList_oms_1, /* Optional members */ - 4, 0, /* Root/Additions */ -1, /* First extension addition */ }; asn_TYPE_descriptor_t asn_DEF_TBSCertList = { diff --git a/src/asn1/asn1c/Time.c b/src/asn1/asn1c/Time.c index a6990b75..2c867f30 100644 --- a/src/asn1/asn1c/Time.c +++ b/src/asn1/asn1c/Time.c @@ -7,9 +7,6 @@ #include "asn1/asn1c/Time.h" -static asn_oer_constraints_t asn_OER_type_Time_constr_1 CC_NOTUSED = { - { 0, 0 }, - -1}; asn_TYPE_member_t asn_MBR_Time_1[] = { { ATF_NOFLAGS, 0, offsetof(struct Time, choice.utcTime), (ASN_TAG_CLASS_UNIVERSAL | (23 << 2)), @@ -41,7 +38,6 @@ asn_CHOICE_specifics_t asn_SPC_Time_specs_1 = { sizeof(((struct Time *)0)->present), asn_MAP_Time_tag2el_1, 2, /* Count of tags in the map */ - 0, 0, -1 /* Extensions start */ }; asn_TYPE_descriptor_t asn_DEF_Time = { @@ -52,7 +48,7 @@ asn_TYPE_descriptor_t asn_DEF_Time = { 0, /* No effective tags (count) */ 0, /* No tags (pointer) */ 0, /* No tags (count) */ - { &asn_OER_type_Time_constr_1, 0, CHOICE_constraint }, + { NULL, 0, CHOICE_constraint }, asn_MBR_Time_1, 2, /* Elements count */ &asn_SPC_Time_specs_1 /* Additional specs */ diff --git a/src/asn1/asn1c/UTCTime.c b/src/asn1/asn1c/UTCTime.c index 86091407..eca241f5 100644 --- a/src/asn1/asn1c/UTCTime.c +++ b/src/asn1/asn1c/UTCTime.c @@ -20,11 +20,6 @@ static const ber_tlv_tag_t asn_DEF_UTCTime_tags[] = { (ASN_TAG_CLASS_UNIVERSAL | (26 << 2)), /* [UNIVERSAL 26] IMPLICIT ...*/ (ASN_TAG_CLASS_UNIVERSAL | (4 << 2)) /* ... OCTET STRING */ }; -static asn_per_constraints_t asn_DEF_UTCTime_constraints = { - { APC_CONSTRAINED, 7, 7, 0x20, 0x7e }, /* Value */ - { APC_SEMI_CONSTRAINED, -1, -1, 0, 0 }, /* Size */ - 0, 0 -}; asn_TYPE_operation_t asn_OP_UTCTime = { OCTET_STRING_free, UTCTime_print, @@ -33,20 +28,6 @@ asn_TYPE_operation_t asn_OP_UTCTime = { OCTET_STRING_encode_der, /* Implemented in terms of OCTET STRING */ OCTET_STRING_decode_xer_utf8, UTCTime_encode_xer, -#ifdef ASN_DISABLE_OER_SUPPORT - 0, - 0, -#else - OCTET_STRING_decode_oer, - OCTET_STRING_encode_oer, -#endif /* ASN_DISABLE_OER_SUPPORT */ -#ifdef ASN_DISABLE_PER_SUPPORT - 0, - 0, -#else - OCTET_STRING_decode_uper, - OCTET_STRING_encode_uper, -#endif /* ASN_DISABLE_PER_SUPPORT */ UTCTime_random_fill, 0 /* Use generic outmost tag fetcher */ }; @@ -60,7 +41,7 @@ asn_TYPE_descriptor_t asn_DEF_UTCTime = { asn_DEF_UTCTime_tags, sizeof(asn_DEF_UTCTime_tags) / sizeof(asn_DEF_UTCTime_tags[0]), - { 0, &asn_DEF_UTCTime_constraints, UTCTime_constraint }, + { 0, NULL, UTCTime_constraint }, 0, 0, /* No members */ 0 /* No specifics */ }; diff --git a/src/asn1/asn1c/UTCTime.h b/src/asn1/asn1c/UTCTime.h index 33318cf8..67025902 100644 --- a/src/asn1/asn1c/UTCTime.h +++ b/src/asn1/asn1c/UTCTime.h @@ -28,8 +28,6 @@ asn_random_fill_f UTCTime_random_fill; #define UTCTime_decode_ber OCTET_STRING_decode_ber #define UTCTime_encode_der OCTET_STRING_encode_der #define UTCTime_decode_xer OCTET_STRING_decode_xer_utf8 -#define UTCTime_decode_uper OCTET_STRING_decode_uper -#define UTCTime_encode_uper OCTET_STRING_encode_uper /*********************** * Some handy helpers. * diff --git a/src/asn1/asn1c/UnsignedAttributes.c b/src/asn1/asn1c/UnsignedAttributes.c index 19428fa4..3e12d61b 100644 --- a/src/asn1/asn1c/UnsignedAttributes.c +++ b/src/asn1/asn1c/UnsignedAttributes.c @@ -7,9 +7,6 @@ #include "asn1/asn1c/UnsignedAttributes.h" -static asn_oer_constraints_t asn_OER_type_UnsignedAttributes_constr_1 CC_NOTUSED = { - { 0, 0 }, - -1 /* (SIZE(1..MAX)) */}; asn_TYPE_member_t asn_MBR_UnsignedAttributes_1[] = { { ATF_POINTER, 0, 0, (ASN_TAG_CLASS_UNIVERSAL | (16 << 2)), @@ -39,7 +36,7 @@ asn_TYPE_descriptor_t asn_DEF_UnsignedAttributes = { asn_DEF_UnsignedAttributes_tags_1, /* Same as above */ sizeof(asn_DEF_UnsignedAttributes_tags_1) /sizeof(asn_DEF_UnsignedAttributes_tags_1[0]), /* 1 */ - { &asn_OER_type_UnsignedAttributes_constr_1, 0, SET_OF_constraint }, + { NULL, 0, SET_OF_constraint }, asn_MBR_UnsignedAttributes_1, 1, /* Single element */ &asn_SPC_UnsignedAttributes_specs_1 /* Additional specs */ diff --git a/src/asn1/asn1c/Version.h b/src/asn1/asn1c/Version.h index 78d9c737..c117f812 100644 --- a/src/asn1/asn1c/Version.h +++ b/src/asn1/asn1c/Version.h @@ -37,8 +37,6 @@ ber_type_decoder_f Version_decode_ber; der_type_encoder_f Version_encode_der; xer_type_decoder_f Version_decode_xer; xer_type_encoder_f Version_encode_xer; -oer_type_decoder_f Version_decode_oer; -oer_type_encoder_f Version_encode_oer; #ifdef __cplusplus } diff --git a/src/asn1/asn1c/asn_application.c b/src/asn1/asn1c/asn_application.c index 562f87b8..c5d43478 100644 --- a/src/asn1/asn1c/asn_application.c +++ b/src/asn1/asn1c/asn_application.c @@ -288,72 +288,6 @@ asn_encode_internal(const asn_codec_ctx_t *opt_codec_ctx, errno = ENOENT; /* Transfer syntax is not defined for any type. */ ASN__ENCODE_FAILED; -#ifdef ASN_DISABLE_OER_SUPPORT - case ATS_BASIC_OER: - case ATS_CANONICAL_OER: - errno = ENOENT; /* PER is not defined. */ - ASN__ENCODE_FAILED; - break; -#else /* ASN_DISABLE_OER_SUPPORT */ - case ATS_BASIC_OER: - /* CANONICAL-OER is a superset of BASIC-OER. */ - /* Fall through. */ - case ATS_CANONICAL_OER: - if(td->op->oer_encoder) { - er = oer_encode(td, sptr, callback, callback_key); - if(er.encoded == -1) { - if(er.failed_type && er.failed_type->op->oer_encoder) { - errno = EBADF; /* Structure has incorrect form. */ - } else { - errno = ENOENT; /* OER is not defined for this type. */ - } - } - } else { - errno = ENOENT; /* Transfer syntax is not defined for this type. */ - ASN__ENCODE_FAILED; - } - break; -#endif /* ASN_DISABLE_OER_SUPPORT */ - -#ifdef ASN_DISABLE_PER_SUPPORT - case ATS_UNALIGNED_BASIC_PER: - case ATS_UNALIGNED_CANONICAL_PER: - errno = ENOENT; /* PER is not defined. */ - ASN__ENCODE_FAILED; - break; -#else /* ASN_DISABLE_PER_SUPPORT */ - case ATS_UNALIGNED_BASIC_PER: - /* CANONICAL-UPER is a superset of BASIC-UPER. */ - /* Fall through. */ - case ATS_UNALIGNED_CANONICAL_PER: - if(td->op->uper_encoder) { - er = uper_encode(td, 0, sptr, callback, callback_key); - if(er.encoded == -1) { - if(er.failed_type && er.failed_type->op->uper_encoder) { - errno = EBADF; /* Structure has incorrect form. */ - } else { - errno = ENOENT; /* UPER is not defined for this type. */ - } - } else { - ASN_DEBUG("Complete encoded in %ld bits", (long)er.encoded); - if(er.encoded == 0) { - /* Enforce "Complete Encoding" of X.691 #11.1 */ - if(callback("\0", 1, callback_key) < 0) { - errno = EBADF; - ASN__ENCODE_FAILED; - } - er.encoded = 8; /* Exactly 8 zero bits is added. */ - } - /* Convert bits into bytes */ - er.encoded = (er.encoded + 7) >> 3; - } - } else { - errno = ENOENT; /* Transfer syntax is not defined for this type. */ - ASN__ENCODE_FAILED; - } - break; -#endif /* ASN_DISABLE_PER_SUPPORT */ - case ATS_BASIC_XER: /* CANONICAL-XER is a superset of BASIC-XER. */ xer_flags &= ~XER_F_CANONICAL; @@ -415,24 +349,6 @@ asn_decode(const asn_codec_ctx_t *opt_codec_ctx, case ATS_BER: return ber_decode(opt_codec_ctx, td, sptr, buffer, size); - case ATS_BASIC_OER: - case ATS_CANONICAL_OER: -#ifdef ASN_DISABLE_OER_SUPPORT - errno = ENOENT; - ASN__DECODE_FAILED; -#else - return oer_decode(opt_codec_ctx, td, sptr, buffer, size); -#endif - - case ATS_UNALIGNED_BASIC_PER: - case ATS_UNALIGNED_CANONICAL_PER: -#ifdef ASN_DISABLE_PER_SUPPORT - errno = ENOENT; - ASN__DECODE_FAILED; -#else - return uper_decode_complete(opt_codec_ctx, td, sptr, buffer, size); -#endif - case ATS_BASIC_XER: case ATS_CANONICAL_XER: return xer_decode(opt_codec_ctx, td, sptr, buffer, size); diff --git a/src/asn1/asn1c/asn_application.h b/src/asn1/asn1c/asn_application.h index 7d33201e..d9e5756e 100644 --- a/src/asn1/asn1c/asn_application.h +++ b/src/asn1/asn1c/asn_application.h @@ -36,21 +36,6 @@ enum asn_transfer_syntax { ATS_BER, ATS_DER, ATS_CER, /* Only decoding is supported */ - /* - * X.696: - * OER: Octet Encoding Rules. - * CANONICAL-OER is a more strict variant of BASIC-OER. - */ - ATS_BASIC_OER, - ATS_CANONICAL_OER, - /* - * X.691: - * PER: Packed Encoding Rules. - * CANONICAL-PER is a more strict variant of BASIC-PER. - * NOTE: Produces or consumes a complete encoding (X.691 (08/2015) #11.1). - */ - ATS_UNALIGNED_BASIC_PER, - ATS_UNALIGNED_CANONICAL_PER, /* * X.693: * XER: XML Encoding Rules. diff --git a/src/asn1/asn1c/asn_bit_data.c b/src/asn1/asn1c/asn_bit_data.c deleted file mode 100644 index 85602f4f..00000000 --- a/src/asn1/asn1c/asn_bit_data.c +++ /dev/null @@ -1,335 +0,0 @@ -/* - * Copyright (c) 2005-2017 Lev Walkin . - * All rights reserved. - * Redistribution and modifications are permitted subject to BSD license. - */ - -#include - -#include "asn1/asn1c/asn_system.h" -#include "asn1/asn1c/asn_internal.h" -#include "asn1/asn1c/asn_bit_data.h" - -/* - * Create a contiguous non-refillable bit data structure. - * Can be freed by FREEMEM(). - */ -asn_bit_data_t * -asn_bit_data_new_contiguous(const void *data, size_t size_bits) { - size_t size_bytes = (size_bits + 7) / 8; - asn_bit_data_t *pd; - uint8_t *bytes; - - /* Get the extensions map */ - pd = CALLOC(1, sizeof(*pd) + size_bytes + 1); - if(!pd) { - return NULL; - } - bytes = (void *)(((char *)pd) + sizeof(*pd)); - memcpy(bytes, data, size_bytes); - bytes[size_bytes] = 0; - pd->buffer = bytes; - pd->nboff = 0; - pd->nbits = size_bits; - - return pd; -} - - -char * -asn_bit_data_string(asn_bit_data_t *pd) { - static char buf[2][32]; - static int n; - n = (n+1) % 2; - snprintf(buf[n], sizeof(buf[n]), - "{m=%" ASN_PRI_SIZE " span %" ASN_PRI_SIZE "[%" ASN_PRI_SIZE - "..%" ASN_PRI_SIZE "] (%" ASN_PRI_SIZE ")}", - pd->moved, ((uintptr_t)(pd->buffer) & 0xf), pd->nboff, pd->nbits, - pd->nbits - pd->nboff); - return buf[n]; -} - -void -asn_get_undo(asn_bit_data_t *pd, int nbits) { - if((ssize_t)pd->nboff < nbits) { - assert((ssize_t)pd->nboff < nbits); - } else { - pd->nboff -= nbits; - pd->moved -= nbits; - } -} - -/* - * Extract a small number of bits (<= 31) from the specified PER data pointer. - */ -int32_t -asn_get_few_bits(asn_bit_data_t *pd, int nbits) { - size_t off; /* Next after last bit offset */ - ssize_t nleft; /* Number of bits left in this stream */ - uint32_t accum; - const uint8_t *buf; - - if(nbits < 0) - return -1; - - nleft = pd->nbits - pd->nboff; - if(nbits > nleft) { - int32_t tailv, vhead; - if(!pd->refill || nbits > 31) return -1; - /* Accumulate unused bytes before refill */ - ASN_DEBUG("Obtain the rest %d bits (want %d)", - (int)nleft, (int)nbits); - tailv = asn_get_few_bits(pd, nleft); - if(tailv < 0) return -1; - /* Refill (replace pd contents with new data) */ - if(pd->refill(pd)) - return -1; - nbits -= nleft; - vhead = asn_get_few_bits(pd, nbits); - /* Combine the rest of previous pd with the head of new one */ - tailv = (tailv << nbits) | vhead; /* Could == -1 */ - return tailv; - } - - /* - * Normalize position indicator. - */ - if(pd->nboff >= 8) { - pd->buffer += (pd->nboff >> 3); - pd->nbits -= (pd->nboff & ~0x07); - pd->nboff &= 0x07; - } - pd->moved += nbits; - pd->nboff += nbits; - off = pd->nboff; - buf = pd->buffer; - - /* - * Extract specified number of bits. - */ - if(off <= 8) - accum = nbits ? (buf[0]) >> (8 - off) : 0; - else if(off <= 16) - accum = ((buf[0] << 8) + buf[1]) >> (16 - off); - else if(off <= 24) - accum = ((buf[0] << 16) + (buf[1] << 8) + buf[2]) >> (24 - off); - else if(off <= 31) - accum = (((uint32_t)buf[0] << 24) + (buf[1] << 16) - + (buf[2] << 8) + (buf[3])) >> (32 - off); - else if(nbits <= 31) { - asn_bit_data_t tpd = *pd; - /* Here are we with our 31-bits limit plus 1..7 bits offset. */ - asn_get_undo(&tpd, nbits); - /* The number of available bits in the stream allow - * for the following operations to take place without - * invoking the ->refill() function */ - accum = asn_get_few_bits(&tpd, nbits - 24) << 24; - accum |= asn_get_few_bits(&tpd, 24); - } else { - asn_get_undo(pd, nbits); - return -1; - } - - accum &= (((uint32_t)1 << nbits) - 1); - - ASN_DEBUG(" [PER got %2d<=%2d bits => span %d %+ld[%d..%d]:%02x (%d) => 0x%x]", - (int)nbits, (int)nleft, - (int)pd->moved, - (((long)pd->buffer) & 0xf), - (int)pd->nboff, (int)pd->nbits, - ((pd->buffer != NULL)?pd->buffer[0]:0), - (int)(pd->nbits - pd->nboff), - (int)accum); - - return accum; -} - -/* - * Extract a large number of bits from the specified PER data pointer. - */ -int -asn_get_many_bits(asn_bit_data_t *pd, uint8_t *dst, int alright, int nbits) { - int32_t value; - - if(alright && (nbits & 7)) { - /* Perform right alignment of a first few bits */ - value = asn_get_few_bits(pd, nbits & 0x07); - if(value < 0) return -1; - *dst++ = value; /* value is already right-aligned */ - nbits &= ~7; - } - - while(nbits) { - if(nbits >= 24) { - value = asn_get_few_bits(pd, 24); - if(value < 0) return -1; - *(dst++) = value >> 16; - *(dst++) = value >> 8; - *(dst++) = value; - nbits -= 24; - } else { - value = asn_get_few_bits(pd, nbits); - if(value < 0) return -1; - if(nbits & 7) { /* implies left alignment */ - value <<= 8 - (nbits & 7), - nbits += 8 - (nbits & 7); - if(nbits > 24) - *dst++ = value >> 24; - } - if(nbits > 16) - *dst++ = value >> 16; - if(nbits > 8) - *dst++ = value >> 8; - *dst++ = value; - break; - } - } - - return 0; -} - -/* - * Put a small number of bits (<= 31). - */ -int -asn_put_few_bits(asn_bit_outp_t *po, uint32_t bits, int obits) { - size_t off; /* Next after last bit offset */ - size_t omsk; /* Existing last byte meaningful bits mask */ - uint8_t *buf; - - if(obits <= 0 || obits >= 32) return obits ? -1 : 0; - - ASN_DEBUG("[PER put %d bits %x to %p+%d bits]", - obits, (int)bits, (void *)po->buffer, (int)po->nboff); - - /* - * Normalize position indicator. - */ - if(po->nboff >= 8) { - po->buffer += (po->nboff >> 3); - po->nbits -= (po->nboff & ~0x07); - po->nboff &= 0x07; - } - - /* - * Flush whole-bytes output, if necessary. - */ - if(po->nboff + obits > po->nbits) { - size_t complete_bytes; - if(!po->buffer) po->buffer = po->tmpspace; - complete_bytes = (po->buffer - po->tmpspace); - ASN_DEBUG("[PER output %ld complete + %ld]", - (long)complete_bytes, (long)po->flushed_bytes); - if(po->output(po->tmpspace, complete_bytes, po->op_key) < 0) - return -1; - if(po->nboff) - po->tmpspace[0] = po->buffer[0]; - po->buffer = po->tmpspace; - po->nbits = 8 * sizeof(po->tmpspace); - po->flushed_bytes += complete_bytes; - } - - /* - * Now, due to sizeof(tmpspace), we are guaranteed large enough space. - */ - buf = po->buffer; - omsk = ~((1 << (8 - po->nboff)) - 1); - off = (po->nboff + obits); - - /* Clear data of debris before meaningful bits */ - bits &= (((uint32_t)1 << obits) - 1); - - ASN_DEBUG("[PER out %d %u/%x (t=%d,o=%d) %x&%x=%x]", obits, - (int)bits, (int)bits, - (int)po->nboff, (int)off, - buf[0], (int)(omsk&0xff), - (int)(buf[0] & omsk)); - - if(off <= 8) /* Completely within 1 byte */ - po->nboff = off, - bits <<= (8 - off), - buf[0] = (buf[0] & omsk) | bits; - else if(off <= 16) - po->nboff = off, - bits <<= (16 - off), - buf[0] = (buf[0] & omsk) | (bits >> 8), - buf[1] = bits; - else if(off <= 24) - po->nboff = off, - bits <<= (24 - off), - buf[0] = (buf[0] & omsk) | (bits >> 16), - buf[1] = bits >> 8, - buf[2] = bits; - else if(off <= 31) - po->nboff = off, - bits <<= (32 - off), - buf[0] = (buf[0] & omsk) | (bits >> 24), - buf[1] = bits >> 16, - buf[2] = bits >> 8, - buf[3] = bits; - else { - if(asn_put_few_bits(po, bits >> (obits - 24), 24)) return -1; - if(asn_put_few_bits(po, bits, obits - 24)) return -1; - } - - ASN_DEBUG("[PER out %u/%x => %02x buf+%ld]", - (int)bits, (int)bits, buf[0], - (long)(po->buffer - po->tmpspace)); - - return 0; -} - - -/* - * Output a large number of bits. - */ -int -asn_put_many_bits(asn_bit_outp_t *po, const uint8_t *src, int nbits) { - - while(nbits) { - uint32_t value; - - if(nbits >= 24) { - value = (src[0] << 16) | (src[1] << 8) | src[2]; - src += 3; - nbits -= 24; - if(asn_put_few_bits(po, value, 24)) - return -1; - } else { - value = src[0]; - if(nbits > 8) - value = (value << 8) | src[1]; - if(nbits > 16) - value = (value << 8) | src[2]; - if(nbits & 0x07) - value >>= (8 - (nbits & 0x07)); - if(asn_put_few_bits(po, value, nbits)) - return -1; - break; - } - } - - return 0; -} - - -int -asn_put_aligned_flush(asn_bit_outp_t *po) { - uint32_t unused_bits = (0x7 & (8 - (po->nboff & 0x07))); - size_t complete_bytes = - (po->buffer ? po->buffer - po->tmpspace : 0) + ((po->nboff + 7) >> 3); - - if(unused_bits) { - po->buffer[po->nboff >> 3] &= ~0u << unused_bits; - } - - if(po->output(po->tmpspace, complete_bytes, po->op_key) < 0) { - return -1; - } else { - po->buffer = po->tmpspace; - po->nboff = 0; - po->nbits = 8 * sizeof(po->tmpspace); - po->flushed_bytes += complete_bytes; - return 0; - } -} diff --git a/src/asn1/asn1c/asn_bit_data.h b/src/asn1/asn1c/asn_bit_data.h deleted file mode 100644 index 54b58077..00000000 --- a/src/asn1/asn1c/asn_bit_data.h +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (c) 2005-2017 Lev Walkin . All rights reserved. - * Redistribution and modifications are permitted subject to BSD license. - */ -#ifndef ASN_BIT_DATA -#define ASN_BIT_DATA - -#include "asn1/asn1c/asn_system.h" /* Platform-specific types */ -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/* - * This structure describes a position inside an incoming PER bit stream. - */ -typedef struct asn_bit_data_s { - const uint8_t *buffer; /* Pointer to the octet stream */ - size_t nboff; /* Bit offset to the meaningful bit */ - size_t nbits; /* Number of bits in the stream */ - size_t moved; /* Number of bits moved through this bit stream */ - int (*refill)(struct asn_bit_data_s *); - void *refill_key; -} asn_bit_data_t; - -/* - * Create a contiguous non-refillable bit data structure. - * Can be freed by FREEMEM(). - */ -asn_bit_data_t *asn_bit_data_new_contiguous(const void *data, size_t size_bits); - -/* - * Extract a small number of bits (<= 31) from the specified PER data pointer. - * This function returns -1 if the specified number of bits could not be - * extracted due to EOD or other conditions. - */ -int32_t asn_get_few_bits(asn_bit_data_t *, int get_nbits); - -/* Undo the immediately preceeding "get_few_bits" operation */ -void asn_get_undo(asn_bit_data_t *, int get_nbits); - -/* - * Extract a large number of bits from the specified PER data pointer. - * This function returns -1 if the specified number of bits could not be - * extracted due to EOD or other conditions. - */ -int asn_get_many_bits(asn_bit_data_t *, uint8_t *dst, int right_align, - int get_nbits); - -/* Non-thread-safe debugging function, don't use it */ -char *asn_bit_data_string(asn_bit_data_t *); - -/* - * This structure supports forming bit output. - */ -typedef struct asn_bit_outp_s { - uint8_t *buffer; /* Pointer into the (tmpspace) */ - size_t nboff; /* Bit offset to the meaningful bit */ - size_t nbits; /* Number of bits left in (tmpspace) */ - uint8_t tmpspace[32]; /* Preliminary storage to hold data */ - int (*output)(const void *data, size_t size, void *op_key); - void *op_key; /* Key for (output) data callback */ - size_t flushed_bytes; /* Bytes already flushed through (output) */ -} asn_bit_outp_t; - -/* Output a small number of bits (<= 31) */ -int asn_put_few_bits(asn_bit_outp_t *, uint32_t bits, int obits); - -/* Output a large number of bits */ -int asn_put_many_bits(asn_bit_outp_t *, const uint8_t *src, int put_nbits); - -/* - * Flush whole bytes (0 or more) through (outper) member. - * The least significant bits which are not used are guaranteed to be set to 0. - * Returns -1 if callback returns -1. Otherwise, 0. - */ -int asn_put_aligned_flush(asn_bit_outp_t *); - -#ifdef __cplusplus -} -#endif - -#endif /* ASN_BIT_DATA */ diff --git a/src/asn1/asn1c/asn_codecs.h b/src/asn1/asn1c/asn_codecs.h index c2fbfe93..f550ae35 100644 --- a/src/asn1/asn1c/asn_codecs.h +++ b/src/asn1/asn1c/asn_codecs.h @@ -25,8 +25,8 @@ struct asn_TYPE_descriptor_s; /* Forward declaration */ * WARNING: if max_stack_size member is set, and you are calling the * function pointers of the asn_TYPE_descriptor_t directly, * this structure must be ALLOCATED ON THE STACK! - * If you can't always satisfy this requirement, use ber_decode(), - * xer_decode() and uper_decode() functions instead. + * If you can't always satisfy this requirement, use ber_decode() + * and xer_decode() functions instead. */ typedef struct asn_codec_ctx_s { /* diff --git a/src/asn1/asn1c/asn_random_fill.h b/src/asn1/asn1c/asn_random_fill.h index 0c80c4f6..e5383b2a 100644 --- a/src/asn1/asn1c/asn_random_fill.h +++ b/src/asn1/asn1c/asn_random_fill.h @@ -23,9 +23,6 @@ struct asn_encoding_constraints_s; * ARGUMENTS: * (max_length) - See (approx_max_length_limit). * (memb_constraints) - Member constraints, if exist. - * The type can be constrained differently according - * to PER and OER specifications, so we find a value - * at the intersection of these constraints. * In case the return differs from ARFILL_OK, the (struct_ptr) contents * and (current_length) value remain in their original state. */ diff --git a/src/asn1/asn1c/constr_CHOICE.c b/src/asn1/asn1c/constr_CHOICE.c index 60efb780..c55492d5 100644 --- a/src/asn1/asn1c/constr_CHOICE.c +++ b/src/asn1/asn1c/constr_CHOICE.c @@ -7,7 +7,6 @@ #include "asn1/asn1c/asn_internal.h" #include "asn1/asn1c/constr_CHOICE.h" -#include "asn1/asn1c/per_opentype.h" /* * Number of bytes left for this structure. @@ -832,188 +831,6 @@ cb_failed: ASN__ENCODE_FAILED; } -asn_dec_rval_t -CHOICE_decode_uper(const asn_codec_ctx_t *opt_codec_ctx, - const asn_TYPE_descriptor_t *td, - const asn_per_constraints_t *constraints, void **sptr, - asn_per_data_t *pd) { - const asn_CHOICE_specifics_t *specs = - (const asn_CHOICE_specifics_t *)td->specifics; - asn_dec_rval_t rv; - const asn_per_constraint_t *ct; - asn_TYPE_member_t *elm; /* CHOICE's element */ - void *memb_ptr; - void **memb_ptr2; - void *st = *sptr; - int value; - - if(ASN__STACK_OVERFLOW_CHECK(opt_codec_ctx)) - ASN__DECODE_FAILED; - - /* - * Create the target structure if it is not present already. - */ - if(!st) { - st = *sptr = CALLOC(1, specs->struct_size); - if(!st) ASN__DECODE_FAILED; - } - - if(constraints) ct = &constraints->value; - else if(td->encoding_constraints.per_constraints) ct = &td->encoding_constraints.per_constraints->value; - else ct = 0; - - if(ct && ct->flags & APC_EXTENSIBLE) { - value = per_get_few_bits(pd, 1); - if(value < 0) ASN__DECODE_STARVED; - if(value) ct = 0; /* Not restricted */ - } - - if(ct && ct->range_bits >= 0) { - value = per_get_few_bits(pd, ct->range_bits); - if(value < 0) ASN__DECODE_STARVED; - ASN_DEBUG("CHOICE %s got index %d in range %d", - td->name, value, ct->range_bits); - if(value > ct->upper_bound) - ASN__DECODE_FAILED; - } else { - if(specs->ext_start == -1) - ASN__DECODE_FAILED; - value = uper_get_nsnnwn(pd); - if(value < 0) ASN__DECODE_STARVED; - value += specs->ext_start; - if((unsigned)value >= td->elements_count) - ASN__DECODE_FAILED; - } - - /* Adjust if canonical order is different from natural order */ - if(specs->from_canonical_order) { - ASN_DEBUG("CHOICE presence from wire %d", value); - value = specs->from_canonical_order[value]; - ASN_DEBUG("CHOICE presence index effective %d", value); - } - - /* Set presence to be able to free it later */ - _set_present_idx(st, specs->pres_offset, specs->pres_size, value + 1); - - elm = &td->elements[value]; - if(elm->flags & ATF_POINTER) { - /* Member is a pointer to another structure */ - memb_ptr2 = (void **)((char *)st + elm->memb_offset); - } else { - memb_ptr = (char *)st + elm->memb_offset; - memb_ptr2 = &memb_ptr; - } - ASN_DEBUG("Discovered CHOICE %s encodes %s", td->name, elm->name); - - if(ct && ct->range_bits >= 0) { - rv = elm->type->op->uper_decoder(opt_codec_ctx, elm->type, - elm->encoding_constraints.per_constraints, memb_ptr2, pd); - } else { - rv = uper_open_type_get(opt_codec_ctx, elm->type, - elm->encoding_constraints.per_constraints, memb_ptr2, pd); - } - - if(rv.code != RC_OK) - ASN_DEBUG("Failed to decode %s in %s (CHOICE) %d", - elm->name, td->name, rv.code); - return rv; -} - -asn_enc_rval_t -CHOICE_encode_uper(const asn_TYPE_descriptor_t *td, - const asn_per_constraints_t *constraints, const void *sptr, - asn_per_outp_t *po) { - const asn_CHOICE_specifics_t *specs = (const asn_CHOICE_specifics_t *)td->specifics; - asn_TYPE_member_t *elm; /* CHOICE's element */ - const asn_per_constraint_t *ct; - const void *memb_ptr; - unsigned present; - int present_enc; - - if(!sptr) ASN__ENCODE_FAILED; - - ASN_DEBUG("Encoding %s as CHOICE", td->name); - - if(constraints) ct = &constraints->value; - else if(td->encoding_constraints.per_constraints) - ct = &td->encoding_constraints.per_constraints->value; - else ct = 0; - - present = _fetch_present_idx(sptr, specs->pres_offset, specs->pres_size); - - /* - * If the structure was not initialized properly, it cannot be encoded: - * can't deduce what to encode in the choice type. - */ - if(present == 0 || present > td->elements_count) - ASN__ENCODE_FAILED; - else - present--; - - ASN_DEBUG("Encoding %s CHOICE element %d", td->name, present); - - /* Adjust if canonical order is different from natural order */ - if(specs->to_canonical_order) - present_enc = specs->to_canonical_order[present]; - else - present_enc = present; - - if(ct && ct->range_bits >= 0) { - if(present_enc < ct->lower_bound - || present_enc > ct->upper_bound) { - if(ct->flags & APC_EXTENSIBLE) { - ASN_DEBUG( - "CHOICE member %d (enc %d) is an extension (%ld..%ld)", - present, present_enc, ct->lower_bound, ct->upper_bound); - if(per_put_few_bits(po, 1, 1)) - ASN__ENCODE_FAILED; - } else { - ASN__ENCODE_FAILED; - } - ct = 0; - } - } - if(ct && ct->flags & APC_EXTENSIBLE) { - ASN_DEBUG("CHOICE member %d (enc %d) is not an extension (%ld..%ld)", - present, present_enc, ct->lower_bound, ct->upper_bound); - if(per_put_few_bits(po, 0, 1)) - ASN__ENCODE_FAILED; - } - - - elm = &td->elements[present]; - ASN_DEBUG("CHOICE member \"%s\" %d (as %d)", elm->name, present, - present_enc); - if(elm->flags & ATF_POINTER) { - /* Member is a pointer to another structure */ - memb_ptr = - *(const void *const *)((const char *)sptr + elm->memb_offset); - if(!memb_ptr) ASN__ENCODE_FAILED; - } else { - memb_ptr = (const char *)sptr + elm->memb_offset; - } - - if(ct && ct->range_bits >= 0) { - if(per_put_few_bits(po, present_enc, ct->range_bits)) - ASN__ENCODE_FAILED; - - return elm->type->op->uper_encoder( - elm->type, elm->encoding_constraints.per_constraints, memb_ptr, po); - } else { - asn_enc_rval_t rval; - if(specs->ext_start == -1) ASN__ENCODE_FAILED; - if(uper_put_nsnnwn(po, present_enc - specs->ext_start)) - ASN__ENCODE_FAILED; - if(uper_open_type_put(elm->type, - elm->encoding_constraints.per_constraints, - memb_ptr, po)) - ASN__ENCODE_FAILED; - rval.encoded = 0; - ASN__ENCODED_OK(rval); - } -} - - int CHOICE_print(const asn_TYPE_descriptor_t *td, const void *sptr, int ilevel, asn_app_consume_bytes_f *cb, void *app_key) { @@ -1324,20 +1141,6 @@ asn_TYPE_operation_t asn_OP_CHOICE = { CHOICE_encode_der, CHOICE_decode_xer, CHOICE_encode_xer, -#ifdef ASN_DISABLE_OER_SUPPORT - 0, - 0, -#else - CHOICE_decode_oer, - CHOICE_encode_oer, -#endif /* ASN_DISABLE_OER_SUPPORT */ -#ifdef ASN_DISABLE_PER_SUPPORT - 0, - 0, -#else - CHOICE_decode_uper, - CHOICE_encode_uper, -#endif /* ASN_DISABLE_PER_SUPPORT */ CHOICE_random_fill, CHOICE_outmost_tag }; diff --git a/src/asn1/asn1c/constr_CHOICE.h b/src/asn1/asn1c/constr_CHOICE.h index 59b6fa81..29984526 100644 --- a/src/asn1/asn1c/constr_CHOICE.h +++ b/src/asn1/asn1c/constr_CHOICE.h @@ -26,10 +26,6 @@ typedef struct asn_CHOICE_specifics_s { const asn_TYPE_tag2member_t *tag2el; unsigned tag2el_count; - /* Canonical ordering of CHOICE elements, for PER */ - const unsigned *to_canonical_order; - const unsigned *from_canonical_order; - /* * Extensions-related stuff. */ @@ -47,10 +43,6 @@ ber_type_decoder_f CHOICE_decode_ber; der_type_encoder_f CHOICE_encode_der; xer_type_decoder_f CHOICE_decode_xer; xer_type_encoder_f CHOICE_encode_xer; -oer_type_decoder_f CHOICE_decode_oer; -oer_type_encoder_f CHOICE_encode_oer; -per_type_decoder_f CHOICE_decode_uper; -per_type_encoder_f CHOICE_encode_uper; asn_outmost_tag_f CHOICE_outmost_tag; asn_random_fill_f CHOICE_random_fill; extern asn_TYPE_operation_t asn_OP_CHOICE; diff --git a/src/asn1/asn1c/constr_CHOICE_oer.c b/src/asn1/asn1c/constr_CHOICE_oer.c deleted file mode 100644 index 0b7bea90..00000000 --- a/src/asn1/asn1c/constr_CHOICE_oer.c +++ /dev/null @@ -1,379 +0,0 @@ -/* - * Copyright (c) 2017 Lev Walkin . - * All rights reserved. - * Redistribution and modifications are permitted subject to BSD license. - */ -#ifndef ASN_DISABLE_OER_SUPPORT - -#include "asn1/asn1c/asn_internal.h" -#include "asn1/asn1c/constr_CHOICE.h" - -/* - * Return a standardized complex structure. - */ -#undef RETURN -#define RETURN(_code) \ - do { \ - asn_dec_rval_t rval; \ - rval.code = _code; \ - rval.consumed = consumed_myself; \ - return rval; \ - } while(0) - -#undef ADVANCE -#define ADVANCE(num_bytes) \ - do { \ - size_t num = num_bytes; \ - ptr = ((const char *)ptr) + num; \ - size -= num; \ - consumed_myself += num; \ - } while(0) - -/* - * Switch to the next phase of parsing. - */ -#undef NEXT_PHASE -#define NEXT_PHASE(ctx) \ - do { \ - ctx->phase++; \ - ctx->step = 0; \ - } while(0) -#undef SET_PHASE -#define SET_PHASE(ctx, value) \ - do { \ - ctx->phase = value; \ - ctx->step = 0; \ - } while(0) - -/* - * Tags are canonically sorted in the tag to member table. - */ -static int -_search4tag(const void *ap, const void *bp) { - const asn_TYPE_tag2member_t *a = (const asn_TYPE_tag2member_t *)ap; - const asn_TYPE_tag2member_t *b = (const asn_TYPE_tag2member_t *)bp; - - int a_class = BER_TAG_CLASS(a->el_tag); - int b_class = BER_TAG_CLASS(b->el_tag); - - if(a_class == b_class) { - ber_tlv_tag_t a_value = BER_TAG_VALUE(a->el_tag); - ber_tlv_tag_t b_value = BER_TAG_VALUE(b->el_tag); - - if(a_value == b_value) - return 0; - else if(a_value < b_value) - return -1; - else - return 1; - } else if(a_class < b_class) { - return -1; - } else { - return 1; - } -} - -/* - * X.696 (08/2015) #8.7 Encoding of tags - */ -static ssize_t -oer_fetch_tag(const void *ptr, size_t size, ber_tlv_tag_t *tag_r) { - ber_tlv_tag_t val; - ber_tlv_tag_t tclass; - size_t skipped; - - if(size == 0) - return 0; - - val = *(const uint8_t *)ptr; - tclass = (val >> 6); - if((val & 0x3F) != 0x3F) { - /* #8.7.1 */ - *tag_r = ((val & 0x3F) << 2) | tclass; - return 1; - } - - /* - * Each octet contains 7 bits of useful information. - * The MSB is 0 if it is the last octet of the tag. - */ - for(val = 0, ptr = ((const char *)ptr) + 1, skipped = 2; skipped <= size; - ptr = ((const char *)ptr) + 1, skipped++) { - unsigned int oct = *(const uint8_t *)ptr; - if(oct & 0x80) { - val = (val << 7) | (oct & 0x7F); - /* - * Make sure there are at least 9 bits spare - * at the MS side of a value. - */ - if(val >> ((8 * sizeof(val)) - 9)) { - /* - * We would not be able to accomodate - * any more tag bits. - */ - return -1; - } - } else { - val = (val << 7) | oct; - *tag_r = (val << 2) | tclass; - return skipped; - } - } - - return 0; /* Want more */ -} - -asn_dec_rval_t -CHOICE_decode_oer(const asn_codec_ctx_t *opt_codec_ctx, - const asn_TYPE_descriptor_t *td, - const asn_oer_constraints_t *constraints, void **struct_ptr, - const void *ptr, size_t size) { - /* - * Bring closer parts of structure description. - */ - const asn_CHOICE_specifics_t *specs = - (const asn_CHOICE_specifics_t *)td->specifics; - asn_TYPE_member_t *elements = td->elements; - - /* - * Parts of the structure being constructed. - */ - void *st = *struct_ptr; /* Target structure. */ - asn_struct_ctx_t *ctx; /* Decoder context */ - - ssize_t consumed_myself = 0; /* Consumed bytes from ptr */ - - (void)constraints; - - ASN_DEBUG("Decoding %s as CHOICE", td->name); - - /* - * Create the target structure if it is not present already. - */ - if(st == 0) { - st = *struct_ptr = CALLOC(1, specs->struct_size); - if(st == 0) { - RETURN(RC_FAIL); - } - } - - /* - * Restore parsing context. - */ - ctx = (asn_struct_ctx_t *)((char *)st + specs->ctx_offset); - switch(ctx->phase) { - case 0: { - /* - * Discover the tag. - */ - ber_tlv_tag_t tlv_tag; /* T from TLV */ - ssize_t tag_len; /* Length of TLV's T */ - - tag_len = oer_fetch_tag(ptr, size, &tlv_tag); - switch(tag_len) { - case 0: - ASN__DECODE_STARVED; - case -1: - ASN__DECODE_FAILED; - } - - do { - const asn_TYPE_tag2member_t *t2m; - asn_TYPE_tag2member_t key = {0, 0, 0, 0}; - key.el_tag = tlv_tag; - - t2m = (const asn_TYPE_tag2member_t *)bsearch( - &key, specs->tag2el, specs->tag2el_count, - sizeof(specs->tag2el[0]), _search4tag); - if(t2m) { - /* - * Found the element corresponding to the tag. - */ - NEXT_PHASE(ctx); - ctx->step = t2m->el_no; - break; - } else if(specs->ext_start == -1) { - ASN_DEBUG( - "Unexpected tag %s " - "in non-extensible CHOICE %s", - ber_tlv_tag_string(tlv_tag), td->name); - RETURN(RC_FAIL); - } else { - /* Skip open type extension */ - ASN_DEBUG( - "Not implemented skipping open type extension for tag %s", - ber_tlv_tag_string(tlv_tag)); - RETURN(RC_FAIL); - } - } while(0); - - - ADVANCE(tag_len); - } - /* Fall through */ - case 1: { - asn_TYPE_member_t *elm = &elements[ctx->step]; /* CHOICE's element */ - void *memb_ptr; /* Pointer to the member */ - void **memb_ptr2; /* Pointer to that pointer */ - asn_dec_rval_t rval; - - /* - * Compute the position of the member inside a structure, - * and also a type of containment (it may be contained - * as pointer or using inline inclusion). - */ - if(elm->flags & ATF_POINTER) { - /* Member is a pointer to another structure */ - memb_ptr2 = (void **)((char *)st + elm->memb_offset); - } else { - /* - * A pointer to a pointer - * holding the start of the structure - */ - memb_ptr = (char *)st + elm->memb_offset; - memb_ptr2 = &memb_ptr; - } - - /* Set presence to be able to free it properly at any time */ - (void)CHOICE_variant_set_presence(td, st, ctx->step + 1); - - if(specs->ext_start >= 0 && specs->ext_start <= ctx->step) { - ssize_t got = - oer_open_type_get(opt_codec_ctx, elm->type, - elm->encoding_constraints.oer_constraints, - memb_ptr2, ptr, size); - if(got < 0) ASN__DECODE_FAILED; - if(got == 0) ASN__DECODE_STARVED; - rval.code = RC_OK; - rval.consumed = got; - } else { - rval = elm->type->op->oer_decoder( - opt_codec_ctx, elm->type, - elm->encoding_constraints.oer_constraints, memb_ptr2, ptr, - size); - } - rval.consumed += consumed_myself; - switch(rval.code) { - case RC_OK: - NEXT_PHASE(ctx); - case RC_WMORE: - break; - case RC_FAIL: - SET_PHASE(ctx, 3); /* => 3 */ - } - return rval; - } - case 2: - /* Already decoded everything */ - RETURN(RC_OK); - case 3: - /* Failed to decode, after all */ - RETURN(RC_FAIL); - } - - RETURN(RC_FAIL); -} - -/* - * X.696 (08/2015) #8.7 Encoding of tags - */ -static ssize_t -oer_put_tag(ber_tlv_tag_t tag, asn_app_consume_bytes_f *cb, void *app_key) { - uint8_t tclass = BER_TAG_CLASS(tag); - ber_tlv_tag_t tval = BER_TAG_VALUE(tag); - - if(tval < 0x3F) { - uint8_t b = (uint8_t)((tclass << 6) | tval); - if(cb(&b, 1, app_key) < 0) { - return -1; - } - return 1; - } else { - uint8_t buf[1 + 2 * sizeof(tval)]; - uint8_t *b = &buf[sizeof(buf)-1]; /* Last addressable */ - size_t encoded; - for(; ; tval >>= 7) { - if(tval >> 7) { - *b-- = 0x80 | (tval & 0x7f); - } else { - *b-- = tval & 0x7f; - break; - } - } - *b = (uint8_t)((tclass << 6) | 0x3F); - encoded = sizeof(buf) - (b - buf); - if(cb(b, encoded, app_key) < 0) { - return -1; - } - return encoded; - } - -} - -/* - * Encode as Canonical OER. - */ -asn_enc_rval_t -CHOICE_encode_oer(const asn_TYPE_descriptor_t *td, - const asn_oer_constraints_t *constraints, const void *sptr, - asn_app_consume_bytes_f *cb, void *app_key) { - const asn_CHOICE_specifics_t *specs = - (const asn_CHOICE_specifics_t *)td->specifics; - asn_TYPE_member_t *elm; /* CHOICE element */ - unsigned present; - const void *memb_ptr; - ber_tlv_tag_t tag; - ssize_t tag_len; - asn_enc_rval_t er = {0, 0, 0}; - - (void)constraints; - - if(!sptr) ASN__ENCODE_FAILED; - - ASN_DEBUG("OER %s encoding as CHOICE", td->name); - - present = CHOICE_variant_get_presence(td, sptr); - if(present == 0 || present > td->elements_count) { - ASN_DEBUG("CHOICE %s member is not selected", td->name); - ASN__ENCODE_FAILED; - } - - elm = &td->elements[present-1]; - if(elm->flags & ATF_POINTER) { - memb_ptr = - *(const void *const *)((const char *)sptr + elm->memb_offset); - if(memb_ptr == 0) { - /* Mandatory element absent */ - ASN__ENCODE_FAILED; - } - } else { - memb_ptr = (const void *)((const char *)sptr + elm->memb_offset); - } - - tag = asn_TYPE_outmost_tag(elm->type, memb_ptr, elm->tag_mode, elm->tag); - if(tag == 0) { - ASN__ENCODE_FAILED; - } - - tag_len = oer_put_tag(tag, cb, app_key); - if(tag_len < 0) { - ASN__ENCODE_FAILED; - } - - if(specs->ext_start >= 0 && (unsigned)specs->ext_start <= (present-1)) { - ssize_t encoded = oer_open_type_put(elm->type, - elm->encoding_constraints.oer_constraints, - memb_ptr, cb, app_key); - if(encoded < 0) ASN__ENCODE_FAILED; - er.encoded = tag_len + encoded; - } else { - er = elm->type->op->oer_encoder( - elm->type, elm->encoding_constraints.oer_constraints, memb_ptr, cb, - app_key); - if(er.encoded >= 0) er.encoded += tag_len; - } - - return er; -} - -#endif /* ASN_DISABLE_OER_SUPPORT */ diff --git a/src/asn1/asn1c/constr_SEQUENCE.c b/src/asn1/asn1c/constr_SEQUENCE.c index 73bfd8cc..2a3667fb 100644 --- a/src/asn1/asn1c/constr_SEQUENCE.c +++ b/src/asn1/asn1c/constr_SEQUENCE.c @@ -9,7 +9,6 @@ #include "asn1/asn1c/asn_internal.h" #include "asn1/asn1c/constr_SEQUENCE.h" #include "asn1/asn1c/OPEN_TYPE.h" -#include "asn1/asn1c/per_opentype.h" /* * Number of bytes left for this structure. @@ -1073,422 +1072,6 @@ SEQUENCE_constraint(const asn_TYPE_descriptor_t *td, const void *sptr, return 0; } -#ifndef ASN_DISABLE_PER_SUPPORT - -asn_dec_rval_t -SEQUENCE_decode_uper(const asn_codec_ctx_t *opt_codec_ctx, - const asn_TYPE_descriptor_t *td, - const asn_per_constraints_t *constraints, void **sptr, - asn_per_data_t *pd) { - const asn_SEQUENCE_specifics_t *specs = (const asn_SEQUENCE_specifics_t *)td->specifics; - void *st = *sptr; /* Target structure. */ - int extpresent; /* Extension additions are present */ - uint8_t *opres; /* Presence of optional root members */ - asn_per_data_t opmd; - asn_dec_rval_t rv; - size_t edx; - - (void)constraints; - - if(ASN__STACK_OVERFLOW_CHECK(opt_codec_ctx)) - ASN__DECODE_FAILED; - - if(!st) { - st = *sptr = CALLOC(1, specs->struct_size); - if(!st) ASN__DECODE_FAILED; - } - - ASN_DEBUG("Decoding %s as SEQUENCE (UPER)", td->name); - - /* Handle extensions */ - if(specs->first_extension < 0) { - extpresent = 0; - } else { - extpresent = per_get_few_bits(pd, 1); - if(extpresent < 0) ASN__DECODE_STARVED; - } - - /* Prepare a place and read-in the presence bitmap */ - memset(&opmd, 0, sizeof(opmd)); - if(specs->roms_count) { - opres = (uint8_t *)MALLOC(((specs->roms_count + 7) >> 3) + 1); - if(!opres) ASN__DECODE_FAILED; - /* Get the presence map */ - if(per_get_many_bits(pd, opres, 0, specs->roms_count)) { - FREEMEM(opres); - ASN__DECODE_STARVED; - } - opmd.buffer = opres; - opmd.nbits = specs->roms_count; - ASN_DEBUG("Read in presence bitmap for %s of %d bits (%x..)", - td->name, specs->roms_count, *opres); - } else { - opres = 0; - } - - /* - * Get the sequence ROOT elements. - */ - for(edx = 0; - edx < (specs->first_extension < 0 ? td->elements_count - : (size_t)specs->first_extension); - edx++) { - asn_TYPE_member_t *elm = &td->elements[edx]; - void *memb_ptr; /* Pointer to the member */ - void **memb_ptr2; /* Pointer to that pointer */ - - assert(!IN_EXTENSION_GROUP(specs, edx)); - - /* Fetch the pointer to this member */ - if(elm->flags & ATF_POINTER) { - memb_ptr2 = (void **)((char *)st + elm->memb_offset); - } else { - memb_ptr = (char *)st + elm->memb_offset; - memb_ptr2 = &memb_ptr; - } - - /* Deal with optionality */ - if(elm->optional) { - int present = per_get_few_bits(&opmd, 1); - ASN_DEBUG("Member %s->%s is optional, p=%d (%d->%d)", - td->name, elm->name, present, - (int)opmd.nboff, (int)opmd.nbits); - if(present == 0) { - /* This element is not present */ - if(elm->default_value_set) { - /* Fill-in DEFAULT */ - if(elm->default_value_set(memb_ptr2)) { - FREEMEM(opres); - ASN__DECODE_FAILED; - } - ASN_DEBUG("Filled-in default"); - } - /* The member is just not present */ - continue; - } - /* Fall through */ - } - - /* Fetch the member from the stream */ - ASN_DEBUG("Decoding member \"%s\" in %s", elm->name, td->name); - - if(elm->flags & ATF_OPEN_TYPE) { - rv = OPEN_TYPE_uper_get(opt_codec_ctx, td, st, elm, pd); - } else { - rv = elm->type->op->uper_decoder(opt_codec_ctx, elm->type, - elm->encoding_constraints.per_constraints, memb_ptr2, pd); - } - if(rv.code != RC_OK) { - ASN_DEBUG("Failed decode %s in %s", - elm->name, td->name); - FREEMEM(opres); - return rv; - } - } - - /* Optionality map is not needed anymore */ - FREEMEM(opres); - - /* - * Deal with extensions. - */ - if(extpresent) { - ssize_t bmlength; - uint8_t *epres; /* Presence of extension members */ - asn_per_data_t epmd; - - bmlength = uper_get_nslength(pd); - if(bmlength < 0) ASN__DECODE_STARVED; - - ASN_DEBUG("Extensions %" ASN_PRI_SSIZE " present in %s", bmlength, td->name); - - epres = (uint8_t *)MALLOC((bmlength + 15) >> 3); - if(!epres) ASN__DECODE_STARVED; - - /* Get the extensions map */ - if(per_get_many_bits(pd, epres, 0, bmlength)) { - FREEMEM(epres); - ASN__DECODE_STARVED; - } - - memset(&epmd, 0, sizeof(epmd)); - epmd.buffer = epres; - epmd.nbits = bmlength; - ASN_DEBUG("Read in extensions bitmap for %s of %ld bits (%x..)", - td->name, (long)bmlength, *epres); - - /* Go over extensions and read them in */ - for(edx = specs->first_extension; edx < td->elements_count; edx++) { - asn_TYPE_member_t *elm = &td->elements[edx]; - void *memb_ptr; /* Pointer to the member */ - void **memb_ptr2; /* Pointer to that pointer */ - int present; - - /* Fetch the pointer to this member */ - if(elm->flags & ATF_POINTER) { - memb_ptr2 = (void **)((char *)st + elm->memb_offset); - } else { - memb_ptr = (void *)((char *)st + elm->memb_offset); - memb_ptr2 = &memb_ptr; - } - - present = per_get_few_bits(&epmd, 1); - if(present <= 0) { - if(present < 0) break; /* No more extensions */ - continue; - } - - ASN_DEBUG("Decoding member %s in %s %p", elm->name, td->name, - *memb_ptr2); - rv = uper_open_type_get(opt_codec_ctx, elm->type, - elm->encoding_constraints.per_constraints, - memb_ptr2, pd); - if(rv.code != RC_OK) { - FREEMEM(epres); - return rv; - } - } - - /* Skip over overflow extensions which aren't present - * in this system's version of the protocol */ - for(;;) { - ASN_DEBUG("Getting overflow extensions"); - switch(per_get_few_bits(&epmd, 1)) { - case -1: break; - case 0: continue; - default: - if(uper_open_type_skip(opt_codec_ctx, pd)) { - FREEMEM(epres); - ASN__DECODE_STARVED; - } - ASN_DEBUG("Skipped overflow extension"); - continue; - } - break; - } - - FREEMEM(epres); - } - - if(specs->first_extension >= 0) { - unsigned i; - /* Fill DEFAULT members in extensions */ - for(i = specs->roms_count; i < specs->roms_count + specs->aoms_count; - i++) { - asn_TYPE_member_t *elm; - void **memb_ptr2; /* Pointer to member pointer */ - - edx = specs->oms[i]; - elm = &td->elements[edx]; - - if(!elm->default_value_set) continue; - - /* Fetch the pointer to this member */ - if(elm->flags & ATF_POINTER) { - memb_ptr2 = (void **)((char *)st + elm->memb_offset); - if(*memb_ptr2) continue; - } else { - continue; /* Extensions are all optionals */ - } - - /* Set default value */ - if(elm->default_value_set(memb_ptr2)) { - ASN__DECODE_FAILED; - } - } - } - - rv.consumed = 0; - rv.code = RC_OK; - return rv; -} - -static int -SEQUENCE__handle_extensions(const asn_TYPE_descriptor_t *td, const void *sptr, - asn_per_outp_t *po1, asn_per_outp_t *po2) { - const asn_SEQUENCE_specifics_t *specs = - (const asn_SEQUENCE_specifics_t *)td->specifics; - int exts_present = 0; - int exts_count = 0; - size_t edx; - - if(specs->first_extension < 0) { - return 0; - } - - /* Find out which extensions are present */ - for(edx = specs->first_extension; edx < td->elements_count; edx++) { - asn_TYPE_member_t *elm = &td->elements[edx]; - const void *memb_ptr; /* Pointer to the member */ - const void *const *memb_ptr2; /* Pointer to that pointer */ - int present; - - /* Fetch the pointer to this member */ - if(elm->flags & ATF_POINTER) { - memb_ptr2 = - (const void *const *)((const char *)sptr + elm->memb_offset); - present = (*memb_ptr2 != 0); - } else { - memb_ptr = (const void *)((const char *)sptr + elm->memb_offset); - memb_ptr2 = &memb_ptr; - present = 1; - } - - ASN_DEBUG("checking %s:%s (@%" ASN_PRI_SIZE ") present => %d", elm->name, - elm->type->name, edx, present); - exts_count++; - exts_present += present; - - /* Encode as presence marker */ - if(po1 && per_put_few_bits(po1, present, 1)) { - return -1; - } - /* Encode as open type field */ - if(po2 && present - && uper_open_type_put(elm->type, - elm->encoding_constraints.per_constraints, - *memb_ptr2, po2)) - return -1; - } - - return exts_present ? exts_count : 0; -} - -asn_enc_rval_t -SEQUENCE_encode_uper(const asn_TYPE_descriptor_t *td, - const asn_per_constraints_t *constraints, const void *sptr, - asn_per_outp_t *po) { - const asn_SEQUENCE_specifics_t *specs - = (const asn_SEQUENCE_specifics_t *)td->specifics; - asn_enc_rval_t er; - int n_extensions; - size_t edx; - size_t i; - - (void)constraints; - - if(!sptr) - ASN__ENCODE_FAILED; - - er.encoded = 0; - - ASN_DEBUG("Encoding %s as SEQUENCE (UPER)", td->name); - - /* - * X.691#18.1 Whether structure is extensible - * and whether to encode extensions - */ - if(specs->first_extension < 0) { - n_extensions = 0; /* There are no extensions to encode */ - } else { - n_extensions = SEQUENCE__handle_extensions(td, sptr, 0, 0); - if(n_extensions < 0) ASN__ENCODE_FAILED; - if(per_put_few_bits(po, n_extensions ? 1 : 0, 1)) { - ASN__ENCODE_FAILED; - } - } - - /* Encode a presence bitmap */ - for(i = 0; i < specs->roms_count; i++) { - asn_TYPE_member_t *elm; - const void *memb_ptr; /* Pointer to the member */ - const void *const *memb_ptr2; /* Pointer to that pointer */ - int present; - - edx = specs->oms[i]; - elm = &td->elements[edx]; - - /* Fetch the pointer to this member */ - if(elm->flags & ATF_POINTER) { - memb_ptr2 = - (const void *const *)((const char *)sptr + elm->memb_offset); - present = (*memb_ptr2 != 0); - } else { - memb_ptr = (const void *)((const char *)sptr + elm->memb_offset); - memb_ptr2 = &memb_ptr; - present = 1; - } - - /* Eliminate default values */ - if(present && elm->default_value_cmp - && elm->default_value_cmp(*memb_ptr2) == 0) - present = 0; - - ASN_DEBUG("Element %s %s %s->%s is %s", - elm->flags & ATF_POINTER ? "ptr" : "inline", - elm->default_value_cmp ? "def" : "wtv", - td->name, elm->name, present ? "present" : "absent"); - if(per_put_few_bits(po, present, 1)) - ASN__ENCODE_FAILED; - } - - /* - * Encode the sequence ROOT elements. - */ - ASN_DEBUG("first_extension = %d, elements = %d", specs->first_extension, - td->elements_count); - for(edx = 0; - edx < ((specs->first_extension < 0) ? td->elements_count - : (size_t)specs->first_extension); - edx++) { - asn_TYPE_member_t *elm = &td->elements[edx]; - const void *memb_ptr; /* Pointer to the member */ - const void *const *memb_ptr2; /* Pointer to that pointer */ - - ASN_DEBUG("About to encode %s", elm->type->name); - - /* Fetch the pointer to this member */ - if(elm->flags & ATF_POINTER) { - memb_ptr2 = - (const void *const *)((const char *)sptr + elm->memb_offset); - if(!*memb_ptr2) { - ASN_DEBUG("Element %s %" ASN_PRI_SIZE " not present", - elm->name, edx); - if(elm->optional) - continue; - /* Mandatory element is missing */ - ASN__ENCODE_FAILED; - } - } else { - memb_ptr = (const void *)((const char *)sptr + elm->memb_offset); - memb_ptr2 = &memb_ptr; - } - - /* Eliminate default values */ - if(elm->default_value_cmp && elm->default_value_cmp(*memb_ptr2) == 0) - continue; - - ASN_DEBUG("Encoding %s->%s:%s", td->name, elm->name, elm->type->name); - er = elm->type->op->uper_encoder( - elm->type, elm->encoding_constraints.per_constraints, *memb_ptr2, - po); - if(er.encoded == -1) return er; - } - - /* No extensions to encode */ - if(!n_extensions) ASN__ENCODED_OK(er); - - ASN_DEBUG("Length of extensions %d bit-map", n_extensions); - /* #18.8. Write down the presence bit-map length. */ - if(uper_put_nslength(po, n_extensions)) - ASN__ENCODE_FAILED; - - ASN_DEBUG("Bit-map of %d elements", n_extensions); - /* #18.7. Encoding the extensions presence bit-map. */ - /* TODO (asn1c) act upon NOTE in #18.7 for canonical PER */ - if(SEQUENCE__handle_extensions(td, sptr, po, 0) != n_extensions) - ASN__ENCODE_FAILED; - - ASN_DEBUG("Writing %d extensions", n_extensions); - /* #18.9. Encode extensions as open type fields. */ - if(SEQUENCE__handle_extensions(td, sptr, 0, po) != n_extensions) - ASN__ENCODE_FAILED; - - ASN__ENCODED_OK(er); -} - -#endif /* ASN_DISABLE_PER_SUPPORT */ - int SEQUENCE_compare(const asn_TYPE_descriptor_t *td, const void *aptr, const void *bptr) { @@ -1541,20 +1124,6 @@ asn_TYPE_operation_t asn_OP_SEQUENCE = { SEQUENCE_encode_der, SEQUENCE_decode_xer, SEQUENCE_encode_xer, -#ifdef ASN_DISABLE_OER_SUPPORT - 0, - 0, -#else - SEQUENCE_decode_oer, - SEQUENCE_encode_oer, -#endif /* ASN_DISABLE_OER_SUPPORT */ -#ifdef ASN_DISABLE_PER_SUPPORT - 0, - 0, -#else - SEQUENCE_decode_uper, - SEQUENCE_encode_uper, -#endif /* ASN_DISABLE_PER_SUPPORT */ SEQUENCE_random_fill, 0 /* Use generic outmost tag fetcher */ }; diff --git a/src/asn1/asn1c/constr_SEQUENCE.h b/src/asn1/asn1c/constr_SEQUENCE.h index 89ffc6f2..a6f87897 100644 --- a/src/asn1/asn1c/constr_SEQUENCE.h +++ b/src/asn1/asn1c/constr_SEQUENCE.h @@ -24,14 +24,6 @@ typedef struct asn_SEQUENCE_specifics_s { const asn_TYPE_tag2member_t *tag2el; unsigned tag2el_count; - /* - * Optional members of the extensions root (roms) or additions (aoms). - * Meaningful for PER. - */ - const int *oms; /* Optional MemberS */ - unsigned roms_count; /* Root optional members count */ - unsigned aoms_count; /* Additions optional members count */ - /* * Description of an extensions group. * Root components are clustered at the beginning of the structure, @@ -52,10 +44,6 @@ ber_type_decoder_f SEQUENCE_decode_ber; der_type_encoder_f SEQUENCE_encode_der; xer_type_decoder_f SEQUENCE_decode_xer; xer_type_encoder_f SEQUENCE_encode_xer; -oer_type_decoder_f SEQUENCE_decode_oer; -oer_type_encoder_f SEQUENCE_encode_oer; -per_type_decoder_f SEQUENCE_decode_uper; -per_type_encoder_f SEQUENCE_encode_uper; asn_random_fill_f SEQUENCE_random_fill; extern asn_TYPE_operation_t asn_OP_SEQUENCE; diff --git a/src/asn1/asn1c/constr_SEQUENCE_OF.c b/src/asn1/asn1c/constr_SEQUENCE_OF.c index 99e178c8..58b411a7 100644 --- a/src/asn1/asn1c/constr_SEQUENCE_OF.c +++ b/src/asn1/asn1c/constr_SEQUENCE_OF.c @@ -139,94 +139,6 @@ cb_failed: ASN__ENCODE_FAILED; } -#ifndef ASN_DISABLE_PER_SUPPORT - -asn_enc_rval_t -SEQUENCE_OF_encode_uper(const asn_TYPE_descriptor_t *td, - const asn_per_constraints_t *constraints, - const void *sptr, asn_per_outp_t *po) { - const asn_anonymous_sequence_ *list; - const asn_per_constraint_t *ct; - asn_enc_rval_t er; - const asn_TYPE_member_t *elm = td->elements; - size_t encoded_edx; - - if(!sptr) ASN__ENCODE_FAILED; - list = _A_CSEQUENCE_FROM_VOID(sptr); - - er.encoded = 0; - - ASN_DEBUG("Encoding %s as SEQUENCE OF (%d)", td->name, list->count); - - if(constraints) ct = &constraints->size; - else if(td->encoding_constraints.per_constraints) - ct = &td->encoding_constraints.per_constraints->size; - else ct = 0; - - /* If extensible constraint, check if size is in root */ - if(ct) { - int not_in_root = - (list->count < ct->lower_bound || list->count > ct->upper_bound); - ASN_DEBUG("lb %ld ub %ld %s", ct->lower_bound, ct->upper_bound, - ct->flags & APC_EXTENSIBLE ? "ext" : "fix"); - if(ct->flags & APC_EXTENSIBLE) { - /* Declare whether size is in extension root */ - if(per_put_few_bits(po, not_in_root, 1)) ASN__ENCODE_FAILED; - if(not_in_root) ct = 0; - } else if(not_in_root && ct->effective_bits >= 0) { - ASN__ENCODE_FAILED; - } - - } - - if(ct && ct->effective_bits >= 0) { - /* X.691, #19.5: No length determinant */ - if(per_put_few_bits(po, list->count - ct->lower_bound, - ct->effective_bits)) - ASN__ENCODE_FAILED; - } else if(list->count == 0) { - /* When the list is empty add only the length determinant - * X.691, #20.6 and #11.9.4.1 - */ - if (uper_put_length(po, 0, 0)) { - ASN__ENCODE_FAILED; - } - ASN__ENCODED_OK(er); - } - - for(encoded_edx = 0; (ssize_t)encoded_edx < list->count;) { - ssize_t may_encode; - size_t edx; - int need_eom = 0; - - if(ct && ct->effective_bits >= 0) { - may_encode = list->count; - } else { - may_encode = - uper_put_length(po, list->count - encoded_edx, &need_eom); - if(may_encode < 0) ASN__ENCODE_FAILED; - } - - for(edx = encoded_edx; edx < encoded_edx + may_encode; edx++) { - void *memb_ptr = list->array[edx]; - if(!memb_ptr) ASN__ENCODE_FAILED; - er = elm->type->op->uper_encoder( - elm->type, elm->encoding_constraints.per_constraints, memb_ptr, - po); - if(er.encoded == -1) ASN__ENCODE_FAILED; - } - - if(need_eom && uper_put_length(po, 0, 0)) - ASN__ENCODE_FAILED; /* End of Message length */ - - encoded_edx += may_encode; - } - - ASN__ENCODED_OK(er); -} - -#endif /* ASN_DISABLE_PER_SUPPORT */ - int SEQUENCE_OF_compare(const asn_TYPE_descriptor_t *td, const void *aptr, const void *bptr) { @@ -264,20 +176,6 @@ asn_TYPE_operation_t asn_OP_SEQUENCE_OF = { SEQUENCE_OF_encode_der, SEQUENCE_OF_decode_xer, SEQUENCE_OF_encode_xer, -#ifdef ASN_DISABLE_OER_SUPPORT - 0, - 0, -#else - SEQUENCE_OF_decode_oer, /* Same as SET OF decoder. */ - SEQUENCE_OF_encode_oer, /* Same as SET OF encoder */ -#endif /* ASN_DISABLE_OER_SUPPORT */ -#ifdef ASN_DISABLE_PER_SUPPORT - 0, - 0, -#else - SEQUENCE_OF_decode_uper, /* Same as SET OF decoder */ - SEQUENCE_OF_encode_uper, -#endif /* ASN_DISABLE_PER_SUPPORT */ SEQUENCE_OF_random_fill, 0 /* Use generic outmost tag fetcher */ }; diff --git a/src/asn1/asn1c/constr_SEQUENCE_OF.h b/src/asn1/asn1c/constr_SEQUENCE_OF.h index c48ca2c0..1b54ca47 100644 --- a/src/asn1/asn1c/constr_SEQUENCE_OF.h +++ b/src/asn1/asn1c/constr_SEQUENCE_OF.h @@ -19,7 +19,6 @@ extern "C" { asn_struct_compare_f SEQUENCE_OF_compare; der_type_encoder_f SEQUENCE_OF_encode_der; xer_type_encoder_f SEQUENCE_OF_encode_xer; -per_type_encoder_f SEQUENCE_OF_encode_uper; extern asn_TYPE_operation_t asn_OP_SEQUENCE_OF; #define SEQUENCE_OF_free SET_OF_free @@ -27,9 +26,6 @@ extern asn_TYPE_operation_t asn_OP_SEQUENCE_OF; #define SEQUENCE_OF_constraint SET_OF_constraint #define SEQUENCE_OF_decode_ber SET_OF_decode_ber #define SEQUENCE_OF_decode_xer SET_OF_decode_xer -#define SEQUENCE_OF_decode_uper SET_OF_decode_uper -#define SEQUENCE_OF_decode_oer SET_OF_decode_oer -#define SEQUENCE_OF_encode_oer SET_OF_encode_oer #define SEQUENCE_OF_random_fill SET_OF_random_fill #ifdef __cplusplus diff --git a/src/asn1/asn1c/constr_SEQUENCE_oer.c b/src/asn1/asn1c/constr_SEQUENCE_oer.c deleted file mode 100644 index a2327bde..00000000 --- a/src/asn1/asn1c/constr_SEQUENCE_oer.c +++ /dev/null @@ -1,561 +0,0 @@ -/* - * Copyright (c) 2017 Lev Walkin . - * All rights reserved. - * Redistribution and modifications are permitted subject to BSD license. - */ -#ifndef ASN_DISABLE_OER_SUPPORT - -#include "asn1/asn1c/asn_internal.h" -#include "asn1/asn1c/constr_SEQUENCE.h" -#include "asn1/asn1c/OPEN_TYPE.h" -#include - -/* - * This macro "eats" the part of the buffer which is definitely "consumed", - * i.e. was correctly converted into local representation or rightfully skipped. - */ -#undef ADVANCE -#define ADVANCE(num_bytes) \ - do { \ - size_t num = num_bytes; \ - ptr = ((const char *)ptr) + num; \ - size -= num; \ - consumed_myself += num; \ - } while(0) - -/* - * Switch to the next phase of parsing. - */ -#undef NEXT_PHASE -#undef PHASE_OUT -#define NEXT_PHASE(ctx) \ - do { \ - ctx->phase++; \ - ctx->step = 0; \ - } while(0) - -/* - * Check whether we are inside the extensions group. - */ -#define IN_EXTENSION_GROUP(specs, memb_idx) \ - ((specs)->first_extension >= 0 \ - && (unsigned)(specs)->first_extension <= (memb_idx)) - -#define IN_ROOT_GROUP_PRED(edx) \ - edx < (specs->first_extension < 0 ? td->elements_count \ - : (size_t)specs->first_extension) - -#define FOR_IN_ROOT_GROUP(edx) for(edx = 0; IN_ROOT_GROUP_PRED(edx); edx++) - -/* - * Return a standardized complex structure. - */ -#undef RETURN -#define RETURN(_code) do { \ - rval.code = _code; \ - rval.consumed = consumed_myself;\ - return rval; \ - } while(0) - -/* - * Return pointer to a member. - */ -static void ** -element_ptrptr(void *struct_ptr, asn_TYPE_member_t *elm, void **tmp_save_ptr) { - if(elm->flags & ATF_POINTER) { - /* Member is a pointer to another structure */ - return (void **)((char *)struct_ptr + elm->memb_offset); - } else { - assert(tmp_save_ptr); - *tmp_save_ptr = (void *)((char *)struct_ptr + elm->memb_offset); - return tmp_save_ptr; - } -} - -static const void * -element_ptr(const void *struct_ptr, const asn_TYPE_member_t *elm) { - if(elm->flags & ATF_POINTER) { - /* Member is a pointer to another structure */ - return *(const void *const *)((const char *)struct_ptr - + elm->memb_offset); - } else { - return (const void *)((const char *)struct_ptr + elm->memb_offset); - } -} - -asn_dec_rval_t -SEQUENCE_decode_oer(const asn_codec_ctx_t *opt_codec_ctx, - const asn_TYPE_descriptor_t *td, - const asn_oer_constraints_t *constraints, void **struct_ptr, - const void *ptr, size_t size) { - const asn_SEQUENCE_specifics_t *specs = - (const asn_SEQUENCE_specifics_t *)td->specifics; - asn_dec_rval_t rval = {RC_OK, 0}; - void *st = *struct_ptr; /* Target structure */ - asn_struct_ctx_t *ctx; /* Decoder context */ - size_t consumed_myself = 0; /* Consumed bytes from ptr. */ - - (void)constraints; - - if(ASN__STACK_OVERFLOW_CHECK(opt_codec_ctx)) - ASN__DECODE_FAILED; - - /* - * Create the target structure if it is not present already. - */ - if(st == 0) { - st = *struct_ptr = CALLOC(1, specs->struct_size); - if(st == 0) { - RETURN(RC_FAIL); - } - } - - /* - * Restore parsing context. - */ - ctx = (asn_struct_ctx_t *)((char *)st + specs->ctx_offset); - - /* - * Start to parse where left previously. - */ - switch(ctx->phase) { - case 0: { - /* - * Fetch preamble. - */ - asn_bit_data_t *preamble; - int has_extensions_bit = (specs->first_extension >= 0); - size_t preamble_bits = (has_extensions_bit + specs->roms_count); - size_t preamble_bytes = ((7 + preamble_bits) >> 3); - - ASN_DEBUG("OER SEQUENCE %s Decoding PHASE 0", td->name); - - ASN_DEBUG( - "Expecting preamble bits %" ASN_PRI_SIZE " for %s (including %d extension bits)", - preamble_bits, td->name, has_extensions_bit); - - if(preamble_bytes > size) { - ASN__DECODE_STARVED; - } - - preamble = asn_bit_data_new_contiguous(ptr, preamble_bits); - if(!preamble) { - RETURN(RC_FAIL); - } - preamble->nboff = has_extensions_bit; - ctx->ptr = preamble; - ADVANCE(preamble_bytes); - } - NEXT_PHASE(ctx); - /* FALL THROUGH */ - case 1: { - /* Decode components of the extension root */ - asn_bit_data_t *preamble = ctx->ptr; - size_t edx; - - ASN_DEBUG("OER SEQUENCE %s Decoding PHASE 1 (Root)", td->name); - - assert(preamble); - - for(edx = (ctx->step >> 1); IN_ROOT_GROUP_PRED(edx); - edx++, ctx->step = (ctx->step & ~1) + 2) { - asn_TYPE_member_t *elm = &td->elements[edx]; - - ASN_DEBUG("Decoding %s->%s", td->name, elm->name); - - assert(!IN_EXTENSION_GROUP(specs, edx)); - - if(ctx->step & 1) { - goto microphase2_decode_continues; - } - - - if(elm->optional) { - int32_t present = asn_get_few_bits(preamble, 1); - if(present < 0) { - ASN_DEBUG("Presence map ended prematurely: %d", present); - RETURN(RC_FAIL); - } else if(present == 0) { - if(elm->default_value_set) { - /* Fill-in DEFAULT */ - void *tmp; - if(elm->default_value_set( - element_ptrptr(st, elm, &tmp))) { - RETURN(RC_FAIL); - } - } - /* The member is not present. */ - continue; - } - /* Present OPTIONAL or DEFAULT component. */ - } - - /* - * MICROPHASE 2: Invoke the member-specific decoder. - */ - ctx->step |= 1; /* Confirm entering next microphase */ - microphase2_decode_continues: - if(elm->flags & ATF_OPEN_TYPE) { - rval = OPEN_TYPE_oer_get(opt_codec_ctx, td, st, elm, ptr, size); - } else { - void *save_memb_ptr; /* Temporary reference. */ - void **memb_ptr2; /* Pointer to a pointer to a memmber */ - - memb_ptr2 = element_ptrptr(st, elm, &save_memb_ptr); - - rval = elm->type->op->oer_decoder( - opt_codec_ctx, elm->type, - elm->encoding_constraints.oer_constraints, memb_ptr2, ptr, - size); - } - switch(rval.code) { - case RC_OK: - ADVANCE(rval.consumed); - break; - case RC_WMORE: - ASN_DEBUG("More bytes needed at element %s \"%s\"", td->name, - elm->name); - ADVANCE(rval.consumed); - RETURN(RC_WMORE); - case RC_FAIL: - ASN_DEBUG("Decoding failed at element %s \"%s\"", td->name, - elm->name); - RETURN(RC_FAIL); - } - } /* for(all root members) */ - - } - NEXT_PHASE(ctx); - /* FALL THROUGH */ - case 2: - assert(ctx->ptr); - { - /* Cleanup preamble. */ - asn_bit_data_t *preamble = ctx->ptr; - asn_bit_data_t *extadds; - int has_extensions_bit = (specs->first_extension >= 0); - int extensions_present = - has_extensions_bit - && (preamble->buffer == NULL - || (((const uint8_t *)preamble->buffer)[0] & 0x80)); - uint8_t unused_bits; - size_t len = 0; - ssize_t len_len; - - ASN_DEBUG("OER SEQUENCE %s Decoding PHASE 2", td->name); - - preamble->buffer = 0; /* Will do extensions_present==1 next time. */ - - if(!extensions_present) { - ctx->phase = 10; - RETURN(RC_OK); - } - - /* - * X.696 (08/2015) #16.1 (c), #16.4 - * Read in the extension addition presence bitmap. - */ - - len_len = oer_fetch_length(ptr, size, &len); - if(len_len > 0) { - ADVANCE(len_len); - } else if(len_len < 0) { - RETURN(RC_FAIL); - } else { - RETURN(RC_WMORE); - } - - if(len == 0) { - /* 16.4.1-2 */ - RETURN(RC_FAIL); - } else if(len > size) { - RETURN(RC_WMORE); - } - - /* Account for unused bits */ - unused_bits = 0x7 & *(const uint8_t *)ptr; - ADVANCE(1); - len--; - if(unused_bits && len == 0) { - RETURN(RC_FAIL); - } - - /* Get the extensions map */ - extadds = asn_bit_data_new_contiguous(ptr, len * 8 - unused_bits); - if(!extadds) { - RETURN(RC_FAIL); - } - FREEMEM(preamble); - ctx->ptr = extadds; - ADVANCE(len); - } - NEXT_PHASE(ctx); - ctx->step = - (specs->first_extension < 0 ? td->elements_count - : (size_t)specs->first_extension); - /* Fall through */ - case 3: - ASN_DEBUG("OER SEQUENCE %s Decoding PHASE 3 (Extensions)", td->name); - for(; ctx->step < (signed)td->elements_count; ctx->step++) { - asn_bit_data_t *extadds = ctx->ptr; - size_t edx = ctx->step; - asn_TYPE_member_t *elm = &td->elements[edx]; - void *tmp_memb_ptr; - void **memb_ptr2 = element_ptrptr(st, elm, &tmp_memb_ptr); - - switch(asn_get_few_bits(extadds, 1)) { - case -1: - /* - * Not every one of our extensions is known to the remote side. - * Continue filling in their defaults though. - */ - /* Fall through */ - case 0: - /* Fill-in DEFAULT */ - if(elm->default_value_set - && elm->default_value_set(memb_ptr2)) { - RETURN(RC_FAIL); - } - continue; - case 1: { - /* Read OER open type */ - ssize_t ot_size = - oer_open_type_get(opt_codec_ctx, elm->type, - elm->encoding_constraints.oer_constraints, - memb_ptr2, ptr, size); - assert(ot_size <= (ssize_t)size); - if(ot_size > 0) { - ADVANCE(ot_size); - } else if(ot_size < 0) { - RETURN(RC_FAIL); - } else { - /* Roll back open type parsing */ - asn_get_undo(extadds, 1); - RETURN(RC_WMORE); - } - break; - } - default: - RETURN(RC_FAIL); - } - } - - NEXT_PHASE(ctx); - /* Fall through */ - case 4: - ASN_DEBUG("OER SEQUENCE %s Decoding PHASE 4", td->name); - /* Read in the rest of Open Types while ignoring them */ - for(;;) { - asn_bit_data_t *extadds = ctx->ptr; - switch(asn_get_few_bits(extadds, 1)) { - case 0: - continue; - case 1: { - ssize_t skipped = oer_open_type_skip(ptr, size); - if(skipped > 0) { - ADVANCE(skipped); - } else if(skipped < 0) { - RETURN(RC_FAIL); - } else { - asn_get_undo(extadds, 1); - RETURN(RC_WMORE); - } - continue; - } - case -1: - /* No more Open Type encoded components */ - break; - default: - RETURN(RC_FAIL); - } - break; - } - } - - RETURN(RC_OK); -} - -/* - * Encode as Canonical OER. - */ -asn_enc_rval_t -SEQUENCE_encode_oer(const asn_TYPE_descriptor_t *td, - const asn_oer_constraints_t *constraints, const void *sptr, - asn_app_consume_bytes_f *cb, void *app_key) { - const asn_SEQUENCE_specifics_t *specs = (const asn_SEQUENCE_specifics_t *)td->specifics; - size_t computed_size = 0; - int has_extensions_bit = (specs->first_extension >= 0); - size_t preamble_bits = (has_extensions_bit + specs->roms_count); - uint32_t has_extensions = 0; - size_t edx; - int ret; - - (void)constraints; - - if(preamble_bits) { - asn_bit_outp_t preamble; - - memset(&preamble, 0, sizeof(preamble)); - preamble.output = cb; - preamble.op_key = app_key; - - if(has_extensions_bit) { - for(edx = specs->first_extension; edx < td->elements_count; edx++) { - asn_TYPE_member_t *elm = &td->elements[edx]; - const void *memb_ptr = element_ptr(sptr, elm); - if(memb_ptr) { - if(elm->default_value_cmp - && elm->default_value_cmp(memb_ptr) == 0) { - /* Do not encode default values in extensions */ - } else { - has_extensions = 1; - break; - } - } - } - ret = asn_put_few_bits(&preamble, has_extensions, 1); - assert(ret == 0); - if(ret < 0) { - ASN__ENCODE_FAILED; - } - } - - /* - * Encode optional components bitmap. - */ - if(specs->roms_count) { - FOR_IN_ROOT_GROUP(edx) { - asn_TYPE_member_t *elm = &td->elements[edx]; - - if(IN_EXTENSION_GROUP(specs, edx)) break; - - if(elm->optional) { - const void *memb_ptr = element_ptr(sptr, elm); - uint32_t has_component = memb_ptr != NULL; - if(has_component && elm->default_value_cmp - && elm->default_value_cmp(memb_ptr) == 0) { - has_component = 0; - } - ret = asn_put_few_bits(&preamble, has_component, 1); - if(ret < 0) { - ASN__ENCODE_FAILED; - } - } - } - } - - asn_put_aligned_flush(&preamble); - computed_size += preamble.flushed_bytes; - } /* if(preamble_bits) */ - - /* - * Put root components and extensions root. - */ - for(edx = 0; edx < td->elements_count; edx++) { - asn_TYPE_member_t *elm = &td->elements[edx]; - asn_enc_rval_t er; - const void *memb_ptr; - - if(IN_EXTENSION_GROUP(specs, edx)) break; - - memb_ptr = element_ptr(sptr, elm); - if(memb_ptr) { - if(elm->default_value_cmp - && elm->default_value_cmp(memb_ptr) == 0) { - /* Skip default values in encoding */ - continue; - } - } else { - if(elm->optional) continue; - /* Mandatory element is missing */ - ASN__ENCODE_FAILED; - } - if(!elm->type->op->oer_encoder) { - ASN_DEBUG("OER encoder is not defined for type %s", elm->type->name); - ASN__ENCODE_FAILED; - } - er = elm->type->op->oer_encoder( - elm->type, elm->encoding_constraints.oer_constraints, memb_ptr, cb, - app_key); - if(er.encoded == -1) { - ASN_DEBUG("... while encoding %s member \"%s\"\n", td->name, - elm->name); - return er; - } - computed_size += er.encoded; - } - - /* - * Before encode extensions, encode extensions additions presense bitmap - # X.696 (08/2015) #16.4. - */ - if(has_extensions) { - asn_bit_outp_t extadds; - - /* Special case allowing us to use exactly one byte for #8.6 */ - size_t aoms_length_bits = specs->aoms_count; - size_t aoms_length_bytes = (7 + aoms_length_bits) >> 3; - uint8_t unused_bits = 0x07 & (8 - (aoms_length_bits & 0x07)); - - assert(1 + aoms_length_bytes <= 127); - - memset(&extadds, 0, sizeof(extadds)); - extadds.output = cb; - extadds.op_key = app_key; - - /* #8.6 length determinant */ - ret = asn_put_few_bits(&extadds, (1 + aoms_length_bytes), 8); - if(ret < 0) ASN__ENCODE_FAILED; - - /* Number of unused bytes, #16.4.2 */ - ret = asn_put_few_bits(&extadds, unused_bits, 8); - if(ret < 0) ASN__ENCODE_FAILED; - - /* Encode presence bitmap #16.4.3 */ - for(edx = specs->first_extension; edx < td->elements_count; edx++) { - asn_TYPE_member_t *elm = &td->elements[edx]; - const void *memb_ptr = element_ptr(sptr, elm); - if(memb_ptr && elm->default_value_cmp - && elm->default_value_cmp(memb_ptr) == 0) { - memb_ptr = 0; /* Do not encode default value. */ - } - ret |= asn_put_few_bits(&extadds, memb_ptr ? 1 : 0, 1); - } - if(ret < 0) ASN__ENCODE_FAILED; - - asn_put_aligned_flush(&extadds); - computed_size += extadds.flushed_bytes; - - /* Now, encode extensions */ - for(edx = specs->first_extension; edx < td->elements_count; edx++) { - asn_TYPE_member_t *elm = &td->elements[edx]; - const void *memb_ptr = element_ptr(sptr, elm); - - if(memb_ptr) { - if(elm->default_value_cmp - && elm->default_value_cmp(memb_ptr) == 0) { - /* Do not encode default value. */ - } else { - ssize_t wrote = oer_open_type_put( - elm->type, elm->encoding_constraints.oer_constraints, - memb_ptr, cb, app_key); - if(wrote == -1) { - ASN__ENCODE_FAILED; - } - computed_size += wrote; - } - } else if(!elm->optional) { - ASN__ENCODE_FAILED; - } - } - } /* if(has_extensions) */ - - - { - asn_enc_rval_t er = {0, 0, 0}; - er.encoded = computed_size; - ASN__ENCODED_OK(er); - } -} - -#endif /* ASN_DISABLE_OER_SUPPORT */ diff --git a/src/asn1/asn1c/constr_SET_OF.c b/src/asn1/asn1c/constr_SET_OF.c index b996c7bd..7ae2c0bd 100644 --- a/src/asn1/asn1c/constr_SET_OF.c +++ b/src/asn1/asn1c/constr_SET_OF.c @@ -352,7 +352,6 @@ SET_OF__encode_sorted_free(struct _el_buffer *el_buf, size_t count) { enum SET_OF__encode_method { SOES_DER, /* Distinguished Encoding Rules */ - SOES_CUPER /* Canonical Unaligned Packed Encoding Rules */ }; static struct _el_buffer * @@ -386,16 +385,6 @@ SET_OF__encode_sorted(const asn_TYPE_member_t *elm, erval = elm->type->op->der_encoder(elm->type, memb_ptr, 0, elm->tag, _el_addbytes, encoding_el); break; - case SOES_CUPER: - erval = uper_encode(elm->type, - elm->encoding_constraints.per_constraints, - memb_ptr, _el_addbytes, encoding_el); - if(erval.encoded != -1) { - size_t extra_bits = erval.encoded % 8; - assert(encoding_el->length == (size_t)(erval.encoded + 7) / 8); - encoding_el->bits_unused = (8 - extra_bits) & 0x7; - } - break; default: assert(!"Unreachable"); break; @@ -905,204 +894,6 @@ SET_OF_constraint(const asn_TYPE_descriptor_t *td, const void *sptr, return 0; } -#ifndef ASN_DISABLE_PER_SUPPORT - -asn_dec_rval_t -SET_OF_decode_uper(const asn_codec_ctx_t *opt_codec_ctx, - const asn_TYPE_descriptor_t *td, - const asn_per_constraints_t *constraints, void **sptr, - asn_per_data_t *pd) { - asn_dec_rval_t rv; - const asn_SET_OF_specifics_t *specs = (const asn_SET_OF_specifics_t *)td->specifics; - const asn_TYPE_member_t *elm = td->elements; /* Single one */ - void *st = *sptr; - asn_anonymous_set_ *list; - const asn_per_constraint_t *ct; - int repeat = 0; - ssize_t nelems; - - if(ASN__STACK_OVERFLOW_CHECK(opt_codec_ctx)) - ASN__DECODE_FAILED; - - /* - * Create the target structure if it is not present already. - */ - if(!st) { - st = *sptr = CALLOC(1, specs->struct_size); - if(!st) ASN__DECODE_FAILED; - } - list = _A_SET_FROM_VOID(st); - - /* Figure out which constraints to use */ - if(constraints) ct = &constraints->size; - else if(td->encoding_constraints.per_constraints) - ct = &td->encoding_constraints.per_constraints->size; - else ct = 0; - - if(ct && ct->flags & APC_EXTENSIBLE) { - int value = per_get_few_bits(pd, 1); - if(value < 0) ASN__DECODE_STARVED; - if(value) ct = 0; /* Not restricted! */ - } - - if(ct && ct->effective_bits >= 0) { - /* X.691, #19.5: No length determinant */ - nelems = per_get_few_bits(pd, ct->effective_bits); - ASN_DEBUG("Preparing to fetch %ld+%ld elements from %s", - (long)nelems, ct->lower_bound, td->name); - if(nelems < 0) ASN__DECODE_STARVED; - nelems += ct->lower_bound; - } else { - nelems = -1; - } - - do { - int i; - if(nelems < 0) { - nelems = uper_get_length(pd, -1, 0, &repeat); - ASN_DEBUG("Got to decode %" ASN_PRI_SSIZE " elements (eff %d)", - nelems, (int)(ct ? ct->effective_bits : -1)); - if(nelems < 0) ASN__DECODE_STARVED; - } - - for(i = 0; i < nelems; i++) { - void *ptr = 0; - ASN_DEBUG("SET OF %s decoding", elm->type->name); - rv = elm->type->op->uper_decoder(opt_codec_ctx, elm->type, - elm->encoding_constraints.per_constraints, &ptr, pd); - ASN_DEBUG("%s SET OF %s decoded %d, %p", - td->name, elm->type->name, rv.code, ptr); - if(rv.code == RC_OK) { - if(ASN_SET_ADD(list, ptr) == 0) { - if(rv.consumed == 0 && nelems > 200) { - /* Protect from SET OF NULL compression bombs. */ - ASN__DECODE_FAILED; - } - continue; - } - ASN_DEBUG("Failed to add element into %s", - td->name); - /* Fall through */ - rv.code = RC_FAIL; - } else { - ASN_DEBUG("Failed decoding %s of %s (SET OF)", - elm->type->name, td->name); - } - if(ptr) ASN_STRUCT_FREE(*elm->type, ptr); - return rv; - } - - nelems = -1; /* Allow uper_get_length() */ - } while(repeat); - - ASN_DEBUG("Decoded %s as SET OF", td->name); - - rv.code = RC_OK; - rv.consumed = 0; - return rv; -} - -asn_enc_rval_t -SET_OF_encode_uper(const asn_TYPE_descriptor_t *td, - const asn_per_constraints_t *constraints, const void *sptr, - asn_per_outp_t *po) { - const asn_anonymous_set_ *list; - const asn_per_constraint_t *ct; - const asn_TYPE_member_t *elm = td->elements; - struct _el_buffer *encoded_els; - asn_enc_rval_t er; - size_t encoded_edx; - - if(!sptr) ASN__ENCODE_FAILED; - - list = _A_CSET_FROM_VOID(sptr); - - er.encoded = 0; - - ASN_DEBUG("Encoding %s as SEQUENCE OF (%d)", td->name, list->count); - - if(constraints) ct = &constraints->size; - else if(td->encoding_constraints.per_constraints) - ct = &td->encoding_constraints.per_constraints->size; - else ct = 0; - - /* If extensible constraint, check if size is in root */ - if(ct) { - int not_in_root = - (list->count < ct->lower_bound || list->count > ct->upper_bound); - ASN_DEBUG("lb %ld ub %ld %s", ct->lower_bound, ct->upper_bound, - ct->flags & APC_EXTENSIBLE ? "ext" : "fix"); - if(ct->flags & APC_EXTENSIBLE) { - /* Declare whether size is in extension root */ - if(per_put_few_bits(po, not_in_root, 1)) ASN__ENCODE_FAILED; - if(not_in_root) ct = 0; - } else if(not_in_root && ct->effective_bits >= 0) { - ASN__ENCODE_FAILED; - } - - } - - if(ct && ct->effective_bits >= 0) { - /* X.691, #19.5: No length determinant */ - if(per_put_few_bits(po, list->count - ct->lower_bound, - ct->effective_bits)) - ASN__ENCODE_FAILED; - } else if(list->count == 0) { - /* When the list is empty add only the length determinant - * X.691, #20.6 and #11.9.4.1 - */ - if (uper_put_length(po, 0, 0)) { - ASN__ENCODE_FAILED; - } - ASN__ENCODED_OK(er); - } - - - /* - * Canonical UPER #22.1 mandates dynamic sorting of the SET OF elements - * according to their encodings. Build an array of the encoded elements. - */ - encoded_els = SET_OF__encode_sorted(elm, list, SOES_CUPER); - - for(encoded_edx = 0; (ssize_t)encoded_edx < list->count;) { - ssize_t may_encode; - size_t edx; - int need_eom = 0; - - if(ct && ct->effective_bits >= 0) { - may_encode = list->count; - } else { - may_encode = - uper_put_length(po, list->count - encoded_edx, &need_eom); - if(may_encode < 0) ASN__ENCODE_FAILED; - } - - for(edx = encoded_edx; edx < encoded_edx + may_encode; edx++) { - const struct _el_buffer *el = &encoded_els[edx]; - if(asn_put_many_bits(po, el->buf, - (8 * el->length) - el->bits_unused) < 0) { - break; - } - } - - if(need_eom && uper_put_length(po, 0, 0)) - ASN__ENCODE_FAILED; /* End of Message length */ - - encoded_edx += may_encode; - } - - SET_OF__encode_sorted_free(encoded_els, list->count); - - if((ssize_t)encoded_edx == list->count) { - ASN__ENCODED_OK(er); - } else { - ASN__ENCODE_FAILED; - } -} - - -#endif /* ASN_DISABLE_PER_SUPPORT */ - struct comparable_ptr { const asn_TYPE_descriptor_t *td; const void *sptr; @@ -1191,20 +982,6 @@ asn_TYPE_operation_t asn_OP_SET_OF = { SET_OF_encode_der, SET_OF_decode_xer, SET_OF_encode_xer, -#ifdef ASN_DISABLE_OER_SUPPORT - 0, - 0, -#else - SET_OF_decode_oer, - SET_OF_encode_oer, -#endif -#ifdef ASN_DISABLE_PER_SUPPORT - 0, - 0, -#else - SET_OF_decode_uper, - SET_OF_encode_uper, -#endif /* ASN_DISABLE_PER_SUPPORT */ SET_OF_random_fill, 0 /* Use generic outmost tag fetcher */ }; @@ -1246,63 +1023,10 @@ SET_OF_random_fill(const asn_TYPE_descriptor_t *td, void **sptr, } sub = slb + max_elements; - if(!constraints || !constraints->per_constraints) - constraints = &td->encoding_constraints; - if(constraints->per_constraints) { - const asn_per_constraint_t *pc = &constraints->per_constraints->size; - if(pc->flags & APC_SEMI_CONSTRAINED) { - slb = pc->lower_bound; - sub = pc->lower_bound + max_elements; - } else if(pc->flags & APC_CONSTRAINED) { - slb = pc->lower_bound; - sub = pc->upper_bound; - if(sub - slb > max_elements) sub = slb + max_elements; - } - } - /* Bias towards edges of allowed space */ switch(asn_random_between(-1, 4)) { default: case -1: - /* Prepare lengths somewhat outside of constrained range. */ - if(constraints->per_constraints - && (constraints->per_constraints->size.flags & APC_EXTENSIBLE)) { - switch(asn_random_between(0, 5)) { - default: - case 0: - rnd_len = 0; - break; - case 1: - if(slb > 0) { - rnd_len = slb - 1; - } else { - rnd_len = 0; - } - break; - case 2: - rnd_len = asn_random_between(0, slb); - break; - case 3: - if(sub < (ssize_t)max_length) { - rnd_len = sub + 1; - } else { - rnd_len = max_length; - } - break; - case 4: - if(sub < (ssize_t)max_length) { - rnd_len = asn_random_between(sub + 1, max_length); - } else { - rnd_len = max_length; - } - break; - case 5: - rnd_len = max_length; - break; - } - break; - } - /* Fall through */ case 0: rnd_len = asn_random_between(slb, sub); break; diff --git a/src/asn1/asn1c/constr_SET_OF.h b/src/asn1/asn1c/constr_SET_OF.h index 4237edc7..cf5cd2b9 100644 --- a/src/asn1/asn1c/constr_SET_OF.h +++ b/src/asn1/asn1c/constr_SET_OF.h @@ -33,10 +33,6 @@ ber_type_decoder_f SET_OF_decode_ber; der_type_encoder_f SET_OF_encode_der; xer_type_decoder_f SET_OF_decode_xer; xer_type_encoder_f SET_OF_encode_xer; -oer_type_decoder_f SET_OF_decode_oer; -oer_type_encoder_f SET_OF_encode_oer; -per_type_decoder_f SET_OF_decode_uper; -per_type_encoder_f SET_OF_encode_uper; asn_random_fill_f SET_OF_random_fill; extern asn_TYPE_operation_t asn_OP_SET_OF; diff --git a/src/asn1/asn1c/constr_SET_OF_oer.c b/src/asn1/asn1c/constr_SET_OF_oer.c deleted file mode 100644 index 98c2ae16..00000000 --- a/src/asn1/asn1c/constr_SET_OF_oer.c +++ /dev/null @@ -1,285 +0,0 @@ -/* - * Copyright (c) 2017 Lev Walkin . - * All rights reserved. - * Redistribution and modifications are permitted subject to BSD license. - */ -#ifndef ASN_DISABLE_OER_SUPPORT - -#include "asn1/asn1c/asn_internal.h" -#include "asn1/asn1c/constr_SET_OF.h" -#include "asn1/asn1c/asn_SET_OF.h" -#include - -/* - * This macro "eats" the part of the buffer which is definitely "consumed", - * i.e. was correctly converted into local representation or rightfully skipped. - */ -#undef ADVANCE -#define ADVANCE(num_bytes) \ - do { \ - size_t num = num_bytes; \ - ptr = ((const char *)ptr) + num; \ - size -= num; \ - consumed_myself += num; \ - } while(0) - -/* - * Switch to the next phase of parsing. - */ -#undef NEXT_PHASE -#define NEXT_PHASE(ctx) \ - do { \ - ctx->phase++; \ - ctx->step = 0; \ - } while(0) -#undef SET_PHASE -#define SET_PHASE(ctx, value) \ - do { \ - ctx->phase = value; \ - ctx->step = 0; \ - } while(0) - -/* - * Return a standardized complex structure. - */ -#undef RETURN -#define RETURN(_code) \ - do { \ - asn_dec_rval_t rval; \ - rval.code = _code; \ - rval.consumed = consumed_myself; \ - return rval; \ - } while(0) - -/* - * The SEQUENCE OF and SET OF values utilize a "quantity field". - * It is is a pointless combination of #8.6 (length determinant, capable - * of encoding tiny and huge numbers in the shortest possible number of octets) - * and the variable sized integer. What could have been encoded by #8.6 alone - * is required to be encoded by #8.6 followed by that number of unsigned octets. - * This doesn't make too much sense. It seems that the original version of OER - * standard have been using the unconstrained unsigned integer as a quantity - * field, and this legacy have gone through ISO/ITU-T standardization process. - */ -static ssize_t -oer_fetch_quantity(const void *ptr, size_t size, size_t *qty_r) { - const uint8_t *b; - const uint8_t *bend; - size_t len = 0; - size_t qty; - - ssize_t len_len = oer_fetch_length(ptr, size, &len); - if(len_len <= 0) { - *qty_r = 0; - return len_len; - } - - if((len_len + len) > size) { - *qty_r = 0; - return 0; - } - - b = (const uint8_t *)ptr + len_len; - bend = b + len; - - /* Skip the leading 0-bytes */ - for(; b < bend && *b == 0; b++) { - } - - if((bend - b) > (ssize_t)sizeof(size_t)) { - /* Length is not representable by the native size_t type */ - *qty_r = 0; - return -1; - } - - for(qty = 0; b < bend; b++) { - qty = (qty << 8) + *b; - } - - if(qty > RSIZE_MAX) { /* A bit of C11 validation */ - *qty_r = 0; - return -1; - } - - *qty_r = qty; - assert((size_t)len_len + len == (size_t)(bend - (const uint8_t *)ptr)); - return len_len + len; -} - -asn_dec_rval_t -SET_OF_decode_oer(const asn_codec_ctx_t *opt_codec_ctx, - const asn_TYPE_descriptor_t *td, - const asn_oer_constraints_t *constraints, void **struct_ptr, - const void *ptr, size_t size) { - const asn_SET_OF_specifics_t *specs = (const asn_SET_OF_specifics_t *)td->specifics; - asn_dec_rval_t rval = {RC_OK, 0}; - void *st = *struct_ptr; /* Target structure */ - asn_struct_ctx_t *ctx; /* Decoder context */ - size_t consumed_myself = 0; /* Consumed bytes from ptr. */ - - (void)constraints; - - if(ASN__STACK_OVERFLOW_CHECK(opt_codec_ctx)) - ASN__DECODE_FAILED; - - /* - * Create the target structure if it is not present already. - */ - if(st == 0) { - st = *struct_ptr = CALLOC(1, specs->struct_size); - if(st == 0) { - RETURN(RC_FAIL); - } - } - - /* - * Restore parsing context. - */ - ctx = (asn_struct_ctx_t *)((char *)st + specs->ctx_offset); - - /* - * Start to parse where left previously. - */ - switch(ctx->phase) { - case 0: { - /* - * Fetch number of elements to decode. - */ - size_t length = 0; - size_t len_size = oer_fetch_quantity(ptr, size, &length); - switch(len_size) { - case 0: - RETURN(RC_WMORE); - case -1: - RETURN(RC_FAIL); - default: - ADVANCE(len_size); - ctx->left = length; - } - } - NEXT_PHASE(ctx); - /* FALL THROUGH */ - case 1: { - /* Decode components of the extension root */ - asn_TYPE_member_t *elm = td->elements; - asn_anonymous_set_ *list = _A_SET_FROM_VOID(st); - const void *base_ptr = ptr; - ber_tlv_len_t base_ctx_left = ctx->left; - - assert(td->elements_count == 1); - - ASN_DEBUG("OER SET OF %s Decoding PHASE 1", td->name); - - for(; ctx->left > 0; ctx->left--) { - asn_dec_rval_t rv = elm->type->op->oer_decoder( - opt_codec_ctx, elm->type, - elm->encoding_constraints.oer_constraints, &ctx->ptr, ptr, - size); - ADVANCE(rv.consumed); - switch(rv.code) { - case RC_OK: - if(ASN_SET_ADD(list, ctx->ptr) != 0) { - RETURN(RC_FAIL); - } else { - ctx->ptr = 0; - /* - * This check is to avoid compression bomb with - * specs like SEQUENCE/SET OF NULL which don't - * consume data at all. - */ - if(rv.consumed == 0 && base_ptr == ptr - && (base_ctx_left - ctx->left) > 200) { - ASN__DECODE_FAILED; - } - break; - } - case RC_WMORE: - RETURN(RC_WMORE); - case RC_FAIL: - ASN_STRUCT_FREE(*elm->type, ctx->ptr); - ctx->ptr = 0; - SET_PHASE(ctx, 3); - RETURN(RC_FAIL); - } - } - /* Decoded decently. */ - NEXT_PHASE(ctx); - } - /* Fall through */ - case 2: - /* Ignore fully decoded */ - assert(ctx->left == 0); - RETURN(RC_OK); - case 3: - /* Failed to decode. */ - RETURN(RC_FAIL); - } - - return rval; -} - -static ssize_t -oer_put_quantity(size_t qty, asn_app_consume_bytes_f *cb, void *app_key) { - uint8_t buf[1 + sizeof(size_t)]; - uint8_t *b = &buf[sizeof(size_t)]; /* Last addressable */ - size_t encoded; - - do { - *b-- = qty; - qty >>= 8; - } while(qty); - - *b = sizeof(buf) - (b-buf) - 1; - encoded = sizeof(buf) - (b-buf); - if(cb(b, encoded, app_key) < 0) - return -1; - return encoded; -} - -/* - * Encode as Canonical OER. - */ -asn_enc_rval_t -SET_OF_encode_oer(const asn_TYPE_descriptor_t *td, - const asn_oer_constraints_t *constraints, const void *sptr, - asn_app_consume_bytes_f *cb, void *app_key) { - const asn_TYPE_member_t *elm; - const asn_anonymous_set_ *list; - size_t computed_size = 0; - ssize_t qty_len; - int n; - - (void)constraints; - - if(!sptr) ASN__ENCODE_FAILED; - - elm = td->elements; - list = _A_CSET_FROM_VOID(sptr); - - qty_len = oer_put_quantity(list->count, cb, app_key); - if(qty_len < 0) { - ASN__ENCODE_FAILED; - } - computed_size += qty_len; - - for(n = 0; n < list->count; n++) { - void *memb_ptr = list->array[n]; - asn_enc_rval_t er; - er = elm->type->op->oer_encoder( - elm->type, elm->encoding_constraints.oer_constraints, memb_ptr, cb, - app_key); - if(er.encoded < 0) { - return er; - } else { - computed_size += er.encoded; - } - } - - { - asn_enc_rval_t erval; - erval.encoded = computed_size; - ASN__ENCODED_OK(erval); - } -} - -#endif /* ASN_DISABLE_OER_SUPPORT */ diff --git a/src/asn1/asn1c/constr_TYPE.h b/src/asn1/asn1c/constr_TYPE.h index c35cfd9d..02d47113 100644 --- a/src/asn1/asn1c/constr_TYPE.h +++ b/src/asn1/asn1c/constr_TYPE.h @@ -38,20 +38,9 @@ typedef struct asn_struct_ctx_s { #include "asn1/asn1c/der_encoder.h" /* Distinguished Encoding Rules encoder */ #include "asn1/asn1c/xer_decoder.h" /* Decoder of XER (XML, text) */ #include "asn1/asn1c/xer_encoder.h" /* Encoder into XER (XML, text) */ -#include "asn1/asn1c/per_decoder.h" /* Packet Encoding Rules decoder */ -#include "asn1/asn1c/per_encoder.h" /* Packet Encoding Rules encoder */ #include "asn1/asn1c/constraints.h" /* Subtype constraints support */ #include "asn1/asn1c/asn_random_fill.h" /* Random structures support */ -#ifdef ASN_DISABLE_OER_SUPPORT -typedef void (oer_type_decoder_f)(void); -typedef void (oer_type_encoder_f)(void); -typedef void asn_oer_constraints_t; -#else -#include "asn1/asn1c/oer_decoder.h" /* Octet Encoding Rules encoder */ -#include "asn1/asn1c/oer_encoder.h" /* Octet Encoding Rules encoder */ -#endif - /* * Free the structure according to its specification. * Use one of ASN_STRUCT_{FREE,RESET,CONTENTS_ONLY} macros instead. @@ -149,20 +138,13 @@ typedef struct asn_TYPE_operation_s { der_type_encoder_f *der_encoder; /* Canonical DER encoder */ xer_type_decoder_f *xer_decoder; /* Generic XER decoder */ xer_type_encoder_f *xer_encoder; /* [Canonical] XER encoder */ - oer_type_decoder_f *oer_decoder; /* Generic OER decoder */ - oer_type_encoder_f *oer_encoder; /* Canonical OER encoder */ - per_type_decoder_f *uper_decoder; /* Unaligned PER decoder */ - per_type_encoder_f *uper_encoder; /* Unaligned PER encoder */ asn_random_fill_f *random_fill; /* Initialize with a random value */ asn_outmost_tag_f *outmost_tag; /* */ } asn_TYPE_operation_t; -/* - * A constraints tuple specifying both the OER and PER constraints. - */ typedef struct asn_encoding_constraints_s { - const struct asn_oer_constraints_s *oer_constraints; - const struct asn_per_constraints_s *per_constraints; + const int *oer_constraints; /* Removed */ + const int *per_constraints; /* Removed */ asn_constr_check_f *general_constraints; } asn_encoding_constraints_t; @@ -191,7 +173,7 @@ typedef struct asn_TYPE_descriptor_s { const ber_tlv_tag_t *all_tags; /* Every tag for BER/containment */ unsigned all_tags_count; /* Number of tags */ - /* OER, PER, and general constraints */ + /* Constraints */ asn_encoding_constraints_t encoding_constraints; /* diff --git a/src/asn1/asn1c/oer_decoder.c b/src/asn1/asn1c/oer_decoder.c deleted file mode 100644 index 6abb5d68..00000000 --- a/src/asn1/asn1c/oer_decoder.c +++ /dev/null @@ -1,152 +0,0 @@ -/* - * Copyright (c) 2017 Lev Walkin . All rights reserved. - * Redistribution and modifications are permitted subject to BSD license. - */ -#include "asn1/asn1c/asn_internal.h" -#include "asn1/asn1c/asn_codecs_prim.h" - -/* - * The OER decoder of any type. - */ -asn_dec_rval_t -oer_decode(const asn_codec_ctx_t *opt_codec_ctx, - const asn_TYPE_descriptor_t *type_descriptor, void **struct_ptr, - const void *ptr, size_t size) { - asn_codec_ctx_t s_codec_ctx; - - /* - * Stack checker requires that the codec context - * must be allocated on the stack. - */ - if(opt_codec_ctx) { - if(opt_codec_ctx->max_stack_size) { - s_codec_ctx = *opt_codec_ctx; - opt_codec_ctx = &s_codec_ctx; - } - } else { - /* If context is not given, be security-conscious anyway */ - memset(&s_codec_ctx, 0, sizeof(s_codec_ctx)); - s_codec_ctx.max_stack_size = ASN__DEFAULT_STACK_MAX; - opt_codec_ctx = &s_codec_ctx; - } - - /* - * Invoke type-specific decoder. - */ - return type_descriptor->op->oer_decoder(opt_codec_ctx, type_descriptor, 0, - struct_ptr, /* Pointer to the destination structure */ - ptr, size /* Buffer and its size */ - ); -} - -/* - * Open Type is encoded as a length (#8.6) followed by that number of bytes. - * Since we're just skipping, reading the length would be enough. - */ -ssize_t -oer_open_type_skip(const void *bufptr, size_t size) { - size_t len = 0; - return oer_fetch_length(bufptr, size, &len); -} - -/* - * Read the Open Type (X.696 (08/2015), #30). - * RETURN VALUES: - * 0: More data expected than bufptr contains. - * -1: Fatal error deciphering length. - * >0: Number of bytes used from bufptr. - */ -ssize_t -oer_open_type_get(const asn_codec_ctx_t *opt_codec_ctx, - const struct asn_TYPE_descriptor_s *td, - const asn_oer_constraints_t *constraints, void **struct_ptr, - const void *bufptr, size_t size) { - asn_dec_rval_t dr; - size_t container_len = 0; - ssize_t len_len; - enum asn_struct_free_method dispose_method = - (*struct_ptr) ? ASFM_FREE_UNDERLYING_AND_RESET : ASFM_FREE_EVERYTHING; - - /* Get the size of a length determinant */ - len_len = oer_fetch_length(bufptr, size, &container_len); - if(len_len <= 0) { - return len_len; /* Error or more data expected */ - } - - /* - * len_len can't be bigger than size, but size without len_len - * should be bigger or equal to container length - */ - if(size - len_len < container_len) { - /* More data is expected */ - return 0; - } - - dr = td->op->oer_decoder(opt_codec_ctx, td, constraints, struct_ptr, - (const uint8_t *)bufptr + len_len, container_len); - if(dr.code == RC_OK) { - return len_len + container_len; - } else { - /* Even if RC_WMORE, we can't get more data into a closed container. */ - td->op->free_struct(td, *struct_ptr, dispose_method); - *struct_ptr = NULL; - return -1; - } -} - - -asn_dec_rval_t -oer_decode_primitive(const asn_codec_ctx_t *opt_codec_ctx, - const asn_TYPE_descriptor_t *td, - const asn_oer_constraints_t *constraints, void **sptr, - const void *ptr, size_t size) { - ASN__PRIMITIVE_TYPE_t *st = (ASN__PRIMITIVE_TYPE_t *)*sptr; - asn_dec_rval_t rval = {RC_OK, 0}; - size_t expected_length = 0; - ssize_t len_len; - - (void)td; - (void)opt_codec_ctx; - (void)constraints; - - if(!st) { - st = (ASN__PRIMITIVE_TYPE_t *)(*sptr = CALLOC( - 1, sizeof(ASN__PRIMITIVE_TYPE_t))); - if(!st) ASN__DECODE_FAILED; - } - - - /* - * X.696 (08/2015) #27.2 - * Encode length determinant as _number of octets_, but only - * if upper bound is not equal to lower bound. - */ - len_len = oer_fetch_length(ptr, size, &expected_length); - if(len_len > 0) { - rval.consumed = len_len; - ptr = (const char *)ptr + len_len; - size -= len_len; - } else if(len_len == 0) { - ASN__DECODE_STARVED; - } else if(len_len < 0) { - ASN__DECODE_FAILED; - } - - if(size < expected_length) { - ASN__DECODE_STARVED; - } else { - uint8_t *buf = MALLOC(expected_length + 1); - if(buf == NULL) { - ASN__DECODE_FAILED; - } else { - memcpy(buf, ptr, expected_length); - buf[expected_length] = '\0'; - } - FREEMEM(st->buf); - st->buf = buf; - st->size = expected_length; - - rval.consumed += expected_length; - return rval; - } -} diff --git a/src/asn1/asn1c/oer_decoder.h b/src/asn1/asn1c/oer_decoder.h deleted file mode 100644 index fbdc1c6f..00000000 --- a/src/asn1/asn1c/oer_decoder.h +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (c) 2017 Lev Walkin . All rights reserved. - * Redistribution and modifications are permitted subject to BSD license. - */ -#ifndef OER_DECODER_H -#define OER_DECODER_H - -#include "asn1/asn1c/asn_application.h" -#include "asn1/asn1c/oer_support.h" - -#ifdef __cplusplus -extern "C" { -#endif - -struct asn_TYPE_descriptor_s; /* Forward declaration */ -struct asn_codec_ctx_s; /* Forward declaration */ - -/* - * The Octet Encoding Rules (OER, X.696 08/2015) decoder for any given type. - * This function may be invoked directly by the application. - * Parses CANONICAL-OER and BASIC-OER. - */ -asn_dec_rval_t oer_decode(const struct asn_codec_ctx_s *opt_codec_ctx, - const struct asn_TYPE_descriptor_s *type_descriptor, - void **struct_ptr, /* Pointer to a target structure's pointer */ - const void *buffer, /* Data to be decoded */ - size_t size /* Size of that buffer */ - ); - -/* - * Type of generic function which decodes the byte stream into the structure. - */ -typedef asn_dec_rval_t(oer_type_decoder_f)( - const struct asn_codec_ctx_s *opt_codec_ctx, - const struct asn_TYPE_descriptor_s *type_descriptor, - const asn_oer_constraints_t *constraints, - void **struct_ptr, - const void *buf_ptr, - size_t size); - -/* - * Swallow the Open Type (X.696 (08/2015), #30) into /dev/null. - * RETURN VALUES: - * -1: Fatal error deciphering length. - * 0: More data expected than bufptr contains. - * >0: Number of bytes used from bufptr. - */ -ssize_t oer_open_type_skip(const void *bufptr, size_t size); - -/* - * Read the Open Type (X.696 (08/2015), #30). - * RETURN VALUES: - * 0: More data expected than bufptr contains. - * -1: Fatal error deciphering length. - * >0: Number of bytes used from bufptr. - */ -ssize_t oer_open_type_get(const asn_codec_ctx_t *opt_codec_ctx, - const struct asn_TYPE_descriptor_s *td, - const asn_oer_constraints_t *constraints, - void **struct_ptr, const void *bufptr, size_t size); - -/* - * Length-prefixed buffer decoding for primitive types. - */ -oer_type_decoder_f oer_decode_primitive; - - -#ifdef __cplusplus -} -#endif - -#endif /* OER_DECODER_H */ diff --git a/src/asn1/asn1c/oer_encoder.c b/src/asn1/asn1c/oer_encoder.c deleted file mode 100644 index a157450b..00000000 --- a/src/asn1/asn1c/oer_encoder.c +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Copyright (c) 2017 Lev Walkin . All rights reserved. - * Redistribution and modifications are permitted subject to BSD license. - */ - -#include - -#include "asn1/asn1c/asn_internal.h" -#include "asn1/asn1c/asn_codecs_prim.h" - -/* - * The OER encoder of any type. - */ -asn_enc_rval_t -oer_encode(const asn_TYPE_descriptor_t *type_descriptor, const void *struct_ptr, - asn_app_consume_bytes_f *consume_bytes, void *app_key) { - ASN_DEBUG("OER encoder invoked for %s", type_descriptor->name); - - /* - * Invoke type-specific encoder. - */ - return type_descriptor->op->oer_encoder( - type_descriptor, 0, - struct_ptr, /* Pointer to the destination structure */ - consume_bytes, app_key); -} - -/* - * Argument type and callback necessary for oer_encode_to_buffer(). - */ -typedef struct enc_to_buf_arg { - void *buffer; - size_t left; -} enc_to_buf_arg; -static int -encode_to_buffer_cb(const void *buffer, size_t size, void *key) { - enc_to_buf_arg *arg = (enc_to_buf_arg *)key; - - if(arg->left < size) return -1; /* Data exceeds the available buffer size */ - - memcpy(arg->buffer, buffer, size); - arg->buffer = ((char *)arg->buffer) + size; - arg->left -= size; - - return 0; -} - -/* - * A variant of the oer_encode() which encodes the data into the provided buffer - */ -asn_enc_rval_t -oer_encode_to_buffer(const asn_TYPE_descriptor_t *type_descriptor, - const asn_oer_constraints_t *constraints, - const void *struct_ptr, /* Structure to be encoded */ - void *buffer, /* Pre-allocated buffer */ - size_t buffer_size /* Initial buffer size (maximum) */ -) { - enc_to_buf_arg arg; - asn_enc_rval_t ec; - - arg.buffer = buffer; - arg.left = buffer_size; - - if(type_descriptor->op->oer_encoder == NULL) { - ec.encoded = -1; - ec.failed_type = type_descriptor; - ec.structure_ptr = struct_ptr; - ASN_DEBUG("OER encoder is not defined for %s", - type_descriptor->name); - } else { - ec = type_descriptor->op->oer_encoder( - type_descriptor, constraints, - struct_ptr, /* Pointer to the destination structure */ - encode_to_buffer_cb, &arg); - if(ec.encoded != -1) { - assert(ec.encoded == (ssize_t)(buffer_size - arg.left)); - /* Return the encoded contents size */ - } - } - return ec; -} - -asn_enc_rval_t -oer_encode_primitive(const asn_TYPE_descriptor_t *td, - const asn_oer_constraints_t *constraints, const void *sptr, - asn_app_consume_bytes_f *cb, void *app_key) { - const ASN__PRIMITIVE_TYPE_t *st = (const ASN__PRIMITIVE_TYPE_t *)sptr; - asn_enc_rval_t er = {0, 0, 0}; - ssize_t ret; - - (void)constraints; - - if(!st) ASN__ENCODE_FAILED; - - ASN_DEBUG("Encoding %s (%" ASN_PRI_SIZE " bytes)", td ? td->name : "", st->size); - - /* - * X.696 (08/2015) #27.2 - */ - ret = oer_serialize_length(st->size, cb, app_key); - if(ret < 0) { - ASN__ENCODE_FAILED; - } - er.encoded += ret; - - er.encoded += st->size; - if(cb(st->buf, st->size, app_key) < 0) { - ASN__ENCODE_FAILED; - } else { - ASN__ENCODED_OK(er); - } -} - -static int -oer__count_bytes(const void *buffer, size_t size, void *bytes_ptr) { - size_t *bytes = bytes_ptr; - (void)buffer; - *bytes += size; - return 0; -} - -ssize_t -oer_open_type_put(const asn_TYPE_descriptor_t *td, - const asn_oer_constraints_t *constraints, const void *sptr, - asn_app_consume_bytes_f *cb, void *app_key) { - size_t serialized_byte_count = 0; - asn_enc_rval_t er; - ssize_t len_len; - - er = td->op->oer_encoder(td, constraints, sptr, oer__count_bytes, - &serialized_byte_count); - if(er.encoded < 0) return -1; - assert(serialized_byte_count == (size_t)er.encoded); - - len_len = oer_serialize_length(serialized_byte_count, cb, app_key); - if(len_len == -1) return -1; - - er = td->op->oer_encoder(td, constraints, sptr, cb, app_key); - if(er.encoded < 0) return -1; - assert(serialized_byte_count == (size_t)er.encoded); - - return len_len + er.encoded; -} diff --git a/src/asn1/asn1c/oer_encoder.h b/src/asn1/asn1c/oer_encoder.h deleted file mode 100644 index 9c239e14..00000000 --- a/src/asn1/asn1c/oer_encoder.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (c) 2017 Lev Walkin . All rights reserved. - * Redistribution and modifications are permitted subject to BSD license. - */ -#ifndef OER_ENCODER_H -#define OER_ENCODER_H - -#include "asn1/asn1c/asn_application.h" - -#ifdef __cplusplus -extern "C" { -#endif - -struct asn_TYPE_descriptor_s; /* Forward declaration */ - -/* - * The Octet Encoding Rules (OER, X.696 08/2015) encoder for any type. - * This function may be invoked directly by the application. - * Produces CANONICAL-OER output compatible with CANONICAL-OER - * and BASIC-OER decoders. - */ -asn_enc_rval_t oer_encode(const struct asn_TYPE_descriptor_s *type_descriptor, - const void *struct_ptr, /* Structure to be encoded */ - asn_app_consume_bytes_f *consume_bytes_cb, - void *app_key /* Arbitrary callback argument */ -); - -/* A variant of oer_encode() which encodes data into the pre-allocated buffer */ -asn_enc_rval_t oer_encode_to_buffer( - const struct asn_TYPE_descriptor_s *type_descriptor, - const asn_oer_constraints_t *constraints, - const void *struct_ptr, /* Structure to be encoded */ - void *buffer, /* Pre-allocated buffer */ - size_t buffer_size /* Initial buffer size (maximum) */ -); - -/* - * Type of the generic OER encoder. - */ -typedef asn_enc_rval_t(oer_type_encoder_f)( - const struct asn_TYPE_descriptor_s *type_descriptor, - const asn_oer_constraints_t *constraints, - const void *struct_ptr, /* Structure to be encoded */ - asn_app_consume_bytes_f *consume_bytes_cb, /* Callback */ - void *app_key /* Arbitrary callback argument */ -); - -/* - * Write out the Open Type (X.696 (08/2015), #30). - * RETURN VALUES: - * -1: Fatal error encoding the type. - * >0: Number of bytes serialized. - */ -ssize_t oer_open_type_put(const struct asn_TYPE_descriptor_s *td, - const asn_oer_constraints_t *constraints, - const void *struct_ptr, - asn_app_consume_bytes_f *consume_bytes_cb, - void *app_key); - - -/* - * Length-prefixed buffer encoding for primitive types. - */ -oer_type_encoder_f oer_encode_primitive; - -#ifdef __cplusplus -} -#endif - -#endif /* OER_ENCODER_H */ diff --git a/src/asn1/asn1c/oer_support.c b/src/asn1/asn1c/oer_support.c deleted file mode 100644 index 4e05d1f3..00000000 --- a/src/asn1/asn1c/oer_support.c +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright (c) 2017 Lev Walkin . - * All rights reserved. - * Redistribution and modifications are permitted subject to BSD license. - */ - -#include - -#include "asn1/asn1c/asn_system.h" -#include "asn1/asn1c/asn_internal.h" - -#include "asn1/asn1c/oer_support.h" - -/* - * Fetch the length determinant (X.696 08/2015, #8.6) into *len_r. - * RETURN VALUES: - * 0: More data expected than bufptr contains. - * -1: Fatal error deciphering length. - * >0: Number of bytes used from bufptr. - */ -ssize_t -oer_fetch_length(const void *bufptr, size_t size, size_t *len_r) { - uint8_t first_byte; - size_t len_len; /* Length of the length determinant */ - const uint8_t *b; - const uint8_t *bend; - size_t len; - - if(size == 0) { - *len_r = 0; - return 0; - } - - first_byte = *(const uint8_t *)bufptr; - if((first_byte & 0x80) == 0) { /* Short form */ - *len_r = first_byte; /* 0..127 */ - return 1; - } - - len_len = (first_byte & 0x7f); - if((1 + len_len) > size) { - *len_r = 0; - return 0; - } - - b = (const uint8_t *)bufptr + 1; - bend = b + len_len; - - for(; b < bend && *b == 0; b++) { - /* Skip the leading 0-bytes */ - } - - if((bend - b) > (ssize_t)sizeof(size_t)) { - /* Length is not representable by the native size_t type */ - *len_r = 0; - return -1; - } - - for(len = 0; b < bend; b++) { - len = (len << 8) + *b; - } - - if(len > RSIZE_MAX) { /* A bit of C11 validation */ - *len_r = 0; - return -1; - } - - *len_r = len; - assert(len_len + 1 == (size_t)(bend - (const uint8_t *)bufptr)); - return len_len + 1; -} - - -/* - * Serialize OER length. Returns the number of bytes serialized - * or -1 if a given callback returned with negative result. - */ -ssize_t -oer_serialize_length(size_t length, asn_app_consume_bytes_f *cb, - void *app_key) { - uint8_t scratch[1 + sizeof(length)]; - uint8_t *sp = scratch; - int littleEndian = 1; /* Run-time detection */ - const uint8_t *pstart; - const uint8_t *pend; - const uint8_t *p; - int add; - - if(length <= 127) { - uint8_t b = length; - if(cb(&b, 1, app_key) < 0) { - return -1; - } - return 1; - } - - if(*(char *)&littleEndian) { - pstart = (const uint8_t *)&length + sizeof(length) - 1; - pend = (const uint8_t *)&length; - add = -1; - } else { - pstart = (const uint8_t *)&length; - pend = pstart + sizeof(length); - add = 1; - } - - for(p = pstart; p != pend; p += add) { - /* Skip leading zeros. */ - if(*p) break; - } - - for(sp = scratch + 1; ; p += add) { - *sp++ = *p; - if(p == pend) break; - } - assert((sp - scratch) - 1 <= 0x7f); - scratch[0] = 0x80 + ((sp - scratch) - 1); - - if(cb(scratch, sp - scratch, app_key) < 0) { - return -1; - } - - return sp - scratch; -} diff --git a/src/asn1/asn1c/oer_support.h b/src/asn1/asn1c/oer_support.h deleted file mode 100644 index 741879b8..00000000 --- a/src/asn1/asn1c/oer_support.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2017 Lev Walkin . All rights reserved. - * Redistribution and modifications are permitted subject to BSD license. - */ -#ifndef OER_SUPPORT_H -#define OER_SUPPORT_H - -#include "asn1/asn1c/asn_system.h" /* Platform-specific types */ - -#ifdef __cplusplus -extern "C" { -#endif - -/* - * Pre-computed OER constraints. - */ -typedef struct asn_oer_constraint_number_s { - unsigned width; /* ±8,4,2,1 fixed bytes */ - unsigned positive; /* 1 for unsigned number, 0 for signed */ -} asn_oer_constraint_number_t; -typedef struct asn_oer_constraints_s { - asn_oer_constraint_number_t value; - ssize_t size; /* -1 (no constraint) or >= 0 */ -} asn_oer_constraints_t; - - -/* - * Fetch the length determinant (X.696 (08/2015), #8.6) into *len_r. - * RETURN VALUES: - * 0: More data expected than bufptr contains. - * -1: Fatal error deciphering length. - * >0: Number of bytes used from bufptr. - */ -ssize_t oer_fetch_length(const void *bufptr, size_t size, size_t *len_r); - -/* - * Serialize OER length. Returns the number of bytes serialized - * or -1 if a given callback returned with negative result. - */ -ssize_t oer_serialize_length(size_t length, asn_app_consume_bytes_f *cb, void *app_key); - - -#ifdef __cplusplus -} -#endif - -#endif /* OER_SUPPORT_H */ diff --git a/src/asn1/asn1c/per_decoder.c b/src/asn1/asn1c/per_decoder.c deleted file mode 100644 index 5099a40c..00000000 --- a/src/asn1/asn1c/per_decoder.c +++ /dev/null @@ -1,98 +0,0 @@ -#include - -#include "asn1/asn1c/asn_application.h" -#include "asn1/asn1c/asn_internal.h" -#include "asn1/asn1c/per_decoder.h" - -/* - * Decode a "Production of a complete encoding", X.691#10.1. - * The complete encoding contains at least one byte, and is an integral - * multiple of 8 bytes. - */ -asn_dec_rval_t -uper_decode_complete(const asn_codec_ctx_t *opt_codec_ctx, - const asn_TYPE_descriptor_t *td, void **sptr, - const void *buffer, size_t size) { - asn_dec_rval_t rval; - - rval = uper_decode(opt_codec_ctx, td, sptr, buffer, size, 0, 0); - if(rval.consumed) { - /* - * We've always given 8-aligned data, - * so convert bits to integral bytes. - */ - rval.consumed += 7; - rval.consumed >>= 3; - } else if(rval.code == RC_OK) { - if(size) { - if(((const uint8_t *)buffer)[0] == 0) { - rval.consumed = 1; /* 1 byte */ - } else { - ASN_DEBUG("Expecting single zeroed byte"); - rval.code = RC_FAIL; - } - } else { - /* Must contain at least 8 bits. */ - rval.code = RC_WMORE; - } - } - - return rval; -} - -asn_dec_rval_t -uper_decode(const asn_codec_ctx_t *opt_codec_ctx, - const asn_TYPE_descriptor_t *td, void **sptr, const void *buffer, - size_t size, int skip_bits, int unused_bits) { - asn_codec_ctx_t s_codec_ctx; - asn_dec_rval_t rval; - asn_per_data_t pd; - - if(skip_bits < 0 || skip_bits > 7 - || unused_bits < 0 || unused_bits > 7 - || (unused_bits > 0 && !size)) - ASN__DECODE_FAILED; - - /* - * Stack checker requires that the codec context - * must be allocated on the stack. - */ - if(opt_codec_ctx) { - if(opt_codec_ctx->max_stack_size) { - s_codec_ctx = *opt_codec_ctx; - opt_codec_ctx = &s_codec_ctx; - } - } else { - /* If context is not given, be security-conscious anyway */ - memset(&s_codec_ctx, 0, sizeof(s_codec_ctx)); - s_codec_ctx.max_stack_size = ASN__DEFAULT_STACK_MAX; - opt_codec_ctx = &s_codec_ctx; - } - - /* Fill in the position indicator */ - memset(&pd, 0, sizeof(pd)); - pd.buffer = (const uint8_t *)buffer; - pd.nboff = skip_bits; - pd.nbits = 8 * size - unused_bits; /* 8 is CHAR_BIT from */ - if(pd.nboff > pd.nbits) - ASN__DECODE_FAILED; - - /* - * Invoke type-specific decoder. - */ - if(!td->op->uper_decoder) - ASN__DECODE_FAILED; /* PER is not compiled in */ - rval = td->op->uper_decoder(opt_codec_ctx, td, 0, sptr, &pd); - if(rval.code == RC_OK) { - /* Return the number of consumed bits */ - rval.consumed = ((pd.buffer - (const uint8_t *)buffer) << 3) - + pd.nboff - skip_bits; - ASN_DEBUG("PER decoding consumed %ld, counted %ld", - (long)rval.consumed, (long)pd.moved); - assert(rval.consumed == pd.moved); - } else { - /* PER codec is not a restartable */ - rval.consumed = 0; - } - return rval; -} diff --git a/src/asn1/asn1c/per_decoder.h b/src/asn1/asn1c/per_decoder.h deleted file mode 100644 index fd61fca6..00000000 --- a/src/asn1/asn1c/per_decoder.h +++ /dev/null @@ -1,57 +0,0 @@ -/*- - * Copyright (c) 2005-2017 Lev Walkin . All rights reserved. - * Redistribution and modifications are permitted subject to BSD license. - */ -#ifndef _PER_DECODER_H_ -#define _PER_DECODER_H_ - -#include "asn1/asn1c/asn_application.h" -#include "asn1/asn1c/per_support.h" - -#ifdef __cplusplus -extern "C" { -#endif - -struct asn_TYPE_descriptor_s; /* Forward declaration */ - -/* - * Unaligned PER decoder of a "complete encoding" as per X.691 (08/2015) #11.1. - * On success, this call always returns (.consumed >= 1), as per #11.1.3. - */ -asn_dec_rval_t uper_decode_complete( - const struct asn_codec_ctx_s *opt_codec_ctx, - const struct asn_TYPE_descriptor_s *type_descriptor, /* Type to decode */ - void **struct_ptr, /* Pointer to a target structure's pointer */ - const void *buffer, /* Data to be decoded */ - size_t size /* Size of data buffer */ -); - -/* - * Unaligned PER decoder of any ASN.1 type. May be invoked by the application. - * WARNING: This call returns the number of BITS read from the stream. Beware. - */ -asn_dec_rval_t uper_decode( - const struct asn_codec_ctx_s *opt_codec_ctx, - const struct asn_TYPE_descriptor_s *type_descriptor, /* Type to decode */ - void **struct_ptr, /* Pointer to a target structure's pointer */ - const void *buffer, /* Data to be decoded */ - size_t size, /* Size of the input data buffer, in bytes */ - int skip_bits, /* Number of unused leading bits, 0..7 */ - int unused_bits /* Number of unused tailing bits, 0..7 */ -); - - -/* - * Type of the type-specific PER decoder function. - */ -typedef asn_dec_rval_t(per_type_decoder_f)( - const asn_codec_ctx_t *opt_codec_ctx, - const struct asn_TYPE_descriptor_s *type_descriptor, - const asn_per_constraints_t *constraints, void **struct_ptr, - asn_per_data_t *per_data); - -#ifdef __cplusplus -} -#endif - -#endif /* _PER_DECODER_H_ */ diff --git a/src/asn1/asn1c/per_encoder.c b/src/asn1/asn1c/per_encoder.c deleted file mode 100644 index 8e061e13..00000000 --- a/src/asn1/asn1c/per_encoder.c +++ /dev/null @@ -1,164 +0,0 @@ -#include "asn1/asn1c/asn_application.h" -#include "asn1/asn1c/asn_internal.h" -#include "asn1/asn1c/per_encoder.h" - -static int _uper_encode_flush_outp(asn_per_outp_t *po); - -static int -ignore_output(const void *data, size_t size, void *app_key) { - (void)data; - (void)size; - (void)app_key; - return 0; -} - -asn_enc_rval_t -uper_encode(const asn_TYPE_descriptor_t *td, - const asn_per_constraints_t *constraints, const void *sptr, - asn_app_consume_bytes_f *cb, void *app_key) { - asn_per_outp_t po; - asn_enc_rval_t er; - - /* - * Invoke type-specific encoder. - */ - if(!td || !td->op->uper_encoder) - ASN__ENCODE_FAILED; /* PER is not compiled in */ - - po.buffer = po.tmpspace; - po.nboff = 0; - po.nbits = 8 * sizeof(po.tmpspace); - po.output = cb ? cb : ignore_output; - po.op_key = app_key; - po.flushed_bytes = 0; - - er = td->op->uper_encoder(td, constraints, sptr, &po); - if(er.encoded != -1) { - size_t bits_to_flush; - - bits_to_flush = ((po.buffer - po.tmpspace) << 3) + po.nboff; - - /* Set number of bits encoded to a firm value */ - er.encoded = (po.flushed_bytes << 3) + bits_to_flush; - - if(_uper_encode_flush_outp(&po)) ASN__ENCODE_FAILED; - } - - return er; -} - -/* - * Argument type and callback necessary for uper_encode_to_buffer(). - */ -typedef struct enc_to_buf_arg { - void *buffer; - size_t left; -} enc_to_buf_arg; -static int encode_to_buffer_cb(const void *buffer, size_t size, void *key) { - enc_to_buf_arg *arg = (enc_to_buf_arg *)key; - - if(arg->left < size) - return -1; /* Data exceeds the available buffer size */ - - memcpy(arg->buffer, buffer, size); - arg->buffer = ((char *)arg->buffer) + size; - arg->left -= size; - - return 0; -} - -asn_enc_rval_t -uper_encode_to_buffer(const asn_TYPE_descriptor_t *td, - const asn_per_constraints_t *constraints, - const void *sptr, void *buffer, size_t buffer_size) { - enc_to_buf_arg key; - - key.buffer = buffer; - key.left = buffer_size; - - if(td) ASN_DEBUG("Encoding \"%s\" using UNALIGNED PER", td->name); - - return uper_encode(td, constraints, sptr, encode_to_buffer_cb, &key); -} - -typedef struct enc_dyn_arg { - void *buffer; - size_t length; - size_t allocated; -} enc_dyn_arg; -static int -encode_dyn_cb(const void *buffer, size_t size, void *key) { - enc_dyn_arg *arg = key; - if(arg->length + size >= arg->allocated) { - size_t new_size = arg->allocated ? arg->allocated : 8; - void *p; - - do { - new_size <<= 2; - } while(arg->length + size >= new_size); - - p = REALLOC(arg->buffer, new_size); - if(!p) { - FREEMEM(arg->buffer); - memset(arg, 0, sizeof(*arg)); - return -1; - } - arg->buffer = p; - arg->allocated = new_size; - } - memcpy(((char *)arg->buffer) + arg->length, buffer, size); - arg->length += size; - return 0; -} -ssize_t -uper_encode_to_new_buffer(const asn_TYPE_descriptor_t *td, - const asn_per_constraints_t *constraints, - const void *sptr, void **buffer_r) { - asn_enc_rval_t er; - enc_dyn_arg key; - - memset(&key, 0, sizeof(key)); - - er = uper_encode(td, constraints, sptr, encode_dyn_cb, &key); - switch(er.encoded) { - case -1: - FREEMEM(key.buffer); - return -1; - case 0: - FREEMEM(key.buffer); - key.buffer = MALLOC(1); - if(key.buffer) { - *(char *)key.buffer = '\0'; - *buffer_r = key.buffer; - return 1; - } else { - return -1; - } - default: - *buffer_r = key.buffer; - ASN_DEBUG("Complete encoded in %ld bits", (long)er.encoded); - return ((er.encoded + 7) >> 3); - } -} - -/* - * Internally useful functions. - */ - -/* Flush partially filled buffer */ -static int -_uper_encode_flush_outp(asn_per_outp_t *po) { - uint8_t *buf; - - if(po->nboff == 0 && po->buffer == po->tmpspace) - return 0; - - buf = po->buffer + (po->nboff >> 3); - /* Make sure we account for the last, partially filled */ - if(po->nboff & 0x07) { - buf[0] &= 0xff << (8 - (po->nboff & 0x07)); - buf++; - } - - return po->output(po->tmpspace, buf - po->tmpspace, po->op_key); -} diff --git a/src/asn1/asn1c/per_encoder.h b/src/asn1/asn1c/per_encoder.h deleted file mode 100644 index cd9e865d..00000000 --- a/src/asn1/asn1c/per_encoder.h +++ /dev/null @@ -1,70 +0,0 @@ -/*- - * Copyright (c) 2006-2017 Lev Walkin . All rights reserved. - * Redistribution and modifications are permitted subject to BSD license. - */ -#ifndef _PER_ENCODER_H_ -#define _PER_ENCODER_H_ - -#include "asn1/asn1c/asn_application.h" -#include "asn1/asn1c/per_support.h" - -#ifdef __cplusplus -extern "C" { -#endif - -struct asn_TYPE_descriptor_s; /* Forward declaration */ - -/* - * Unaligned PER encoder of any ASN.1 type. May be invoked by the application. - * WARNING: This function returns the number of encoded bits in the .encoded - * field of the return value. Use the following formula to convert to bytes: - * bytes = ((.encoded + 7) / 8) - */ -asn_enc_rval_t uper_encode( - const struct asn_TYPE_descriptor_s *type_descriptor, - const asn_per_constraints_t *constraints, - const void *struct_ptr, /* Structure to be encoded */ - asn_app_consume_bytes_f *consume_bytes_cb, /* Data collector */ - void *app_key /* Arbitrary callback argument */ -); - -/* - * A variant of uper_encode() which encodes data into the existing buffer - * WARNING: This function returns the number of encoded bits in the .encoded - * field of the return value. - */ -asn_enc_rval_t uper_encode_to_buffer( - const struct asn_TYPE_descriptor_s *type_descriptor, - const asn_per_constraints_t *constraints, - const void *struct_ptr, /* Structure to be encoded */ - void *buffer, /* Pre-allocated buffer */ - size_t buffer_size /* Initial buffer size (max) */ -); - -/* - * A variant of uper_encode_to_buffer() which allocates buffer itself. - * Returns the number of bytes in the buffer or -1 in case of failure. - * WARNING: This function produces a "Production of the complete encoding", - * with length of at least one octet. Contrast this to precise bit-packing - * encoding of uper_encode() and uper_encode_to_buffer(). - */ -ssize_t uper_encode_to_new_buffer( - const struct asn_TYPE_descriptor_s *type_descriptor, - const asn_per_constraints_t *constraints, - const void *struct_ptr, /* Structure to be encoded */ - void **buffer_r /* Buffer allocated and returned */ -); - -/* - * Type of the generic PER encoder function. - */ -typedef asn_enc_rval_t(per_type_encoder_f)( - const struct asn_TYPE_descriptor_s *type_descriptor, - const asn_per_constraints_t *constraints, const void *struct_ptr, - asn_per_outp_t *per_output); - -#ifdef __cplusplus -} -#endif - -#endif /* _PER_ENCODER_H_ */ diff --git a/src/asn1/asn1c/per_opentype.c b/src/asn1/asn1c/per_opentype.c deleted file mode 100644 index 49b1e8de..00000000 --- a/src/asn1/asn1c/per_opentype.c +++ /dev/null @@ -1,399 +0,0 @@ -/* - * Copyright (c) 2007 Lev Walkin . All rights reserved. - * Redistribution and modifications are permitted subject to BSD license. - */ - -#include - -#include "asn1/asn1c/asn_internal.h" -#include "asn1/asn1c/per_support.h" -#include "asn1/asn1c/constr_TYPE.h" -#include "asn1/asn1c/per_opentype.h" - -typedef struct uper_ugot_key { - asn_per_data_t oldpd; /* Old per data source */ - size_t unclaimed; - size_t ot_moved; /* Number of bits moved by OT processing */ - int repeat; -} uper_ugot_key; - -static int uper_ugot_refill(asn_per_data_t *pd); -static int per_skip_bits(asn_per_data_t *pd, int skip_nbits); -static asn_dec_rval_t uper_sot_suck(const asn_codec_ctx_t *, - const asn_TYPE_descriptor_t *td, - const asn_per_constraints_t *constraints, - void **sptr, asn_per_data_t *pd); - -/* - * Encode an "open type field". - * #10.1, #10.2 - */ -int -uper_open_type_put(const asn_TYPE_descriptor_t *td, - const asn_per_constraints_t *constraints, const void *sptr, - asn_per_outp_t *po) { - void *buf; - void *bptr; - ssize_t size; - - ASN_DEBUG("Open type put %s ...", td->name); - - size = uper_encode_to_new_buffer(td, constraints, sptr, &buf); - if(size <= 0) return -1; - - ASN_DEBUG("Open type put %s of length %" ASN_PRI_SSIZE " + overhead (1byte?)", td->name, - size); - - bptr = buf; - do { - int need_eom = 0; - ssize_t may_save = uper_put_length(po, size, &need_eom); - ASN_DEBUG("Prepending length %" ASN_PRI_SSIZE - " to %s and allowing to save %" ASN_PRI_SSIZE, - size, td->name, may_save); - if(may_save < 0) break; - if(per_put_many_bits(po, bptr, may_save * 8)) break; - bptr = (char *)bptr + may_save; - size -= may_save; - if(need_eom && uper_put_length(po, 0, 0)) { - FREEMEM(buf); - return -1; - } - } while(size); - - FREEMEM(buf); - if(size) return -1; - - return 0; -} - -static asn_dec_rval_t -uper_open_type_get_simple(const asn_codec_ctx_t *ctx, - const asn_TYPE_descriptor_t *td, - const asn_per_constraints_t *constraints, void **sptr, - asn_per_data_t *pd) { - asn_dec_rval_t rv; - ssize_t chunk_bytes; - int repeat; - uint8_t *buf = 0; - size_t bufLen = 0; - size_t bufSize = 0; - asn_per_data_t spd; - size_t padding; - - ASN__STACK_OVERFLOW_CHECK(ctx); - - ASN_DEBUG("Getting open type %s...", td->name); - - do { - chunk_bytes = uper_get_length(pd, -1, 0, &repeat); - if(chunk_bytes < 0) { - FREEMEM(buf); - ASN__DECODE_STARVED; - } - if(bufLen + chunk_bytes > bufSize) { - void *ptr; - bufSize = chunk_bytes + (bufSize << 2); - ptr = REALLOC(buf, bufSize); - if(!ptr) { - FREEMEM(buf); - ASN__DECODE_FAILED; - } - buf = ptr; - } - if(per_get_many_bits(pd, buf + bufLen, 0, chunk_bytes << 3)) { - FREEMEM(buf); - ASN__DECODE_STARVED; - } - bufLen += chunk_bytes; - } while(repeat); - - ASN_DEBUG("Getting open type %s encoded in %ld bytes", td->name, - (long)bufLen); - - memset(&spd, 0, sizeof(spd)); - spd.buffer = buf; - spd.nbits = bufLen << 3; - - ASN_DEBUG_INDENT_ADD(+4); - rv = td->op->uper_decoder(ctx, td, constraints, sptr, &spd); - ASN_DEBUG_INDENT_ADD(-4); - - if(rv.code == RC_OK) { - /* Check padding validity */ - padding = spd.nbits - spd.nboff; - if ((padding < 8 || - /* X.691#10.1.3 */ - (spd.nboff == 0 && spd.nbits == 8 && spd.buffer == buf)) && - per_get_few_bits(&spd, padding) == 0) { - /* Everything is cool */ - FREEMEM(buf); - return rv; - } - FREEMEM(buf); - if(padding >= 8) { - ASN_DEBUG("Too large padding %d in open type", (int)padding); - ASN__DECODE_FAILED; - } else { - ASN_DEBUG("Non-zero padding"); - ASN__DECODE_FAILED; - } - } else { - FREEMEM(buf); - /* rv.code could be RC_WMORE, nonsense in this context */ - rv.code = RC_FAIL; /* Noone would give us more */ - } - - return rv; -} - -static asn_dec_rval_t CC_NOTUSED -uper_open_type_get_complex(const asn_codec_ctx_t *ctx, - const asn_TYPE_descriptor_t *td, - asn_per_constraints_t *constraints, void **sptr, - asn_per_data_t *pd) { - uper_ugot_key arg; - asn_dec_rval_t rv; - ssize_t padding; - - ASN__STACK_OVERFLOW_CHECK(ctx); - - ASN_DEBUG("Getting open type %s from %s", td->name, - asn_bit_data_string(pd)); - arg.oldpd = *pd; - arg.unclaimed = 0; - arg.ot_moved = 0; - arg.repeat = 1; - pd->refill = uper_ugot_refill; - pd->refill_key = &arg; - pd->nbits = pd->nboff; /* 0 good bits at this point, will refill */ - pd->moved = 0; /* This now counts the open type size in bits */ - - ASN_DEBUG_INDENT_ADD(+4); - rv = td->op->uper_decoder(ctx, td, constraints, sptr, pd); - ASN_DEBUG_INDENT_ADD(-4); - -#define UPDRESTOREPD do { \ - /* buffer and nboff are valid, preserve them. */ \ - pd->nbits = arg.oldpd.nbits - (pd->moved - arg.ot_moved); \ - pd->moved = arg.oldpd.moved + (pd->moved - arg.ot_moved); \ - pd->refill = arg.oldpd.refill; \ - pd->refill_key = arg.oldpd.refill_key; \ - } while(0) - - if(rv.code != RC_OK) { - UPDRESTOREPD; - return rv; - } - - ASN_DEBUG("OpenType %s pd%s old%s unclaimed=%d, repeat=%d", td->name, - asn_bit_data_string(pd), - asn_bit_data_string(&arg.oldpd), - (int)arg.unclaimed, (int)arg.repeat); - - padding = pd->moved % 8; - if(padding) { - int32_t pvalue; - if(padding > 7) { - ASN_DEBUG("Too large padding %d in open type", - (int)padding); - rv.code = RC_FAIL; - UPDRESTOREPD; - return rv; - } - padding = 8 - padding; - ASN_DEBUG("Getting padding of %d bits", (int)padding); - pvalue = per_get_few_bits(pd, padding); - switch(pvalue) { - case -1: - ASN_DEBUG("Padding skip failed"); - UPDRESTOREPD; - ASN__DECODE_STARVED; - case 0: break; - default: - ASN_DEBUG("Non-blank padding (%d bits 0x%02x)", - (int)padding, (int)pvalue); - UPDRESTOREPD; - ASN__DECODE_FAILED; - } - } - if(pd->nboff != pd->nbits) { - ASN_DEBUG("Open type %s overhead pd%s old%s", td->name, - asn_bit_data_string(pd), asn_bit_data_string(&arg.oldpd)); - if(1) { - UPDRESTOREPD; - ASN__DECODE_FAILED; - } else { - arg.unclaimed += pd->nbits - pd->nboff; - } - } - - /* Adjust pd back so it points to original data */ - UPDRESTOREPD; - - /* Skip data not consumed by the decoder */ - if(arg.unclaimed) { - ASN_DEBUG("Getting unclaimed %d", (int)arg.unclaimed); - switch(per_skip_bits(pd, arg.unclaimed)) { - case -1: - ASN_DEBUG("Claim of %d failed", (int)arg.unclaimed); - ASN__DECODE_STARVED; - case 0: - ASN_DEBUG("Got claim of %d", (int)arg.unclaimed); - break; - default: - /* Padding must be blank */ - ASN_DEBUG("Non-blank unconsumed padding"); - ASN__DECODE_FAILED; - } - arg.unclaimed = 0; - } - - if(arg.repeat) { - ASN_DEBUG("Not consumed the whole thing"); - rv.code = RC_FAIL; - return rv; - } - - return rv; -} - - -asn_dec_rval_t -uper_open_type_get(const asn_codec_ctx_t *ctx, const asn_TYPE_descriptor_t *td, - const asn_per_constraints_t *constraints, void **sptr, - asn_per_data_t *pd) { - return uper_open_type_get_simple(ctx, td, constraints, sptr, pd); -} - -int -uper_open_type_skip(const asn_codec_ctx_t *ctx, asn_per_data_t *pd) { - asn_TYPE_descriptor_t s_td; - asn_TYPE_operation_t s_op; - asn_dec_rval_t rv; - - s_td.name = ""; - s_td.op = &s_op; - s_op.uper_decoder = uper_sot_suck; - - rv = uper_open_type_get(ctx, &s_td, 0, 0, pd); - if(rv.code != RC_OK) - return -1; - else - return 0; -} - -/* - * Internal functions. - */ - -static asn_dec_rval_t -uper_sot_suck(const asn_codec_ctx_t *ctx, const asn_TYPE_descriptor_t *td, - const asn_per_constraints_t *constraints, void **sptr, - asn_per_data_t *pd) { - asn_dec_rval_t rv; - - (void)ctx; - (void)td; - (void)constraints; - (void)sptr; - - while(per_get_few_bits(pd, 24) >= 0); - - rv.code = RC_OK; - rv.consumed = pd->moved; - - return rv; -} - -static int -uper_ugot_refill(asn_per_data_t *pd) { - uper_ugot_key *arg = pd->refill_key; - ssize_t next_chunk_bytes, next_chunk_bits; - ssize_t avail; - - asn_per_data_t *oldpd = &arg->oldpd; - - ASN_DEBUG("REFILLING pd->moved=%ld, oldpd->moved=%ld", - (long)pd->moved, (long)oldpd->moved); - - /* Advance our position to where pd is */ - oldpd->buffer = pd->buffer; - oldpd->nboff = pd->nboff; - oldpd->nbits -= pd->moved - arg->ot_moved; - oldpd->moved += pd->moved - arg->ot_moved; - arg->ot_moved = pd->moved; - - if(arg->unclaimed) { - /* Refill the container */ - if(per_get_few_bits(oldpd, 1)) - return -1; - if(oldpd->nboff == 0) { - assert(0); - return -1; - } - pd->buffer = oldpd->buffer; - pd->nboff = oldpd->nboff - 1; - pd->nbits = oldpd->nbits; - ASN_DEBUG("UNCLAIMED <- return from (pd->moved=%ld)", - (long)pd->moved); - return 0; - } - - if(!arg->repeat) { - ASN_DEBUG("Want more but refill doesn't have it"); - return -1; - } - - next_chunk_bytes = uper_get_length(oldpd, -1, 0, &arg->repeat); - ASN_DEBUG("Open type LENGTH %ld bytes at off %ld, repeat %ld", - (long)next_chunk_bytes, (long)oldpd->moved, (long)arg->repeat); - if(next_chunk_bytes < 0) return -1; - if(next_chunk_bytes == 0) { - pd->refill = 0; /* No more refills, naturally */ - assert(!arg->repeat); /* Implementation guarantee */ - } - next_chunk_bits = next_chunk_bytes << 3; - avail = oldpd->nbits - oldpd->nboff; - if(avail >= next_chunk_bits) { - pd->nbits = oldpd->nboff + next_chunk_bits; - arg->unclaimed = 0; - ASN_DEBUG("!+Parent frame %ld bits, alloting %ld [%ld..%ld] (%ld)", - (long)next_chunk_bits, (long)oldpd->moved, - (long)oldpd->nboff, (long)oldpd->nbits, - (long)(oldpd->nbits - oldpd->nboff)); - } else { - pd->nbits = oldpd->nbits; - arg->unclaimed = next_chunk_bits - avail; - ASN_DEBUG("!-Parent frame %ld, require %ld, will claim %ld", - (long)avail, (long)next_chunk_bits, - (long)arg->unclaimed); - } - pd->buffer = oldpd->buffer; - pd->nboff = oldpd->nboff; - ASN_DEBUG("Refilled pd%s old%s", - asn_bit_data_string(pd), asn_bit_data_string(oldpd)); - return 0; -} - -static int -per_skip_bits(asn_per_data_t *pd, int skip_nbits) { - int hasNonZeroBits = 0; - while(skip_nbits > 0) { - int skip; - - /* per_get_few_bits() is more efficient when nbits <= 24 */ - if(skip_nbits < 24) - skip = skip_nbits; - else - skip = 24; - skip_nbits -= skip; - - switch(per_get_few_bits(pd, skip)) { - case -1: return -1; /* Starving */ - case 0: continue; /* Skipped empty space */ - default: hasNonZeroBits = 1; continue; - } - } - return hasNonZeroBits; -} diff --git a/src/asn1/asn1c/per_opentype.h b/src/asn1/asn1c/per_opentype.h deleted file mode 100644 index 7e7dc610..00000000 --- a/src/asn1/asn1c/per_opentype.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2007-2017 Lev Walkin . All rights reserved. - * Redistribution and modifications are permitted subject to BSD license. - */ -#ifndef _PER_OPENTYPE_H_ -#define _PER_OPENTYPE_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -asn_dec_rval_t uper_open_type_get(const asn_codec_ctx_t *opt_codec_ctx, - const asn_TYPE_descriptor_t *td, - const asn_per_constraints_t *constraints, - void **sptr, asn_per_data_t *pd); - -int uper_open_type_skip(const asn_codec_ctx_t *opt_codec_ctx, - asn_per_data_t *pd); - -/* - * X.691 (2015/08), #11.2 - * Returns -1 if error is encountered. 0 if all OK. - */ -int uper_open_type_put(const asn_TYPE_descriptor_t *td, - const asn_per_constraints_t *constraints, - const void *sptr, asn_per_outp_t *po); - -#ifdef __cplusplus -} -#endif - -#endif /* _PER_OPENTYPE_H_ */ diff --git a/src/asn1/asn1c/per_support.c b/src/asn1/asn1c/per_support.c deleted file mode 100644 index 5633293e..00000000 --- a/src/asn1/asn1c/per_support.c +++ /dev/null @@ -1,298 +0,0 @@ -/* - * Copyright (c) 2005-2017 Lev Walkin . All rights reserved. - * Redistribution and modifications are permitted subject to BSD license. - */ - -#include - -#include "asn1/asn1c/asn_system.h" -#include "asn1/asn1c/asn_internal.h" -#include "asn1/asn1c/per_support.h" - -/* - * X.691-201508 #10.9 General rules for encoding a length determinant. - * Get the optionally constrained length "n" from the stream. - */ -ssize_t -uper_get_length(asn_per_data_t *pd, int ebits, size_t lower_bound, - int *repeat) { - ssize_t value; - - *repeat = 0; - - /* #11.9.4.1 Encoding if constrained (according to effective bits) */ - if(ebits >= 0 && ebits <= 16) { - value = per_get_few_bits(pd, ebits); - if(value >= 0) value += lower_bound; - return value; - } - - value = per_get_few_bits(pd, 8); - if((value & 0x80) == 0) { /* #11.9.3.6 */ - return (value & 0x7F); - } else if((value & 0x40) == 0) { /* #11.9.3.7 */ - /* bit 8 ... set to 1 and bit 7 ... set to zero */ - value = ((value & 0x3f) << 8) | per_get_few_bits(pd, 8); - return value; /* potential -1 from per_get_few_bits passes through. */ - } else if(value < 0) { - ASN_DEBUG("END of stream reached for PER"); - return -1; - } - value &= 0x3f; /* this is "m" from X.691, #11.9.3.8 */ - if(value < 1 || value > 4) { - return -1; /* Prohibited by #11.9.3.8 */ - } - *repeat = 1; - return (16384 * value); -} - -/* - * Get the normally small length "n". - * This procedure used to decode length of extensions bit-maps - * for SET and SEQUENCE types. - */ -ssize_t -uper_get_nslength(asn_per_data_t *pd) { - ssize_t length; - - ASN_DEBUG("Getting normally small length"); - - if(per_get_few_bits(pd, 1) == 0) { - length = per_get_few_bits(pd, 6) + 1; - if(length <= 0) return -1; - ASN_DEBUG("l=%d", (int)length); - return length; - } else { - int repeat; - length = uper_get_length(pd, -1, 0, &repeat); - if(length >= 0 && !repeat) return length; - return -1; /* Error, or do not support >16K extensions */ - } -} - -/* - * Get the normally small non-negative whole number. - * X.691, #10.6 - */ -ssize_t -uper_get_nsnnwn(asn_per_data_t *pd) { - ssize_t value; - - value = per_get_few_bits(pd, 7); - if(value & 64) { /* implicit (value < 0) */ - value &= 63; - value <<= 2; - value |= per_get_few_bits(pd, 2); - if(value & 128) /* implicit (value < 0) */ - return -1; - if(value == 0) - return 0; - if(value >= 3) - return -1; - value = per_get_few_bits(pd, 8 * value); - return value; - } - - return value; -} - -/* - * X.691-11/2008, #11.6 - * Encoding of a normally small non-negative whole number - */ -int -uper_put_nsnnwn(asn_per_outp_t *po, int n) { - int bytes; - - if(n <= 63) { - if(n < 0) return -1; - return per_put_few_bits(po, n, 7); - } - if(n < 256) - bytes = 1; - else if(n < 65536) - bytes = 2; - else if(n < 256 * 65536) - bytes = 3; - else - return -1; /* This is not a "normally small" value */ - if(per_put_few_bits(po, bytes, 8)) - return -1; - - return per_put_few_bits(po, n, 8 * bytes); -} - - -/* X.691-2008/11, #11.5.6 -> #11.3 */ -int uper_get_constrained_whole_number(asn_per_data_t *pd, unsigned long *out_value, int nbits) { - unsigned long lhalf; /* Lower half of the number*/ - long half; - - if(nbits <= 31) { - half = per_get_few_bits(pd, nbits); - if(half < 0) return -1; - *out_value = half; - return 0; - } - - if((size_t)nbits > 8 * sizeof(*out_value)) - return -1; /* RANGE */ - - half = per_get_few_bits(pd, 31); - if(half < 0) return -1; - - if(uper_get_constrained_whole_number(pd, &lhalf, nbits - 31)) - return -1; - - *out_value = ((unsigned long)half << (nbits - 31)) | lhalf; - return 0; -} - - -/* X.691-2008/11, #11.5.6 -> #11.3 */ -int -uper_put_constrained_whole_number_u(asn_per_outp_t *po, unsigned long v, - int nbits) { - if(nbits <= 31) { - return per_put_few_bits(po, v, nbits); - } else { - /* Put higher portion first, followed by lower 31-bit */ - if(uper_put_constrained_whole_number_u(po, v >> 31, nbits - 31)) - return -1; - return per_put_few_bits(po, v, 31); - } -} - -/* - * X.691 (08/2015) #11.9 "General rules for encoding a length determinant" - * Put the length "n" (or part of it) into the stream. - */ -ssize_t -uper_put_length(asn_per_outp_t *po, size_t length, int *need_eom) { - int dummy = 0; - if(!need_eom) need_eom = &dummy; - - if(length <= 127) { /* #11.9.3.6 */ - *need_eom = 0; - return per_put_few_bits(po, length, 8) - ? -1 : (ssize_t)length; - } else if(length < 16384) { /* #10.9.3.7 */ - *need_eom = 0; - return per_put_few_bits(po, length|0x8000, 16) - ? -1 : (ssize_t)length; - } - - *need_eom = 0 == (length & 16383); - length >>= 14; - if(length > 4) { - *need_eom = 0; - length = 4; - } - - return per_put_few_bits(po, 0xC0 | length, 8) - ? -1 : (ssize_t)(length << 14); - -} - - -/* - * Put the normally small length "n" into the stream. - * This procedure used to encode length of extensions bit-maps - * for SET and SEQUENCE types. - */ -int -uper_put_nslength(asn_per_outp_t *po, size_t length) { - if(length <= 64) { - /* #11.9.3.4 */ - if(length == 0) return -1; - return per_put_few_bits(po, length - 1, 7) ? -1 : 0; - } else { - int need_eom = 0; - if(uper_put_length(po, length, &need_eom) != (ssize_t)length - || need_eom) { - /* This might happen in case of >16K extensions */ - return -1; - } - } - - return 0; -} - -static int -per__long_range(long lb, long ub, unsigned long *range_r) { - unsigned long bounds_range; - if((ub < 0) == (lb < 0)) { - bounds_range = ub - lb; - } else if(lb < 0) { - assert(ub >= 0); - bounds_range = 1 + ((unsigned long)ub + (unsigned long)-(lb + 1)); - } else { - assert(!"Unreachable"); - return -1; - } - *range_r = bounds_range; - return 0; -} - -int -per_long_range_rebase(long v, long lb, long ub, unsigned long *output) { - unsigned long range; - - assert(lb <= ub); - - if(v < lb || v > ub || per__long_range(lb, ub, &range) < 0) { - /* Range error. */ - return -1; - } - - /* - * Fundamentally what we're doing is returning (v-lb). - * However, this triggers undefined behavior when the word width - * of signed (v) is the same as the size of unsigned (*output). - * In practice, it triggers the UndefinedSanitizer. Therefore we shall - * compute the ranges accurately to avoid C's undefined behavior. - */ - if((v < 0) == (lb < 0)) { - *output = v-lb; - return 0; - } else if(v < 0) { - unsigned long rebased = 1 + (unsigned long)-(v+1) + (unsigned long)lb; - assert(rebased <= range); /* By construction */ - *output = rebased; - return 0; - } else if(lb < 0) { - unsigned long rebased = 1 + (unsigned long)-(lb+1) + (unsigned long)v; - assert(rebased <= range); /* By construction */ - *output = rebased; - return 0; - } else { - assert(!"Unreachable"); - return -1; - } -} - -int -per_long_range_unrebase(unsigned long inp, long lb, long ub, long *outp) { - unsigned long range; - - if(per__long_range(lb, ub, &range) != 0) { - return -1; - } - - if(inp > range) { - /* - * We can encode something in the given number of bits that technically - * exceeds the range. This is an avenue for security errors, - * so we don't allow that. - */ - return -1; - } - - if(inp <= LONG_MAX) { - *outp = (long)inp + lb; - } else { - *outp = (lb + LONG_MAX + 1) + (long)((inp - LONG_MAX) - 1); - } - - return 0; -} diff --git a/src/asn1/asn1c/per_support.h b/src/asn1/asn1c/per_support.h deleted file mode 100644 index 66807e75..00000000 --- a/src/asn1/asn1c/per_support.h +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright (c) 2005-2017 Lev Walkin . All rights reserved. - * Redistribution and modifications are permitted subject to BSD license. - */ -#ifndef _PER_SUPPORT_H_ -#define _PER_SUPPORT_H_ - -#include "asn1/asn1c/asn_system.h" /* Platform-specific types */ -#include "asn1/asn1c/asn_bit_data.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* - * Pre-computed PER constraints. - */ -typedef struct asn_per_constraint_s { - enum asn_per_constraint_flags { - APC_UNCONSTRAINED = 0x0, /* No PER visible constraints */ - APC_SEMI_CONSTRAINED = 0x1, /* Constrained at "lb" */ - APC_CONSTRAINED = 0x2, /* Fully constrained */ - APC_EXTENSIBLE = 0x4 /* May have extension */ - } flags; - int range_bits; /* Full number of bits in the range */ - int effective_bits; /* Effective bits */ - long lower_bound; /* "lb" value */ - long upper_bound; /* "ub" value */ -} asn_per_constraint_t; -typedef struct asn_per_constraints_s { - asn_per_constraint_t value; - asn_per_constraint_t size; - int (*value2code)(unsigned int value); - int (*code2value)(unsigned int code); -} asn_per_constraints_t; - -/* Temporary compatibility layer. Will get removed. */ -typedef struct asn_bit_data_s asn_per_data_t; -#define per_get_few_bits(data, bits) asn_get_few_bits(data, bits) -#define per_get_undo(data, bits) asn_get_undo(data, bits) -#define per_get_many_bits(data, dst, align, bits) \ - asn_get_many_bits(data, dst, align, bits) - -/* - * X.691 (08/2015) #11.9 "General rules for encoding a length determinant" - * Get the length "n" from the Unaligned PER stream. - */ -ssize_t uper_get_length(asn_per_data_t *pd, int effective_bound_bits, - size_t lower_bound, int *repeat); - -/* - * Get the normally small length "n". - */ -ssize_t uper_get_nslength(asn_per_data_t *pd); - -/* - * Get the normally small non-negative whole number. - */ -ssize_t uper_get_nsnnwn(asn_per_data_t *pd); - -/* X.691-2008/11, #11.5.6 */ -int uper_get_constrained_whole_number(asn_per_data_t *pd, unsigned long *v, int nbits); - - -/* Temporary compatibility layer. Will get removed. */ -typedef struct asn_bit_outp_s asn_per_outp_t; -#define per_put_few_bits(out, bits, obits) asn_put_few_bits(out, bits, obits) -#define per_put_many_bits(out, src, nbits) asn_put_many_bits(out, src, nbits) -#define per_put_aligned_flush(out) asn_put_aligned_flush(out) - - -/* - * Rebase the given value as an offset into the range specified by the - * lower bound (lb) and upper bound (ub). - * RETURN VALUES: - * -1: Conversion failed due to range problems. - * 0: Conversion was successful. - */ -int per_long_range_rebase(long v, long lb, long ub, unsigned long *output); -/* The inverse operation: restores the value by the offset and its bounds. */ -int per_long_range_unrebase(unsigned long inp, long lb, long ub, long *outp); - -/* X.691-2008/11, #11.5 */ -int uper_put_constrained_whole_number_u(asn_per_outp_t *po, unsigned long v, int nbits); - -/* - * X.691 (08/2015) #11.9 "General rules for encoding a length determinant" - * Put the length "whole_length" to the Unaligned PER stream. - * If (opt_need_eom) is given, it will be set to 1 if final 0-length is needed. - * In that case, invoke uper_put_length(po, 0, 0) after encoding the last block. - * This function returns the number of units which may be flushed - * in the next units saving iteration. - */ -ssize_t uper_put_length(asn_per_outp_t *po, size_t whole_length, - int *opt_need_eom); - -/* - * Put the normally small length "n" to the Unaligned PER stream. - * Returns 0 or -1. - */ -int uper_put_nslength(asn_per_outp_t *po, size_t length); - -/* - * Put the normally small non-negative whole number. - */ -int uper_put_nsnnwn(asn_per_outp_t *po, int n); - -#ifdef __cplusplus -} -#endif - -#endif /* _PER_SUPPORT_H_ */