feat: decode BER-OID key into int (KLV::getTagAsInt)#7
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a convenience API on KLV to decode BER-OID (base-128) encoded keys into an integer, addressing a previously noted gap in the parser and adding unit tests to exercise the new behavior.
Changes:
- Add
KLV::getTagAsInt(uint64_t& out)to accumulate 7-bit BER-OID key bytes into auint64_t. - Remove the BER-OID “human-readable tag” TODO from
KlvParser. - Add
TEST_Fcoverage for single-byte, multi-byte, empty-key, and oversized-key rejection scenarios.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
src/Klv.cpp |
Implements KLV::getTagAsInt BER-OID-to-uint64_t decoder. |
include/Klv.h |
Exposes the new getTagAsInt API and documents its return behavior. |
src/KlvParser.cpp |
Removes obsolete TODO related to BER-OID tag decoding. |
test/KlvTest.cpp |
Adds new unit tests for getTagAsInt behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
fac8090 to
17d3866
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
17d3866 to
cf34d17
Compare
Fills the gap the parser's own TODO flagged; consumers no longer re-implement the 7-bit accumulate.
cf34d17 to
43aac5c
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Summary
KLV::getTagAsInt(uint64_t& out)— validates BER-OID continuation structure, caps at 10 bytes, and rejects any accumulation that would overflowuint64_t.KlvParser.cpp:90that flagged exactly this gap.Why
libklv handed the raw key bytes through without decoding, forcing every consumer to re-implement the same 7-bit accumulate. This closes that gap on the class itself with proper validation so hand-constructed KLVs can't silently produce garbage.
Test plan
KlvTest.cpppass (built against brew googletest 1.17, C++17): the 1 pre-existing case plus 8 new cases covering single-byte, multi-byte, empty key, universal-key rejection, malformed continuation (both directions), fulluint64_trange, and overflow rejection.child->getTagAsInt(tag).