now the unknown group exts are also consumed

This commit is contained in:
Francisco Paisana 2019-08-13 15:52:56 +01:00 committed by Andre Puschmann
parent 116dc0a57b
commit 939c8905cb
3 changed files with 279 additions and 238 deletions

View File

@ -922,17 +922,31 @@ copy_ptr<T> make_copy_ptr(const T& t)
ext group
*********************/
class ext_groups_header
class ext_groups_packer_guard
{
public:
ext_groups_header();
bool& operator[](uint32_t idx);
bool& operator[](uint32_t idx);
SRSASN_CODE pack(bit_ref& bref) const;
private:
bounded_array<bool, 20> groups;
};
class ext_groups_unpacker_guard
{
public:
explicit ext_groups_unpacker_guard(uint32_t nof_supported_groups_);
~ext_groups_unpacker_guard();
void resize(uint32_t new_size);
bool& operator[](uint32_t idx);
SRSASN_CODE unpack(bit_ref& bref);
private:
bounded_array<bool, 20> groups;
const uint32_t nof_supported_groups;
uint32_t nof_unpacked_groups = 0;
bit_ref* bref_tracker = nullptr;
};
/*********************

View File

@ -907,13 +907,7 @@ void log_invalid_choice_id(uint32_t val, const char* choice_type)
ext group
*********************/
ext_groups_header::ext_groups_header()
{
groups.resize(20);
std::fill(groups.data(), groups.data() + groups.size(), false);
}
bool& ext_groups_header::operator[](uint32_t idx)
bool& ext_groups_packer_guard::operator[](uint32_t idx)
{
if (idx >= groups.size()) {
uint32_t prev_size = groups.size();
@ -923,7 +917,7 @@ bool& ext_groups_header::operator[](uint32_t idx)
return groups[idx];
}
SRSASN_CODE ext_groups_header::pack(bit_ref& bref) const
SRSASN_CODE ext_groups_packer_guard::pack(asn1::bit_ref& bref) const
{
// pack number of groups
int32_t i = groups.size() - 1;
@ -942,16 +936,49 @@ SRSASN_CODE ext_groups_header::pack(bit_ref& bref) const
return SRSASN_SUCCESS;
}
SRSASN_CODE ext_groups_header::unpack(bit_ref& bref)
ext_groups_unpacker_guard::ext_groups_unpacker_guard(uint32_t nof_supported_groups_) :
nof_supported_groups(nof_supported_groups_)
{
resize(nof_supported_groups);
}
bool& ext_groups_unpacker_guard::operator[](uint32_t idx)
{
if (idx >= groups.size()) {
// only resizes for unknown extensions
resize(idx + 1);
}
return groups[idx];
}
void ext_groups_unpacker_guard::resize(uint32_t new_size)
{
// always grows
uint32_t prev_size = groups.size();
groups.resize(std::max(new_size, nof_supported_groups));
std::fill(&groups[prev_size], &groups[groups.size()], false);
}
ext_groups_unpacker_guard::~ext_groups_unpacker_guard()
{
uint32_t remaining = nof_unpacked_groups - std::min(nof_unpacked_groups, nof_supported_groups);
// consume all unknown extensions
while (remaining-- > 0) {
varlength_field_unpack_guard scope(*bref_tracker);
}
}
SRSASN_CODE ext_groups_unpacker_guard::unpack(bit_ref& bref)
{
bref_tracker = &bref;
// unpack nof of ext groups
uint32_t nof_groups;
HANDLE_CODE(unpack_norm_small_integer(nof_groups, bref));
nof_groups += 1;
groups.resize(nof_groups);
HANDLE_CODE(unpack_norm_small_integer(nof_unpacked_groups, bref));
nof_unpacked_groups += 1;
resize(nof_unpacked_groups);
// unpack each group presence flag
for (uint32_t i = 0; i < nof_groups; ++i) {
for (uint32_t i = 0; i < nof_unpacked_groups; ++i) {
HANDLE_CODE(bref.unpack(groups[i], 1));
}
return SRSASN_SUCCESS;

File diff suppressed because it is too large Load Diff