|
|
@ -102,23 +102,28 @@ void log_error_code(SRSASN_CODE code, const char* filename, int line)
|
|
|
|
bit_ref
|
|
|
|
bit_ref
|
|
|
|
*********************/
|
|
|
|
*********************/
|
|
|
|
|
|
|
|
|
|
|
|
int bit_ref::distance(const bit_ref& other) const
|
|
|
|
template <typename Ptr>
|
|
|
|
|
|
|
|
int bit_ref_impl<Ptr>::distance(const bit_ref_impl<Ptr>& other) const
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return ((int)offset - (int)other.offset) + 8 * ((int)(ptr - other.ptr));
|
|
|
|
return ((int)offset - (int)other.offset) + 8 * ((int)(ptr - other.ptr));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int bit_ref::distance(uint8_t* ref_ptr) const
|
|
|
|
template <typename Ptr>
|
|
|
|
|
|
|
|
int bit_ref_impl<Ptr>::distance(const uint8_t* ref_ptr) const
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return (int)offset + 8 * ((int)(ptr - ref_ptr));
|
|
|
|
return (int)offset + 8 * ((int)(ptr - ref_ptr));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int bit_ref::distance() const
|
|
|
|
template <typename Ptr>
|
|
|
|
|
|
|
|
int bit_ref_impl<Ptr>::distance() const
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return (int)offset + 8 * ((int)(ptr - start_ptr));
|
|
|
|
return (int)offset + 8 * ((int)(ptr - start_ptr));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int bit_ref::distance_bytes(uint8_t* ref_ptr) const
|
|
|
|
template <typename Ptr>
|
|
|
|
|
|
|
|
int bit_ref_impl<Ptr>::distance_bytes(uint8_t* ref_ptr) const
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return ((int)(ptr - ref_ptr)) + ((offset) ? 1 : 0);
|
|
|
|
return ((int)(ptr - ref_ptr)) + ((offset) ? 1 : 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int bit_ref::distance_bytes() const
|
|
|
|
template <typename Ptr>
|
|
|
|
|
|
|
|
int bit_ref_impl<Ptr>::distance_bytes() const
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return ((int)(ptr - start_ptr)) + ((offset) ? 1 : 0);
|
|
|
|
return ((int)(ptr - start_ptr)) + ((offset) ? 1 : 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -137,7 +142,7 @@ SRSASN_CODE bit_ref::pack(uint32_t val, uint32_t n_bits)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mask = ((1u << n_bits) - 1u);
|
|
|
|
mask = ((1u << n_bits) - 1u);
|
|
|
|
val = val & mask;
|
|
|
|
val = val & mask;
|
|
|
|
uint8_t keepmask = ((uint8_t)-1) - (uint8_t)((1 << (8 - offset)) - 1);
|
|
|
|
uint8_t keepmask = ((uint8_t)-1) - (uint8_t)((1u << (8u - offset)) - 1u);
|
|
|
|
if ((uint32_t)(8 - offset) > n_bits) {
|
|
|
|
if ((uint32_t)(8 - offset) > n_bits) {
|
|
|
|
uint8_t bit = (uint8_t)(val << (8u - offset - n_bits));
|
|
|
|
uint8_t bit = (uint8_t)(val << (8u - offset - n_bits));
|
|
|
|
*ptr = ((*ptr) & keepmask) + bit;
|
|
|
|
*ptr = ((*ptr) & keepmask) + bit;
|
|
|
@ -154,56 +159,73 @@ SRSASN_CODE bit_ref::pack(uint32_t val, uint32_t n_bits)
|
|
|
|
return SRSASN_SUCCESS;
|
|
|
|
return SRSASN_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SRSASN_CODE bit_ref::pack_bytes(const uint8_t* buf, uint32_t n_bytes)
|
|
|
|
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_bytes == 0) {
|
|
|
|
|
|
|
|
return SRSASN_SUCCESS;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ptr + n_bytes >= max_ptr) {
|
|
|
|
|
|
|
|
srsasn_log_print(LOG_LEVEL_ERROR, "Buffer size limit was achieved\n");
|
|
|
|
|
|
|
|
return SRSASN_ERROR_ENCODE_FAIL;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (offset == 0) {
|
|
|
|
|
|
|
|
// Aligned case
|
|
|
|
|
|
|
|
memcpy(ptr, buf, n_bytes);
|
|
|
|
|
|
|
|
ptr += n_bytes;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < n_bytes; ++i) {
|
|
|
|
|
|
|
|
pack(buf[i], 8);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return SRSASN_SUCCESS;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ValOrError unpack_bits(uint8_t*& ptr, uint8_t& offset, uint8_t* max_ptr, uint32_t n_bits)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (n_bits > 32) {
|
|
|
|
if (n_bits > sizeof(T) * 8) {
|
|
|
|
srsasn_log_print(LOG_LEVEL_ERROR, "This method only supports unpacking up to 32 bits\n");
|
|
|
|
srsasn_log_print(LOG_LEVEL_ERROR, "This method only supports unpacking up to %d bits\n", (int)sizeof(T) * 8);
|
|
|
|
return {0, SRSASN_ERROR_DECODE_FAIL};
|
|
|
|
return SRSASN_ERROR_DECODE_FAIL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
uint32_t val = 0;
|
|
|
|
val = 0;
|
|
|
|
while (n_bits > 0) {
|
|
|
|
while (n_bits > 0) {
|
|
|
|
if (ptr >= max_ptr) {
|
|
|
|
if (ptr >= max_ptr) {
|
|
|
|
srsasn_log_print(LOG_LEVEL_ERROR, "Buffer size limit was achieved\n");
|
|
|
|
srsasn_log_print(LOG_LEVEL_ERROR, "Buffer size limit was achieved\n");
|
|
|
|
return ValOrError(val, SRSASN_ERROR_DECODE_FAIL);
|
|
|
|
return SRSASN_ERROR_DECODE_FAIL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((uint32_t)(8 - offset) > n_bits) {
|
|
|
|
if ((uint32_t)(8 - offset) > n_bits) {
|
|
|
|
uint8_t mask = (uint8_t)(1u << (8u - offset)) - (uint8_t)(1u << (8u - offset - n_bits));
|
|
|
|
uint8_t mask = (uint8_t)(1u << (8u - offset)) - (uint8_t)(1u << (8u - offset - n_bits));
|
|
|
|
val += ((uint32_t)((*ptr) & mask)) >> ((uint8_t)8 - offset - n_bits);
|
|
|
|
val += ((uint32_t)((*ptr) & mask)) >> (8u - offset - n_bits);
|
|
|
|
offset += n_bits;
|
|
|
|
offset += n_bits;
|
|
|
|
n_bits = 0;
|
|
|
|
n_bits = 0;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
uint8_t mask = (uint8_t)((1u << (8u - offset)) - 1);
|
|
|
|
uint8_t mask = (uint8_t)((1u << (8u - offset)) - 1u);
|
|
|
|
val += ((uint32_t)((*ptr) & mask)) << (n_bits - 8 + offset);
|
|
|
|
val += ((uint32_t)((*ptr) & mask)) << (n_bits - 8 + offset);
|
|
|
|
n_bits -= 8 - offset;
|
|
|
|
n_bits -= 8 - offset;
|
|
|
|
offset = 0;
|
|
|
|
offset = 0;
|
|
|
|
ptr++;
|
|
|
|
ptr++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ValOrError(val, SRSASN_SUCCESS);
|
|
|
|
return SRSASN_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SRSASN_CODE bit_ref::unpack_bytes(uint8_t* buf, uint32_t n_bytes)
|
|
|
|
template SRSASN_CODE
|
|
|
|
|
|
|
|
unpack_bits<bool, uint8_t*>(bool& val, uint8_t*& ptr, uint8_t& offset, const uint8_t* max_ptr, uint32_t n_bits);
|
|
|
|
|
|
|
|
template SRSASN_CODE unpack_bits<bool, const uint8_t*>(bool& val,
|
|
|
|
|
|
|
|
const uint8_t*& ptr,
|
|
|
|
|
|
|
|
uint8_t& offset,
|
|
|
|
|
|
|
|
const uint8_t* max_ptr,
|
|
|
|
|
|
|
|
uint32_t n_bits);
|
|
|
|
|
|
|
|
template SRSASN_CODE
|
|
|
|
|
|
|
|
unpack_bits<uint8_t, uint8_t*>(uint8_t& val, uint8_t*& ptr, uint8_t& offset, const uint8_t* max_ptr, uint32_t n_bits);
|
|
|
|
|
|
|
|
template SRSASN_CODE unpack_bits<uint8_t, const uint8_t*>(uint8_t& val,
|
|
|
|
|
|
|
|
const uint8_t*& ptr,
|
|
|
|
|
|
|
|
uint8_t& offset,
|
|
|
|
|
|
|
|
const uint8_t* max_ptr,
|
|
|
|
|
|
|
|
uint32_t n_bits);
|
|
|
|
|
|
|
|
template SRSASN_CODE
|
|
|
|
|
|
|
|
unpack_bits<uint16_t, uint8_t*>(uint16_t& val, uint8_t*& ptr, uint8_t& offset, const uint8_t* max_ptr, uint32_t n_bits);
|
|
|
|
|
|
|
|
template SRSASN_CODE unpack_bits<uint16_t, const uint8_t*>(uint16_t& val,
|
|
|
|
|
|
|
|
const uint8_t*& ptr,
|
|
|
|
|
|
|
|
uint8_t& offset,
|
|
|
|
|
|
|
|
const uint8_t* max_ptr,
|
|
|
|
|
|
|
|
uint32_t n_bits);
|
|
|
|
|
|
|
|
template SRSASN_CODE
|
|
|
|
|
|
|
|
unpack_bits<uint32_t, uint8_t*>(uint32_t& val, uint8_t*& ptr, uint8_t& offset, const uint8_t* max_ptr, uint32_t n_bits);
|
|
|
|
|
|
|
|
template SRSASN_CODE unpack_bits<uint32_t, const uint8_t*>(uint32_t& val,
|
|
|
|
|
|
|
|
const uint8_t*& ptr,
|
|
|
|
|
|
|
|
uint8_t& offset,
|
|
|
|
|
|
|
|
const uint8_t* max_ptr,
|
|
|
|
|
|
|
|
uint32_t n_bits);
|
|
|
|
|
|
|
|
template SRSASN_CODE
|
|
|
|
|
|
|
|
unpack_bits<uint64_t, uint8_t*>(uint64_t& val, uint8_t*& ptr, uint8_t& offset, const uint8_t* max_ptr, uint32_t n_bits);
|
|
|
|
|
|
|
|
template SRSASN_CODE unpack_bits<uint64_t, const uint8_t*>(uint64_t& val,
|
|
|
|
|
|
|
|
const uint8_t*& ptr,
|
|
|
|
|
|
|
|
uint8_t& offset,
|
|
|
|
|
|
|
|
const uint8_t* max_ptr,
|
|
|
|
|
|
|
|
uint32_t n_bits);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template <typename Ptr>
|
|
|
|
|
|
|
|
SRSASN_CODE bit_ref_impl<Ptr>::unpack_bytes(uint8_t* buf, uint32_t n_bytes)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (n_bytes == 0) {
|
|
|
|
if (n_bytes == 0) {
|
|
|
|
return SRSASN_SUCCESS;
|
|
|
|
return SRSASN_SUCCESS;
|
|
|
@ -224,7 +246,8 @@ SRSASN_CODE bit_ref::unpack_bytes(uint8_t* buf, uint32_t n_bytes)
|
|
|
|
return SRSASN_SUCCESS;
|
|
|
|
return SRSASN_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SRSASN_CODE bit_ref::align_bytes()
|
|
|
|
template <typename Ptr>
|
|
|
|
|
|
|
|
SRSASN_CODE bit_ref_impl<Ptr>::align_bytes()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (offset == 0)
|
|
|
|
if (offset == 0)
|
|
|
|
return SRSASN_SUCCESS;
|
|
|
|
return SRSASN_SUCCESS;
|
|
|
@ -237,22 +260,8 @@ SRSASN_CODE bit_ref::align_bytes()
|
|
|
|
return SRSASN_SUCCESS;
|
|
|
|
return SRSASN_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SRSASN_CODE bit_ref::align_bytes_zero()
|
|
|
|
template <typename Ptr>
|
|
|
|
{
|
|
|
|
SRSASN_CODE bit_ref_impl<Ptr>::advance_bits(uint32_t n_bits)
|
|
|
|
if (offset == 0)
|
|
|
|
|
|
|
|
return SRSASN_SUCCESS;
|
|
|
|
|
|
|
|
if (ptr >= max_ptr) {
|
|
|
|
|
|
|
|
srsasn_log_print(LOG_LEVEL_ERROR, "Buffer size limit was achieved\n");
|
|
|
|
|
|
|
|
return SRSASN_ERROR_ENCODE_FAIL;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t mask = (uint8_t)(256u - (1u << (8u - offset)));
|
|
|
|
|
|
|
|
*ptr &= mask;
|
|
|
|
|
|
|
|
offset = 0;
|
|
|
|
|
|
|
|
ptr++;
|
|
|
|
|
|
|
|
return SRSASN_SUCCESS;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SRSASN_CODE bit_ref::advance_bits(uint32_t n_bits)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
uint32_t extra_bits = (offset + n_bits) % 8;
|
|
|
|
uint32_t extra_bits = (offset + n_bits) % 8;
|
|
|
|
uint32_t bytes_required = ceilf((offset + n_bits) / 8.0f);
|
|
|
|
uint32_t bytes_required = ceilf((offset + n_bits) / 8.0f);
|
|
|
@ -267,7 +276,8 @@ SRSASN_CODE bit_ref::advance_bits(uint32_t n_bits)
|
|
|
|
return SRSASN_SUCCESS;
|
|
|
|
return SRSASN_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void bit_ref::set(uint8_t* start_ptr_, uint32_t max_size_)
|
|
|
|
template <typename Ptr>
|
|
|
|
|
|
|
|
void bit_ref_impl<Ptr>::set(Ptr start_ptr_, uint32_t max_size_)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ptr = start_ptr_;
|
|
|
|
ptr = start_ptr_;
|
|
|
|
offset = 0;
|
|
|
|
offset = 0;
|
|
|
@ -275,6 +285,45 @@ void bit_ref::set(uint8_t* start_ptr_, uint32_t max_size_)
|
|
|
|
max_ptr = max_size_ + start_ptr_;
|
|
|
|
max_ptr = max_size_ + start_ptr_;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template class asn1::bit_ref_impl<uint8_t*>;
|
|
|
|
|
|
|
|
template class asn1::bit_ref_impl<const uint8_t*>;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SRSASN_CODE bit_ref::pack_bytes(const uint8_t* buf, uint32_t n_bytes)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (n_bytes == 0) {
|
|
|
|
|
|
|
|
return SRSASN_SUCCESS;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ptr + n_bytes >= max_ptr) {
|
|
|
|
|
|
|
|
srsasn_log_print(LOG_LEVEL_ERROR, "Buffer size limit was achieved\n");
|
|
|
|
|
|
|
|
return SRSASN_ERROR_ENCODE_FAIL;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (offset == 0) {
|
|
|
|
|
|
|
|
// Aligned case
|
|
|
|
|
|
|
|
memcpy(ptr, buf, n_bytes);
|
|
|
|
|
|
|
|
ptr += n_bytes;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < n_bytes; ++i) {
|
|
|
|
|
|
|
|
pack(buf[i], 8);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return SRSASN_SUCCESS;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SRSASN_CODE bit_ref::align_bytes_zero()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (offset == 0)
|
|
|
|
|
|
|
|
return SRSASN_SUCCESS;
|
|
|
|
|
|
|
|
if (ptr >= max_ptr) {
|
|
|
|
|
|
|
|
srsasn_log_print(LOG_LEVEL_ERROR, "Buffer size limit was achieved\n");
|
|
|
|
|
|
|
|
return SRSASN_ERROR_ENCODE_FAIL;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t mask = (uint8_t)(256u - (1u << (8u - offset)));
|
|
|
|
|
|
|
|
*ptr &= mask;
|
|
|
|
|
|
|
|
offset = 0;
|
|
|
|
|
|
|
|
ptr++;
|
|
|
|
|
|
|
|
return SRSASN_SUCCESS;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************
|
|
|
|
/*********************
|
|
|
|
ext packing
|
|
|
|
ext packing
|
|
|
|
*********************/
|
|
|
|
*********************/
|
|
|
@ -343,7 +392,7 @@ SRSASN_CODE pack_enum(bit_ref& bref, uint32_t e, uint32_t nof_types, uint32_t no
|
|
|
|
return ret;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ValOrError unpack_enum(uint32_t nof_types, uint32_t nof_exts, bool has_ext, bit_ref& bref)
|
|
|
|
ValOrError unpack_enum(uint32_t nof_types, uint32_t nof_exts, bool has_ext, cbit_ref& bref)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ValOrError ret;
|
|
|
|
ValOrError ret;
|
|
|
|
if (has_ext) {
|
|
|
|
if (has_ext) {
|
|
|
@ -457,7 +506,7 @@ pack_constrained_whole_number<uint64_t>(bit_ref& bref, uint64_t n, uint64_t lb,
|
|
|
|
* @return success or failure
|
|
|
|
* @return success or failure
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
template <class IntType>
|
|
|
|
template <class IntType>
|
|
|
|
SRSASN_CODE unpack_constrained_whole_number(IntType& n, bit_ref& bref, IntType lb, IntType ub, bool aligned)
|
|
|
|
SRSASN_CODE unpack_constrained_whole_number(IntType& n, cbit_ref& bref, IntType lb, IntType ub, bool aligned)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (ub < lb) {
|
|
|
|
if (ub < lb) {
|
|
|
|
srsasn_log_print(LOG_LEVEL_ERROR, "The condition lb <= ub (%ld <= %ld) was not met\n", (long)lb, (long)ub);
|
|
|
|
srsasn_log_print(LOG_LEVEL_ERROR, "The condition lb <= ub (%ld <= %ld) was not met\n", (long)lb, (long)ub);
|
|
|
@ -504,21 +553,21 @@ SRSASN_CODE unpack_constrained_whole_number(IntType& n, bit_ref& bref, IntType l
|
|
|
|
return SRSASN_SUCCESS;
|
|
|
|
return SRSASN_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
template SRSASN_CODE
|
|
|
|
template SRSASN_CODE
|
|
|
|
unpack_constrained_whole_number<int8_t>(int8_t& n, bit_ref& bref, int8_t lb, int8_t ub, bool aligned);
|
|
|
|
unpack_constrained_whole_number<int8_t>(int8_t& n, cbit_ref& bref, int8_t lb, int8_t ub, bool aligned);
|
|
|
|
template SRSASN_CODE
|
|
|
|
template SRSASN_CODE
|
|
|
|
unpack_constrained_whole_number<int16_t>(int16_t& n, bit_ref& bref, int16_t lb, int16_t ub, bool aligned);
|
|
|
|
unpack_constrained_whole_number<int16_t>(int16_t& n, cbit_ref& bref, int16_t lb, int16_t ub, bool aligned);
|
|
|
|
template SRSASN_CODE
|
|
|
|
template SRSASN_CODE
|
|
|
|
unpack_constrained_whole_number<int32_t>(int32_t& n, bit_ref& bref, int32_t lb, int32_t ub, bool aligned);
|
|
|
|
unpack_constrained_whole_number<int32_t>(int32_t& n, cbit_ref& bref, int32_t lb, int32_t ub, bool aligned);
|
|
|
|
template SRSASN_CODE
|
|
|
|
template SRSASN_CODE
|
|
|
|
unpack_constrained_whole_number<int64_t>(int64_t& n, bit_ref& bref, int64_t lb, int64_t ub, bool aligned);
|
|
|
|
unpack_constrained_whole_number<int64_t>(int64_t& n, cbit_ref& bref, int64_t lb, int64_t ub, bool aligned);
|
|
|
|
template SRSASN_CODE
|
|
|
|
template SRSASN_CODE
|
|
|
|
unpack_constrained_whole_number<uint8_t>(uint8_t& n, bit_ref& bref, uint8_t lb, uint8_t ub, bool aligned);
|
|
|
|
unpack_constrained_whole_number<uint8_t>(uint8_t& n, cbit_ref& bref, uint8_t lb, uint8_t ub, bool aligned);
|
|
|
|
template SRSASN_CODE
|
|
|
|
template SRSASN_CODE
|
|
|
|
unpack_constrained_whole_number<uint16_t>(uint16_t& n, bit_ref& bref, uint16_t lb, uint16_t ub, bool aligned);
|
|
|
|
unpack_constrained_whole_number<uint16_t>(uint16_t& n, cbit_ref& bref, uint16_t lb, uint16_t ub, bool aligned);
|
|
|
|
template SRSASN_CODE
|
|
|
|
template SRSASN_CODE
|
|
|
|
unpack_constrained_whole_number<uint32_t>(uint32_t& n, bit_ref& bref, uint32_t lb, uint32_t ub, bool aligned);
|
|
|
|
unpack_constrained_whole_number<uint32_t>(uint32_t& n, cbit_ref& bref, uint32_t lb, uint32_t ub, bool aligned);
|
|
|
|
template SRSASN_CODE
|
|
|
|
template SRSASN_CODE
|
|
|
|
unpack_constrained_whole_number<uint64_t>(uint64_t& n, bit_ref& bref, uint64_t lb, uint64_t ub, bool aligned);
|
|
|
|
unpack_constrained_whole_number<uint64_t>(uint64_t& n, cbit_ref& bref, uint64_t lb, uint64_t ub, bool aligned);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* X.691 - Section 10.6
|
|
|
|
* X.691 - Section 10.6
|
|
|
@ -541,7 +590,7 @@ SRSASN_CODE pack_norm_small_non_neg_whole_number(bit_ref& bref, UintType n)
|
|
|
|
return SRSASN_SUCCESS;
|
|
|
|
return SRSASN_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
template <typename UintType>
|
|
|
|
template <typename UintType>
|
|
|
|
SRSASN_CODE unpack_norm_small_non_neg_whole_number(UintType& n, bit_ref& bref)
|
|
|
|
SRSASN_CODE unpack_norm_small_non_neg_whole_number(UintType& n, cbit_ref& bref)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
bool ext;
|
|
|
|
bool ext;
|
|
|
|
SRSASN_CODE ret = bref.unpack(ext, 1);
|
|
|
|
SRSASN_CODE ret = bref.unpack(ext, 1);
|
|
|
@ -558,10 +607,10 @@ template SRSASN_CODE pack_norm_small_non_neg_whole_number<uint8_t>(bit_ref& bref
|
|
|
|
template SRSASN_CODE pack_norm_small_non_neg_whole_number<uint16_t>(bit_ref& bref, uint16_t n);
|
|
|
|
template SRSASN_CODE pack_norm_small_non_neg_whole_number<uint16_t>(bit_ref& bref, uint16_t n);
|
|
|
|
template SRSASN_CODE pack_norm_small_non_neg_whole_number<uint32_t>(bit_ref& bref, uint32_t n);
|
|
|
|
template SRSASN_CODE pack_norm_small_non_neg_whole_number<uint32_t>(bit_ref& bref, uint32_t n);
|
|
|
|
template SRSASN_CODE pack_norm_small_non_neg_whole_number<uint64_t>(bit_ref& bref, uint64_t n);
|
|
|
|
template SRSASN_CODE pack_norm_small_non_neg_whole_number<uint64_t>(bit_ref& bref, uint64_t n);
|
|
|
|
template SRSASN_CODE unpack_norm_small_non_neg_whole_number<uint8_t>(uint8_t& n, bit_ref& bref);
|
|
|
|
template SRSASN_CODE unpack_norm_small_non_neg_whole_number<uint8_t>(uint8_t& n, cbit_ref& bref);
|
|
|
|
template SRSASN_CODE unpack_norm_small_non_neg_whole_number<uint16_t>(uint16_t& n, bit_ref& bref);
|
|
|
|
template SRSASN_CODE unpack_norm_small_non_neg_whole_number<uint16_t>(uint16_t& n, cbit_ref& bref);
|
|
|
|
template SRSASN_CODE unpack_norm_small_non_neg_whole_number<uint32_t>(uint32_t& n, bit_ref& bref);
|
|
|
|
template SRSASN_CODE unpack_norm_small_non_neg_whole_number<uint32_t>(uint32_t& n, cbit_ref& bref);
|
|
|
|
template SRSASN_CODE unpack_norm_small_non_neg_whole_number<uint64_t>(uint64_t& n, bit_ref& bref);
|
|
|
|
template SRSASN_CODE unpack_norm_small_non_neg_whole_number<uint64_t>(uint64_t& n, cbit_ref& bref);
|
|
|
|
|
|
|
|
|
|
|
|
template <typename IntType>
|
|
|
|
template <typename IntType>
|
|
|
|
IntType unconstrained_whole_number_length(IntType n)
|
|
|
|
IntType unconstrained_whole_number_length(IntType n)
|
|
|
@ -590,7 +639,7 @@ SRSASN_CODE pack_unconstrained_whole_number(bit_ref& bref, IntType n, bool align
|
|
|
|
return SRSASN_SUCCESS;
|
|
|
|
return SRSASN_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
template <typename IntType>
|
|
|
|
template <typename IntType>
|
|
|
|
SRSASN_CODE unpack_unconstrained_whole_number(IntType& n, bit_ref& bref, bool aligned)
|
|
|
|
SRSASN_CODE unpack_unconstrained_whole_number(IntType& n, cbit_ref& bref, bool aligned)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// TODO: Test
|
|
|
|
// TODO: Test
|
|
|
|
uint32_t len;
|
|
|
|
uint32_t len;
|
|
|
@ -606,18 +655,18 @@ template SRSASN_CODE pack_unconstrained_whole_number<int8_t>(bit_ref& bref, int8
|
|
|
|
template SRSASN_CODE pack_unconstrained_whole_number<int16_t>(bit_ref& bref, int16_t n, bool aligned);
|
|
|
|
template SRSASN_CODE pack_unconstrained_whole_number<int16_t>(bit_ref& bref, int16_t n, bool aligned);
|
|
|
|
template SRSASN_CODE pack_unconstrained_whole_number<int32_t>(bit_ref& bref, int32_t n, bool aligned);
|
|
|
|
template SRSASN_CODE pack_unconstrained_whole_number<int32_t>(bit_ref& bref, int32_t n, bool aligned);
|
|
|
|
template SRSASN_CODE pack_unconstrained_whole_number<int64_t>(bit_ref& bref, int64_t n, bool aligned);
|
|
|
|
template SRSASN_CODE pack_unconstrained_whole_number<int64_t>(bit_ref& bref, int64_t n, bool aligned);
|
|
|
|
template SRSASN_CODE unpack_unconstrained_whole_number<int8_t>(int8_t& n, bit_ref& bref, bool aligned);
|
|
|
|
template SRSASN_CODE unpack_unconstrained_whole_number<int8_t>(int8_t& n, cbit_ref& bref, bool aligned);
|
|
|
|
template SRSASN_CODE unpack_unconstrained_whole_number<int16_t>(int16_t& n, bit_ref& bref, bool aligned);
|
|
|
|
template SRSASN_CODE unpack_unconstrained_whole_number<int16_t>(int16_t& n, cbit_ref& bref, bool aligned);
|
|
|
|
template SRSASN_CODE unpack_unconstrained_whole_number<int32_t>(int32_t& n, bit_ref& bref, bool aligned);
|
|
|
|
template SRSASN_CODE unpack_unconstrained_whole_number<int32_t>(int32_t& n, cbit_ref& bref, bool aligned);
|
|
|
|
template SRSASN_CODE unpack_unconstrained_whole_number<int64_t>(int64_t& n, bit_ref& bref, bool aligned);
|
|
|
|
template SRSASN_CODE unpack_unconstrained_whole_number<int64_t>(int64_t& n, cbit_ref& bref, bool aligned);
|
|
|
|
template SRSASN_CODE pack_unconstrained_whole_number<uint8_t>(bit_ref& bref, uint8_t n, bool aligned);
|
|
|
|
template SRSASN_CODE pack_unconstrained_whole_number<uint8_t>(bit_ref& bref, uint8_t n, bool aligned);
|
|
|
|
template SRSASN_CODE pack_unconstrained_whole_number<uint16_t>(bit_ref& bref, uint16_t n, bool aligned);
|
|
|
|
template SRSASN_CODE pack_unconstrained_whole_number<uint16_t>(bit_ref& bref, uint16_t n, bool aligned);
|
|
|
|
template SRSASN_CODE pack_unconstrained_whole_number<uint32_t>(bit_ref& bref, uint32_t n, bool aligned);
|
|
|
|
template SRSASN_CODE pack_unconstrained_whole_number<uint32_t>(bit_ref& bref, uint32_t n, bool aligned);
|
|
|
|
template SRSASN_CODE pack_unconstrained_whole_number<uint64_t>(bit_ref& bref, uint64_t n, bool aligned);
|
|
|
|
template SRSASN_CODE pack_unconstrained_whole_number<uint64_t>(bit_ref& bref, uint64_t n, bool aligned);
|
|
|
|
template SRSASN_CODE unpack_unconstrained_whole_number<uint8_t>(uint8_t& n, bit_ref& bref, bool aligned);
|
|
|
|
template SRSASN_CODE unpack_unconstrained_whole_number<uint8_t>(uint8_t& n, cbit_ref& bref, bool aligned);
|
|
|
|
template SRSASN_CODE unpack_unconstrained_whole_number<uint16_t>(uint16_t& n, bit_ref& bref, bool aligned);
|
|
|
|
template SRSASN_CODE unpack_unconstrained_whole_number<uint16_t>(uint16_t& n, cbit_ref& bref, bool aligned);
|
|
|
|
template SRSASN_CODE unpack_unconstrained_whole_number<uint32_t>(uint32_t& n, bit_ref& bref, bool aligned);
|
|
|
|
template SRSASN_CODE unpack_unconstrained_whole_number<uint32_t>(uint32_t& n, cbit_ref& bref, bool aligned);
|
|
|
|
template SRSASN_CODE unpack_unconstrained_whole_number<uint64_t>(uint64_t& n, bit_ref& bref, bool aligned);
|
|
|
|
template SRSASN_CODE unpack_unconstrained_whole_number<uint64_t>(uint64_t& n, cbit_ref& bref, bool aligned);
|
|
|
|
|
|
|
|
|
|
|
|
/*********************
|
|
|
|
/*********************
|
|
|
|
varlength_packing
|
|
|
|
varlength_packing
|
|
|
@ -638,18 +687,18 @@ template SRSASN_CODE pack_length<int32_t>(bit_ref& bref, int32_t n, int32_t lb,
|
|
|
|
template SRSASN_CODE pack_length<int64_t>(bit_ref& bref, int64_t n, int64_t lb, int64_t ub, bool aligned);
|
|
|
|
template SRSASN_CODE pack_length<int64_t>(bit_ref& bref, int64_t n, int64_t lb, int64_t ub, bool aligned);
|
|
|
|
|
|
|
|
|
|
|
|
template <typename IntType>
|
|
|
|
template <typename IntType>
|
|
|
|
SRSASN_CODE unpack_length(IntType& n, bit_ref& bref, IntType lb, IntType ub, bool aligned)
|
|
|
|
SRSASN_CODE unpack_length(IntType& n, cbit_ref& bref, IntType lb, IntType ub, bool aligned)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return unpack_constrained_whole_number(n, bref, lb, ub, aligned);
|
|
|
|
return unpack_constrained_whole_number(n, bref, lb, ub, aligned);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
template SRSASN_CODE unpack_length<uint8_t>(uint8_t& n, bit_ref& bref, uint8_t lb, uint8_t ub, bool aligned);
|
|
|
|
template SRSASN_CODE unpack_length<uint8_t>(uint8_t& n, cbit_ref& bref, uint8_t lb, uint8_t ub, bool aligned);
|
|
|
|
template SRSASN_CODE unpack_length<uint16_t>(uint16_t& n, bit_ref& bref, uint16_t lb, uint16_t ub, bool aligned);
|
|
|
|
template SRSASN_CODE unpack_length<uint16_t>(uint16_t& n, cbit_ref& bref, uint16_t lb, uint16_t ub, bool aligned);
|
|
|
|
template SRSASN_CODE unpack_length<uint32_t>(uint32_t& n, bit_ref& bref, uint32_t lb, uint32_t ub, bool aligned);
|
|
|
|
template SRSASN_CODE unpack_length<uint32_t>(uint32_t& n, cbit_ref& bref, uint32_t lb, uint32_t ub, bool aligned);
|
|
|
|
template SRSASN_CODE unpack_length<uint64_t>(uint64_t& n, bit_ref& bref, uint64_t lb, uint64_t ub, bool aligned);
|
|
|
|
template SRSASN_CODE unpack_length<uint64_t>(uint64_t& n, cbit_ref& bref, uint64_t lb, uint64_t ub, bool aligned);
|
|
|
|
template SRSASN_CODE unpack_length<int8_t>(int8_t& n, bit_ref& bref, int8_t lb, int8_t ub, bool aligned);
|
|
|
|
template SRSASN_CODE unpack_length<int8_t>(int8_t& n, cbit_ref& bref, int8_t lb, int8_t ub, bool aligned);
|
|
|
|
template SRSASN_CODE unpack_length<int16_t>(int16_t& n, bit_ref& bref, int16_t lb, int16_t ub, bool aligned);
|
|
|
|
template SRSASN_CODE unpack_length<int16_t>(int16_t& n, cbit_ref& bref, int16_t lb, int16_t ub, bool aligned);
|
|
|
|
template SRSASN_CODE unpack_length<int32_t>(int32_t& n, bit_ref& bref, int32_t lb, int32_t ub, bool aligned);
|
|
|
|
template SRSASN_CODE unpack_length<int32_t>(int32_t& n, cbit_ref& bref, int32_t lb, int32_t ub, bool aligned);
|
|
|
|
template SRSASN_CODE unpack_length<int64_t>(int64_t& n, bit_ref& bref, int64_t lb, int64_t ub, bool aligned);
|
|
|
|
template SRSASN_CODE unpack_length<int64_t>(int64_t& n, cbit_ref& bref, int64_t lb, int64_t ub, bool aligned);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* X.691 - Section 10.9
|
|
|
|
* X.691 - Section 10.9
|
|
|
@ -693,7 +742,7 @@ SRSASN_CODE pack_length(bit_ref& bref, uint32_t val, bool aligned)
|
|
|
|
return SRSASN_SUCCESS;
|
|
|
|
return SRSASN_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SRSASN_CODE unpack_length(uint32_t& val, bit_ref& bref, bool aligned)
|
|
|
|
SRSASN_CODE unpack_length(uint32_t& val, cbit_ref& bref, bool aligned)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
bool ext;
|
|
|
|
bool ext;
|
|
|
|
if (not aligned) {
|
|
|
|
if (not aligned) {
|
|
|
@ -803,7 +852,7 @@ template SRSASN_CODE pack_unconstrained_integer<int32_t>(bit_ref& bref, int32_t
|
|
|
|
template SRSASN_CODE pack_unconstrained_integer<int64_t>(bit_ref& bref, int64_t n, bool has_ext, bool aligned);
|
|
|
|
template SRSASN_CODE pack_unconstrained_integer<int64_t>(bit_ref& bref, int64_t n, bool has_ext, bool aligned);
|
|
|
|
|
|
|
|
|
|
|
|
template <typename IntType>
|
|
|
|
template <typename IntType>
|
|
|
|
SRSASN_CODE unpack_integer(IntType& n, bit_ref& bref, IntType lb, IntType ub, bool has_ext, bool aligned)
|
|
|
|
SRSASN_CODE unpack_integer(IntType& n, cbit_ref& bref, IntType lb, IntType ub, bool has_ext, bool aligned)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
bool within_bounds = true;
|
|
|
|
bool within_bounds = true;
|
|
|
|
if (has_ext) {
|
|
|
|
if (has_ext) {
|
|
|
@ -833,32 +882,33 @@ SRSASN_CODE unpack_integer(IntType& n, bit_ref& bref, IntType lb, IntType ub, bo
|
|
|
|
return SRSASN_SUCCESS;
|
|
|
|
return SRSASN_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
template SRSASN_CODE
|
|
|
|
template SRSASN_CODE
|
|
|
|
unpack_integer<uint8_t>(uint8_t& n, bit_ref& bref, uint8_t lb, uint8_t ub, bool has_ext, bool aligned);
|
|
|
|
unpack_integer<uint8_t>(uint8_t& n, cbit_ref& bref, uint8_t lb, uint8_t ub, bool has_ext, bool aligned);
|
|
|
|
|
|
|
|
template SRSASN_CODE
|
|
|
|
|
|
|
|
unpack_integer<uint16_t>(uint16_t& n, cbit_ref& bref, uint16_t lb, uint16_t ub, bool has_ext, bool aligned);
|
|
|
|
template SRSASN_CODE
|
|
|
|
template SRSASN_CODE
|
|
|
|
unpack_integer<uint16_t>(uint16_t& n, bit_ref& bref, uint16_t lb, uint16_t ub, bool has_ext, bool aligned);
|
|
|
|
unpack_integer<uint32_t>(uint32_t& n, cbit_ref& bref, uint32_t lb, uint32_t ub, bool has_ext, bool aligned);
|
|
|
|
template SRSASN_CODE
|
|
|
|
template SRSASN_CODE
|
|
|
|
unpack_integer<uint32_t>(uint32_t& n, bit_ref& bref, uint32_t lb, uint32_t ub, bool has_ext, bool aligned);
|
|
|
|
unpack_integer<uint64_t>(uint64_t& n, cbit_ref& bref, uint64_t lb, uint64_t ub, bool has_ext, bool aligned);
|
|
|
|
template SRSASN_CODE
|
|
|
|
template SRSASN_CODE
|
|
|
|
unpack_integer<uint64_t>(uint64_t& n, bit_ref& bref, uint64_t lb, uint64_t ub, bool has_ext, bool aligned);
|
|
|
|
unpack_integer<int8_t>(int8_t& n, cbit_ref& bref, int8_t lb, int8_t ub, bool has_ext, bool aligned);
|
|
|
|
template SRSASN_CODE unpack_integer<int8_t>(int8_t& n, bit_ref& bref, int8_t lb, int8_t ub, bool has_ext, bool aligned);
|
|
|
|
|
|
|
|
template SRSASN_CODE
|
|
|
|
template SRSASN_CODE
|
|
|
|
unpack_integer<int16_t>(int16_t& n, bit_ref& bref, int16_t lb, int16_t ub, bool has_ext, bool aligned);
|
|
|
|
unpack_integer<int16_t>(int16_t& n, cbit_ref& bref, int16_t lb, int16_t ub, bool has_ext, bool aligned);
|
|
|
|
template SRSASN_CODE
|
|
|
|
template SRSASN_CODE
|
|
|
|
unpack_integer<int32_t>(int32_t& n, bit_ref& bref, int32_t lb, int32_t ub, bool has_ext, bool aligned);
|
|
|
|
unpack_integer<int32_t>(int32_t& n, cbit_ref& bref, int32_t lb, int32_t ub, bool has_ext, bool aligned);
|
|
|
|
template SRSASN_CODE
|
|
|
|
template SRSASN_CODE
|
|
|
|
unpack_integer<int64_t>(int64_t& n, bit_ref& bref, int64_t lb, int64_t ub, bool has_ext, bool aligned);
|
|
|
|
unpack_integer<int64_t>(int64_t& n, cbit_ref& bref, int64_t lb, int64_t ub, bool has_ext, bool aligned);
|
|
|
|
|
|
|
|
|
|
|
|
// unconstrained specialization case
|
|
|
|
// unconstrained specialization case
|
|
|
|
template <typename IntType>
|
|
|
|
template <typename IntType>
|
|
|
|
SRSASN_CODE unpack_unconstrained_integer(IntType& n, bit_ref& bref, bool has_ext, bool aligned)
|
|
|
|
SRSASN_CODE unpack_unconstrained_integer(IntType& n, cbit_ref& bref, bool has_ext, bool aligned)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return unpack_integer(
|
|
|
|
return unpack_integer(
|
|
|
|
n, bref, std::numeric_limits<IntType>::min(), std::numeric_limits<IntType>::max(), has_ext, aligned);
|
|
|
|
n, bref, std::numeric_limits<IntType>::min(), std::numeric_limits<IntType>::max(), has_ext, aligned);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
template SRSASN_CODE unpack_unconstrained_integer<int8_t>(int8_t& n, bit_ref& bref, bool has_ext, bool aligned);
|
|
|
|
template SRSASN_CODE unpack_unconstrained_integer<int8_t>(int8_t& n, cbit_ref& bref, bool has_ext, bool aligned);
|
|
|
|
template SRSASN_CODE unpack_unconstrained_integer<int16_t>(int16_t& n, bit_ref& bref, bool has_ext, bool aligned);
|
|
|
|
template SRSASN_CODE unpack_unconstrained_integer<int16_t>(int16_t& n, cbit_ref& bref, bool has_ext, bool aligned);
|
|
|
|
template SRSASN_CODE unpack_unconstrained_integer<int32_t>(int32_t& n, bit_ref& bref, bool has_ext, bool aligned);
|
|
|
|
template SRSASN_CODE unpack_unconstrained_integer<int32_t>(int32_t& n, cbit_ref& bref, bool has_ext, bool aligned);
|
|
|
|
template SRSASN_CODE unpack_unconstrained_integer<int64_t>(int64_t& n, bit_ref& bref, bool has_ext, bool aligned);
|
|
|
|
template SRSASN_CODE unpack_unconstrained_integer<int64_t>(int64_t& n, cbit_ref& bref, bool has_ext, bool aligned);
|
|
|
|
|
|
|
|
|
|
|
|
// standalone packer
|
|
|
|
// standalone packer
|
|
|
|
template <class IntType>
|
|
|
|
template <class IntType>
|
|
|
@ -876,7 +926,7 @@ SRSASN_CODE integer_packer<IntType>::pack(bit_ref& bref, IntType n)
|
|
|
|
return pack_integer(bref, n, lb, ub, has_ext, aligned);
|
|
|
|
return pack_integer(bref, n, lb, ub, has_ext, aligned);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
template <class IntType>
|
|
|
|
template <class IntType>
|
|
|
|
SRSASN_CODE integer_packer<IntType>::unpack(IntType& n, bit_ref& bref)
|
|
|
|
SRSASN_CODE integer_packer<IntType>::unpack(IntType& n, cbit_ref& bref)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return unpack_integer(n, bref, lb, ub, has_ext, aligned);
|
|
|
|
return unpack_integer(n, bref, lb, ub, has_ext, aligned);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -962,7 +1012,7 @@ SRSASN_CODE unbounded_octstring<Al>::pack(bit_ref& bref) const
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <bool Al>
|
|
|
|
template <bool Al>
|
|
|
|
SRSASN_CODE unbounded_octstring<Al>::unpack(bit_ref& bref)
|
|
|
|
SRSASN_CODE unbounded_octstring<Al>::unpack(cbit_ref& bref)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
uint32_t len;
|
|
|
|
uint32_t len;
|
|
|
|
HANDLE_CODE(unpack_length(len, bref, aligned));
|
|
|
|
HANDLE_CODE(unpack_length(len, bref, aligned));
|
|
|
@ -1070,7 +1120,7 @@ pack(bit_ref& bref, const uint8_t* data, uint32_t len, uint32_t lb, uint32_t ub,
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Unpack ASN1 bitstring length prefix. Accommodates for cases: fixed/unbounded/bounded, aligned/unaligned, with/out ext
|
|
|
|
* Unpack ASN1 bitstring length prefix. Accommodates for cases: fixed/unbounded/bounded, aligned/unaligned, with/out ext
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
SRSASN_CODE unpack_length_prefix(uint32_t& len, bit_ref& bref, uint32_t lb, uint32_t ub, bool has_ext, bool is_aligned)
|
|
|
|
SRSASN_CODE unpack_length_prefix(uint32_t& len, cbit_ref& bref, uint32_t lb, uint32_t ub, bool has_ext, bool is_aligned)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
bool ext = false;
|
|
|
|
bool ext = false;
|
|
|
|
if (has_ext) {
|
|
|
|
if (has_ext) {
|
|
|
@ -1100,7 +1150,7 @@ SRSASN_CODE unpack_length_prefix(uint32_t& len, bit_ref& bref, uint32_t lb, uint
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// for both fixed, constrained and unconstrained scenarios
|
|
|
|
// for both fixed, constrained and unconstrained scenarios
|
|
|
|
SRSASN_CODE unpack_bitfield(uint8_t* buf, bit_ref& bref, uint32_t n, uint32_t lb, uint32_t ub, bool is_aligned)
|
|
|
|
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) {
|
|
|
|
if (n > ASN_64K) {
|
|
|
|
srsasn_log_print(LOG_LEVEL_ERROR, "bitstrings longer than 64K not supported\n");
|
|
|
|
srsasn_log_print(LOG_LEVEL_ERROR, "bitstrings longer than 64K not supported\n");
|
|
|
@ -1235,7 +1285,7 @@ pack(bit_ref& bref, const std::string& s, size_t lb, size_t ub, size_t alb, size
|
|
|
|
return SRSASN_SUCCESS;
|
|
|
|
return SRSASN_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SRSASN_CODE unpack(std::string& s, bit_ref& bref, size_t lb, size_t ub, size_t alb, size_t aub, bool ext, bool aligned)
|
|
|
|
SRSASN_CODE unpack(std::string& s, cbit_ref& bref, size_t lb, size_t ub, size_t alb, size_t aub, bool ext, bool aligned)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
size_t b = asn_string_utils::get_nof_bits_per_char(lb, ub, aligned);
|
|
|
|
size_t b = asn_string_utils::get_nof_bits_per_char(lb, ub, aligned);
|
|
|
|
bool octet_aligned = asn_string_utils::is_octet_aligned(b, alb, aub, aligned);
|
|
|
|
bool octet_aligned = asn_string_utils::is_octet_aligned(b, alb, aub, aligned);
|
|
|
@ -1258,7 +1308,7 @@ SRSASN_CODE unpack(std::string& s, bit_ref& bref, size_t lb, size_t ub, size_t a
|
|
|
|
s.resize(n);
|
|
|
|
s.resize(n);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (octet_aligned) {
|
|
|
|
if (octet_aligned) {
|
|
|
|
bref.align_bytes_zero();
|
|
|
|
bref.align_bytes();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (uint32_t i = 0; i < s.size(); ++i) {
|
|
|
|
for (uint32_t i = 0; i < s.size(); ++i) {
|
|
|
|
HANDLE_CODE(bref.unpack(s[i], b));
|
|
|
|
HANDLE_CODE(bref.unpack(s[i], b));
|
|
|
@ -1334,7 +1384,7 @@ ext_groups_unpacker_guard::~ext_groups_unpacker_guard()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SRSASN_CODE ext_groups_unpacker_guard::unpack(bit_ref& bref)
|
|
|
|
SRSASN_CODE ext_groups_unpacker_guard::unpack(cbit_ref& bref)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
bref_tracker = &bref;
|
|
|
|
bref_tracker = &bref;
|
|
|
|
// unpack nof of ext groups
|
|
|
|
// unpack nof of ext groups
|
|
|
@ -1387,7 +1437,7 @@ varlength_field_pack_guard::~varlength_field_pack_guard()
|
|
|
|
*bref_tracker = brefstart;
|
|
|
|
*bref_tracker = brefstart;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
varlength_field_unpack_guard::varlength_field_unpack_guard(bit_ref& bref, bool align)
|
|
|
|
varlength_field_unpack_guard::varlength_field_unpack_guard(cbit_ref& bref, bool align)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
unpack_length(len, bref, align);
|
|
|
|
unpack_length(len, bref, align);
|
|
|
|
bref0 = bref;
|
|
|
|
bref0 = bref;
|
|
|
|