|
|
|
@ -20,13 +20,70 @@
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "srslte/asn1/asn1_utils.h"
|
|
|
|
|
#include "srslte/common/logmap.h"
|
|
|
|
|
#include <cmath>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
|
|
using srslte::logmap;
|
|
|
|
|
|
|
|
|
|
namespace asn1 {
|
|
|
|
|
|
|
|
|
|
/************************
|
|
|
|
|
logging
|
|
|
|
|
************************/
|
|
|
|
|
|
|
|
|
|
void vlog_print(srslte::LOG_LEVEL_ENUM log_level, const char* format, va_list args)
|
|
|
|
|
{
|
|
|
|
|
char* args_msg = nullptr;
|
|
|
|
|
if (vasprintf(&args_msg, format, args) > 0) {
|
|
|
|
|
switch (log_level) {
|
|
|
|
|
case srslte::LOG_LEVEL_ERROR:
|
|
|
|
|
srslte::logmap::get("ASN1")->error("%s", args_msg);
|
|
|
|
|
break;
|
|
|
|
|
case srslte::LOG_LEVEL_WARNING:
|
|
|
|
|
srslte::logmap::get("ASN1")->warning("%s", args_msg);
|
|
|
|
|
break;
|
|
|
|
|
case srslte::LOG_LEVEL_INFO:
|
|
|
|
|
srslte::logmap::get("ASN1")->info("%s", args_msg);
|
|
|
|
|
break;
|
|
|
|
|
case srslte::LOG_LEVEL_DEBUG:
|
|
|
|
|
srslte::logmap::get("ASN1")->debug("%s", args_msg);
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (args_msg) {
|
|
|
|
|
free(args_msg);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void log_error(const char* format, ...)
|
|
|
|
|
{
|
|
|
|
|
va_list args;
|
|
|
|
|
va_start(args, format);
|
|
|
|
|
vlog_print(srslte::LOG_LEVEL_ERROR, format, args);
|
|
|
|
|
va_end(args);
|
|
|
|
|
}
|
|
|
|
|
void log_warning(const char* format, ...)
|
|
|
|
|
{
|
|
|
|
|
va_list args;
|
|
|
|
|
va_start(args, format);
|
|
|
|
|
vlog_print(srslte::LOG_LEVEL_WARNING, format, args);
|
|
|
|
|
va_end(args);
|
|
|
|
|
}
|
|
|
|
|
void log_info(const char* format, ...)
|
|
|
|
|
{
|
|
|
|
|
va_list args;
|
|
|
|
|
va_start(args, format);
|
|
|
|
|
vlog_print(srslte::LOG_LEVEL_INFO, format, args);
|
|
|
|
|
va_end(args);
|
|
|
|
|
}
|
|
|
|
|
void log_debug(const char* format, ...)
|
|
|
|
|
{
|
|
|
|
|
va_list args;
|
|
|
|
|
va_start(args, format);
|
|
|
|
|
vlog_print(srslte::LOG_LEVEL_DEBUG, format, args);
|
|
|
|
|
va_end(args);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/************************
|
|
|
|
|
error handling
|
|
|
|
|
************************/
|
|
|
|
@ -35,13 +92,13 @@ void log_error_code(SRSASN_CODE code, const char* filename, int line)
|
|
|
|
|
{
|
|
|
|
|
switch (code) {
|
|
|
|
|
case SRSASN_ERROR_ENCODE_FAIL:
|
|
|
|
|
logmap::get("ASN1")->error("[%s][%d] Encoding failure.\n", filename, line);
|
|
|
|
|
log_error("[%s][%d] Encoding failure.\n", filename, line);
|
|
|
|
|
break;
|
|
|
|
|
case SRSASN_ERROR_DECODE_FAIL:
|
|
|
|
|
logmap::get("ASN1")->error("[%s][%d] Decoding failure.\n", filename, line);
|
|
|
|
|
log_error("[%s][%d] Decoding failure.\n", filename, line);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
logmap::get("ASN1")->warning("[%s][%d] SRSASN_CODE=%d not recognized.\n", filename, line, (int)code);
|
|
|
|
|
log_warning("[%s][%d] SRSASN_CODE=%d not recognized.\n", filename, line, (int)code);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -78,13 +135,13 @@ int bit_ref_impl<Ptr>::distance_bytes() const
|
|
|
|
|
SRSASN_CODE bit_ref::pack(uint32_t val, uint32_t n_bits)
|
|
|
|
|
{
|
|
|
|
|
if (n_bits >= 32) {
|
|
|
|
|
logmap::get("ASN1")->error("This method only supports packing up to 32 bits\n");
|
|
|
|
|
log_error("This method only supports packing up to 32 bits\n");
|
|
|
|
|
return SRSASN_ERROR_ENCODE_FAIL;
|
|
|
|
|
}
|
|
|
|
|
uint32_t mask;
|
|
|
|
|
while (n_bits > 0) {
|
|
|
|
|
if (ptr >= max_ptr) {
|
|
|
|
|
logmap::get("ASN1")->error("Buffer size limit was achieved\n");
|
|
|
|
|
log_error("Buffer size limit was achieved\n");
|
|
|
|
|
return SRSASN_ERROR_ENCODE_FAIL;
|
|
|
|
|
}
|
|
|
|
|
mask = ((1u << n_bits) - 1u);
|
|
|
|
@ -110,13 +167,13 @@ template <typename T, typename Ptr>
|
|
|
|
|
SRSASN_CODE unpack_bits(T& val, Ptr& ptr, uint8_t& offset, const uint8_t* max_ptr, uint32_t n_bits)
|
|
|
|
|
{
|
|
|
|
|
if (n_bits > sizeof(T) * 8) {
|
|
|
|
|
logmap::get("ASN1")->error("This method only supports unpacking up to %d bits\n", (int)sizeof(T) * 8);
|
|
|
|
|
log_error("This method only supports unpacking up to %d bits\n", (int)sizeof(T) * 8);
|
|
|
|
|
return SRSASN_ERROR_DECODE_FAIL;
|
|
|
|
|
}
|
|
|
|
|
val = 0;
|
|
|
|
|
while (n_bits > 0) {
|
|
|
|
|
if (ptr >= max_ptr) {
|
|
|
|
|
logmap::get("ASN1")->error("Buffer size limit was achieved\n");
|
|
|
|
|
log_error("Buffer size limit was achieved\n");
|
|
|
|
|
return SRSASN_ERROR_DECODE_FAIL;
|
|
|
|
|
}
|
|
|
|
|
if ((uint32_t)(8 - offset) > n_bits) {
|
|
|
|
@ -178,7 +235,7 @@ SRSASN_CODE bit_ref_impl<Ptr>::unpack_bytes(uint8_t* buf, uint32_t n_bytes)
|
|
|
|
|
return SRSASN_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
if (ptr + n_bytes >= max_ptr) {
|
|
|
|
|
logmap::get("ASN1")->error("Buffer size limit was achieved\n");
|
|
|
|
|
log_error("Buffer size limit was achieved\n");
|
|
|
|
|
return SRSASN_ERROR_DECODE_FAIL;
|
|
|
|
|
}
|
|
|
|
|
if (offset == 0) {
|
|
|
|
@ -199,7 +256,7 @@ SRSASN_CODE bit_ref_impl<Ptr>::align_bytes()
|
|
|
|
|
if (offset == 0)
|
|
|
|
|
return SRSASN_SUCCESS;
|
|
|
|
|
if (ptr >= max_ptr) {
|
|
|
|
|
logmap::get("ASN1")->error("Buffer size limit was achieved\n");
|
|
|
|
|
log_error("Buffer size limit was achieved\n");
|
|
|
|
|
return SRSASN_ERROR_DECODE_FAIL;
|
|
|
|
|
}
|
|
|
|
|
offset = 0;
|
|
|
|
@ -215,7 +272,7 @@ SRSASN_CODE bit_ref_impl<Ptr>::advance_bits(uint32_t n_bits)
|
|
|
|
|
uint32_t bytes_offset = floorf((offset + n_bits) / 8.0f);
|
|
|
|
|
|
|
|
|
|
if (ptr + bytes_required >= max_ptr) {
|
|
|
|
|
logmap::get("ASN1")->error("Buffer size limit was achieved\n");
|
|
|
|
|
log_error("Buffer size limit was achieved\n");
|
|
|
|
|
return SRSASN_ERROR_DECODE_FAIL;
|
|
|
|
|
}
|
|
|
|
|
ptr += bytes_offset;
|
|
|
|
@ -241,7 +298,7 @@ SRSASN_CODE bit_ref::pack_bytes(const uint8_t* buf, uint32_t n_bytes)
|
|
|
|
|
return SRSASN_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
if (ptr + n_bytes >= max_ptr) {
|
|
|
|
|
logmap::get("ASN1")->error("Buffer size limit was achieved\n");
|
|
|
|
|
log_error("Buffer size limit was achieved\n");
|
|
|
|
|
return SRSASN_ERROR_ENCODE_FAIL;
|
|
|
|
|
}
|
|
|
|
|
if (offset == 0) {
|
|
|
|
@ -261,7 +318,7 @@ SRSASN_CODE bit_ref::align_bytes_zero()
|
|
|
|
|
if (offset == 0)
|
|
|
|
|
return SRSASN_SUCCESS;
|
|
|
|
|
if (ptr >= max_ptr) {
|
|
|
|
|
logmap::get("ASN1")->error("Buffer size limit was achieved\n");
|
|
|
|
|
log_error("Buffer size limit was achieved\n");
|
|
|
|
|
return SRSASN_ERROR_ENCODE_FAIL;
|
|
|
|
|
}
|
|
|
|
|
uint8_t mask = (uint8_t)(256u - (1u << (8u - offset)));
|
|
|
|
@ -279,7 +336,7 @@ SRSASN_CODE pack_unsupported_ext_flag(bit_ref& bref, bool ext)
|
|
|
|
|
{
|
|
|
|
|
HANDLE_CODE(bref.pack(ext, 1));
|
|
|
|
|
if (ext) {
|
|
|
|
|
logmap::get("ASN1")->error("asn1 error: ASN extensions not currently supported\n");
|
|
|
|
|
log_error("asn1 error: ASN extensions not currently supported\n");
|
|
|
|
|
return SRSASN_ERROR_ENCODE_FAIL;
|
|
|
|
|
}
|
|
|
|
|
return SRSASN_SUCCESS;
|
|
|
|
@ -289,7 +346,7 @@ SRSASN_CODE unpack_unsupported_ext_flag(bool& ext, bit_ref& bref)
|
|
|
|
|
{
|
|
|
|
|
SRSASN_CODE ret = bref.unpack(ext, 1);
|
|
|
|
|
if (ext) {
|
|
|
|
|
logmap::get("ASN1")->error("asn1 error: ASN extensions not currently supported\n");
|
|
|
|
|
log_error("asn1 error: ASN extensions not currently supported\n");
|
|
|
|
|
return SRSASN_ERROR_DECODE_FAIL;
|
|
|
|
|
}
|
|
|
|
|
return ret;
|
|
|
|
@ -322,7 +379,7 @@ SRSASN_CODE pack_enum(bit_ref& bref, uint32_t enum_val, uint32_t nbits, uint32_t
|
|
|
|
|
SRSASN_CODE pack_enum(bit_ref& bref, uint32_t e, uint32_t nof_types, uint32_t nof_exts, bool has_ext)
|
|
|
|
|
{
|
|
|
|
|
if (e >= nof_types) {
|
|
|
|
|
logmap::get("ASN1")->error(
|
|
|
|
|
log_error(
|
|
|
|
|
"The provided enum is not within the range of possible values (%u>=%u)\n", (unsigned)e, (unsigned)nof_types);
|
|
|
|
|
return SRSASN_ERROR_ENCODE_FAIL;
|
|
|
|
|
}
|
|
|
|
@ -358,7 +415,7 @@ ValOrError unpack_enum(uint32_t nof_types, uint32_t nof_exts, bool has_ext, cbit
|
|
|
|
|
ret.code = bref.unpack(ret.val, nof_bits);
|
|
|
|
|
}
|
|
|
|
|
if (ret.val >= nof_types) {
|
|
|
|
|
logmap::get("ASN1")->error("The provided enum is not within the range of possible values (%u>=%u)\n",
|
|
|
|
|
log_error("The provided enum is not within the range of possible values (%u>=%u)\n",
|
|
|
|
|
(unsigned)ret.val,
|
|
|
|
|
(unsigned)nof_types);
|
|
|
|
|
ret.code = SRSASN_ERROR_DECODE_FAIL;
|
|
|
|
@ -384,8 +441,7 @@ template <class IntType>
|
|
|
|
|
SRSASN_CODE pack_constrained_whole_number(bit_ref& bref, IntType n, IntType lb, IntType ub, bool aligned)
|
|
|
|
|
{
|
|
|
|
|
if (ub < lb or n < lb or n > ub) {
|
|
|
|
|
logmap::get("ASN1")->error(
|
|
|
|
|
"The condition lb <= n <= ub (%ld <= %ld <= %ld) was not met\n", (long)lb, (long)n, (long)ub);
|
|
|
|
|
log_error("The condition lb <= n <= ub (%ld <= %ld <= %ld) was not met\n", (long)lb, (long)n, (long)ub);
|
|
|
|
|
return SRSASN_ERROR_ENCODE_FAIL;
|
|
|
|
|
}
|
|
|
|
|
uint64_t ra = (uint64_t)(ub - lb) + 1; // NOTE: Can overflow if IntType is kept
|
|
|
|
@ -453,7 +509,7 @@ template <class IntType>
|
|
|
|
|
SRSASN_CODE unpack_constrained_whole_number(IntType& n, cbit_ref& bref, IntType lb, IntType ub, bool aligned)
|
|
|
|
|
{
|
|
|
|
|
if (ub < lb) {
|
|
|
|
|
logmap::get("ASN1")->error("The condition lb <= ub (%ld <= %ld) was not met\n", (long)lb, (long)ub);
|
|
|
|
|
log_error("The condition lb <= ub (%ld <= %ld) was not met\n", (long)lb, (long)ub);
|
|
|
|
|
return SRSASN_ERROR_DECODE_FAIL;
|
|
|
|
|
}
|
|
|
|
|
uint64_t ra = (uint64_t)(ub - lb) + 1; // NOTE: Can overflow if IntType is kept.
|
|
|
|
@ -467,8 +523,7 @@ SRSASN_CODE unpack_constrained_whole_number(IntType& n, cbit_ref& bref, IntType
|
|
|
|
|
HANDLE_CODE(bref.unpack(n, n_bits));
|
|
|
|
|
n += lb;
|
|
|
|
|
if (n > ub) {
|
|
|
|
|
logmap::get("ASN1")->error(
|
|
|
|
|
"The condition lb <= n <= ub (%ld <= %ld <= %ld) was not met\n", (long)lb, (long)n, (long)ub);
|
|
|
|
|
log_error("The condition lb <= n <= ub (%ld <= %ld <= %ld) was not met\n", (long)lb, (long)n, (long)ub);
|
|
|
|
|
return SRSASN_ERROR_DECODE_FAIL;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
@ -525,7 +580,7 @@ SRSASN_CODE pack_norm_small_non_neg_whole_number(bit_ref& bref, UintType n)
|
|
|
|
|
HANDLE_CODE(bref.pack(n, 7)); // [1 bit: 0 | 6 bit: n]
|
|
|
|
|
} else {
|
|
|
|
|
HANDLE_CODE(bref.pack(1, 1));
|
|
|
|
|
logmap::get("ASN1")->error("Long small integers not supported\n");
|
|
|
|
|
log_error("Long small integers not supported\n");
|
|
|
|
|
return SRSASN_ERROR_ENCODE_FAIL;
|
|
|
|
|
}
|
|
|
|
|
return SRSASN_SUCCESS;
|
|
|
|
@ -539,7 +594,7 @@ SRSASN_CODE unpack_norm_small_non_neg_whole_number(UintType& n, cbit_ref& bref)
|
|
|
|
|
if (not ext) {
|
|
|
|
|
ret = bref.unpack(n, 6);
|
|
|
|
|
} else {
|
|
|
|
|
logmap::get("ASN1")->error("Long small integers not supported\n");
|
|
|
|
|
log_error("Long small integers not supported\n");
|
|
|
|
|
return SRSASN_ERROR_DECODE_FAIL;
|
|
|
|
|
}
|
|
|
|
|
return ret;
|
|
|
|
@ -658,7 +713,7 @@ SRSASN_CODE pack_length(bit_ref& bref, uint32_t val, bool aligned)
|
|
|
|
|
HANDLE_CODE(bref.pack(0b10, 2));
|
|
|
|
|
HANDLE_CODE(bref.pack(val, 14));
|
|
|
|
|
} else {
|
|
|
|
|
logmap::get("ASN1")->error("Not handling sizes longer than 16383 octets\n");
|
|
|
|
|
log_error("Not handling sizes longer than 16383 octets\n");
|
|
|
|
|
return SRSASN_ERROR_ENCODE_FAIL;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
@ -697,7 +752,7 @@ SRSASN_CODE unpack_length(uint32_t& val, cbit_ref& bref, bool aligned)
|
|
|
|
|
if (not ext) {
|
|
|
|
|
ret = bref.unpack(val, 14);
|
|
|
|
|
} else {
|
|
|
|
|
logmap::get("ASN1")->error("Not handling octet strings longer than 16383 octets\n");
|
|
|
|
|
log_error("Not handling octet strings longer than 16383 octets\n");
|
|
|
|
|
val = 0;
|
|
|
|
|
return SRSASN_ERROR_DECODE_FAIL;
|
|
|
|
|
}
|
|
|
|
@ -737,8 +792,7 @@ SRSASN_CODE pack_integer(bit_ref& bref, IntType n, IntType lb, IntType ub, bool
|
|
|
|
|
if (has_ext) {
|
|
|
|
|
HANDLE_CODE(bref.pack(not within_bounds, 1));
|
|
|
|
|
} else if (not within_bounds) {
|
|
|
|
|
logmap::get("ASN1")->error(
|
|
|
|
|
"The condition lb <= n <= ub (%ld <= %ld <= %ld) was not met\n", (long)lb, (long)n, (long)ub);
|
|
|
|
|
log_error("The condition lb <= n <= ub (%ld <= %ld <= %ld) was not met\n", (long)lb, (long)n, (long)ub);
|
|
|
|
|
return SRSASN_ERROR_ENCODE_FAIL;
|
|
|
|
|
}
|
|
|
|
|
bool lower_bounded = lb != std::numeric_limits<IntType>::min() or lb == 0;
|
|
|
|
@ -888,7 +942,7 @@ template struct integer_packer<uint64_t>;
|
|
|
|
|
uint64_t octstring_to_number(const uint8_t* ptr, uint32_t nbytes)
|
|
|
|
|
{
|
|
|
|
|
if (nbytes > 8) {
|
|
|
|
|
logmap::get("ASN1")->error("octstring of size=%d does not fit in an uint64_t\n", nbytes);
|
|
|
|
|
log_error("octstring of size=%d does not fit in an uint64_t\n", nbytes);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
uint64_t val = 0;
|
|
|
|
@ -901,7 +955,7 @@ uint64_t octstring_to_number(const uint8_t* ptr, uint32_t nbytes)
|
|
|
|
|
void number_to_octstring(uint8_t* ptr, uint64_t number, uint32_t nbytes)
|
|
|
|
|
{
|
|
|
|
|
if (nbytes > 8) {
|
|
|
|
|
logmap::get("ASN1")->error("octstring of size=%d does not fit in an uint64_t\n", nbytes);
|
|
|
|
|
log_error("octstring of size=%d does not fit in an uint64_t\n", nbytes);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
for (uint32_t i = 0; i < nbytes; ++i) {
|
|
|
|
@ -930,7 +984,7 @@ std::string octstring_to_string(const uint8_t* ptr, uint32_t N)
|
|
|
|
|
void string_to_octstring(uint8_t* ptr, const std::string& str)
|
|
|
|
|
{
|
|
|
|
|
if (str.size() % 2 != 0) {
|
|
|
|
|
logmap::get("ASN1")->warning("The provided hex string size=%zd is not a multiple of 2\n.", str.size());
|
|
|
|
|
log_warning("The provided hex string size=%zd is not a multiple of 2\n.", str.size());
|
|
|
|
|
}
|
|
|
|
|
char cstr[] = "\0\0\0";
|
|
|
|
|
for (uint32_t i = 0; i < str.size(); i += 2) {
|
|
|
|
@ -999,12 +1053,12 @@ SRSASN_CODE pack_length_prefix(bit_ref& bref,
|
|
|
|
|
bool is_aligned = false)
|
|
|
|
|
{
|
|
|
|
|
if (has_ext and ub == std::numeric_limits<uint32_t>::max()) {
|
|
|
|
|
logmap::get("ASN1")->error("has extension marker but it is an unbounded prefix size\n");
|
|
|
|
|
log_error("has extension marker but it is an unbounded prefix size\n");
|
|
|
|
|
return SRSASN_ERROR_ENCODE_FAIL;
|
|
|
|
|
}
|
|
|
|
|
bool within_bounds = len >= lb and len <= ub;
|
|
|
|
|
if (not within_bounds and not has_ext) {
|
|
|
|
|
logmap::get("ASN1")->error("bitstring length=%d is not within bounds [%d, %d]\n", len, lb, ub);
|
|
|
|
|
log_error("bitstring length=%d is not within bounds [%d, %d]\n", len, lb, ub);
|
|
|
|
|
return SRSASN_ERROR_ENCODE_FAIL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -1035,7 +1089,7 @@ SRSASN_CODE pack_length_prefix(bit_ref& bref,
|
|
|
|
|
SRSASN_CODE pack_bitfield(bit_ref& bref, const uint8_t* buf, uint32_t nbits, uint32_t lb, uint32_t ub, bool is_aligned)
|
|
|
|
|
{
|
|
|
|
|
if (nbits == 0) {
|
|
|
|
|
logmap::get("ASN1")->error("Invalid bitstring size=%d\n", nbits);
|
|
|
|
|
log_error("Invalid bitstring size=%d\n", nbits);
|
|
|
|
|
return SRSASN_ERROR_ENCODE_FAIL;
|
|
|
|
|
}
|
|
|
|
|
if (is_aligned and (lb != ub or ub > 16)) {
|
|
|
|
@ -1098,7 +1152,7 @@ SRSASN_CODE unpack_length_prefix(uint32_t& len, cbit_ref& bref, uint32_t lb, uin
|
|
|
|
|
SRSASN_CODE unpack_bitfield(uint8_t* buf, cbit_ref& bref, uint32_t n, uint32_t lb, uint32_t ub, bool is_aligned)
|
|
|
|
|
{
|
|
|
|
|
if (n > ASN_64K) {
|
|
|
|
|
logmap::get("ASN1")->error("bitstrings longer than 64K not supported\n");
|
|
|
|
|
log_error("bitstrings longer than 64K not supported\n");
|
|
|
|
|
return SRSASN_ERROR_DECODE_FAIL;
|
|
|
|
|
}
|
|
|
|
|
if (n == 0) {
|
|
|
|
@ -1121,7 +1175,7 @@ SRSASN_CODE unpack_bitfield(uint8_t* buf, cbit_ref& bref, uint32_t n, uint32_t l
|
|
|
|
|
void from_number(uint8_t* ptr, uint64_t number, uint32_t nbits)
|
|
|
|
|
{
|
|
|
|
|
if (nbits > 64) {
|
|
|
|
|
logmap::get("ASN1")->error("bitstring of size=%d does not fit in an uint64_t\n", nbits);
|
|
|
|
|
log_error("bitstring of size=%d does not fit in an uint64_t\n", nbits);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
uint32_t nof_bytes = (uint32_t)ceilf(nbits / 8.0f);
|
|
|
|
@ -1146,7 +1200,7 @@ std::string to_string(const uint8_t* ptr, uint32_t nbits)
|
|
|
|
|
uint64_t to_number(const uint8_t* ptr, uint32_t nbits)
|
|
|
|
|
{
|
|
|
|
|
if (nbits > 64) {
|
|
|
|
|
logmap::get("ASN1")->error("bitstring of size=%d does not fit in an uint64_t\n", nbits);
|
|
|
|
|
log_error("bitstring of size=%d does not fit in an uint64_t\n", nbits);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
uint64_t val = 0;
|
|
|
|
@ -1164,11 +1218,11 @@ uint64_t to_number(const uint8_t* ptr, uint32_t nbits)
|
|
|
|
|
*********************/
|
|
|
|
|
void log_invalid_access_choice_id(uint32_t val, uint32_t choice_id)
|
|
|
|
|
{
|
|
|
|
|
logmap::get("ASN1")->error("The access choide id is invalid (%zd!=%zd)\n", (size_t)val, (size_t)choice_id);
|
|
|
|
|
log_error("The access choide id is invalid (%zd!=%zd)\n", (size_t)val, (size_t)choice_id);
|
|
|
|
|
}
|
|
|
|
|
void log_invalid_choice_id(uint32_t val, const char* choice_type)
|
|
|
|
|
{
|
|
|
|
|
logmap::get("ASN1")->error("Invalid choice id=%zd for choice type %s\n", (size_t)val, choice_type);
|
|
|
|
|
log_error("Invalid choice id=%zd for choice type %s\n", (size_t)val, choice_type);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*********************
|
|
|
|
@ -1205,8 +1259,7 @@ pack(bit_ref& bref, const std::string& s, size_t lb, size_t ub, size_t alb, size
|
|
|
|
|
if (not within_limits) {
|
|
|
|
|
// TODO: print error
|
|
|
|
|
// NOTE: This should be valid for exts
|
|
|
|
|
logmap::get("ASN1")->error(
|
|
|
|
|
"The PrintableString size=%zd is not within the limits [%zd, %zd]\n", s.size(), alb, aub);
|
|
|
|
|
log_error("The PrintableString size=%zd is not within the limits [%zd, %zd]\n", s.size(), alb, aub);
|
|
|
|
|
return SRSASN_ERROR_ENCODE_FAIL;
|
|
|
|
|
}
|
|
|
|
|
size_t b = asn_string_utils::get_nof_bits_per_char(lb, ub, aligned);
|
|
|
|
@ -1243,7 +1296,7 @@ SRSASN_CODE unpack(std::string& s, cbit_ref& bref, size_t lb, size_t ub, size_t
|
|
|
|
|
bool is_ext;
|
|
|
|
|
HANDLE_CODE(bref.unpack(is_ext, 1));
|
|
|
|
|
if (is_ext) {
|
|
|
|
|
logmap::get("ASN1")->error("Extension of PrintableString not supported\n");
|
|
|
|
|
log_error("Extension of PrintableString not supported\n");
|
|
|
|
|
return SRSASN_ERROR_DECODE_FAIL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -1366,7 +1419,7 @@ varlength_field_pack_guard::~varlength_field_pack_guard()
|
|
|
|
|
// check how many bytes were written in total
|
|
|
|
|
uint32_t nof_bytes = bref_tracker->distance(bref0) / (uint32_t)8;
|
|
|
|
|
if (nof_bytes > sizeof(buffer)) {
|
|
|
|
|
logmap::get("ASN1")->error("The packed variable sized field is too long for the reserved buffer (%zd > %zd)\n",
|
|
|
|
|
log_error("The packed variable sized field is too long for the reserved buffer (%zd > %zd)\n",
|
|
|
|
|
(size_t)nof_bytes,
|
|
|
|
|
sizeof(buffer));
|
|
|
|
|
}
|
|
|
|
|