Skip to content

BER - Support OIDs with integers larger than 16383 - #307

Merged
DougLau merged 1 commit into
mnit-rtmc:masterfrom
Wostmann:BER-support-large-oid-ints
Oct 1, 2026
Merged

DougLau merged 1 commit into
mnit-rtmc:masterfrom
Wostmann:BER-support-large-oid-ints

Conversation

@djaeckel-wai

Copy link
Copy Markdown
Contributor

The current BER ObjectIdentifier (OID) encoding only support numbers between 0 and 16383. Any OIDs with larger values have their significant bits "truncated". This change supports BER encoding of OIDs containing numbers larger than 16383.

BER encodes OIDs in 8-bit chunks (octet) in big-endian. The first two octets encode the object type (06) and the length. Next, the first two values of the OID are combined using a function (value1 * 40 + value2). Subsequent numbers are encoded as base 128 or in 7-bit chunks with each octet's most-significant bit signifying whether the number is complete (0) or requires consuming another chunk (1).

For example, 16383 is encoded as 2 octets equaling (in hex) to ff 7f, whereas 16384 requires another octet 81 80 00.

This implementation keeps the existing logic and simply writes the number to the byte array if less than 127 (0x7F). If larger, it calculates the required number of 7-bit chunks to represent the number, then iteratively writes each required chunk to the byte array with the most-significant bit set to 1 until the final chunk is written with the most-significant bit set to 0.

The includes some tests to verify the correct encoding output. The second and fourth tests will fail without the changes included in this commit.

This fixes #306

The current BER ObjectIdentifier (OID) encoding only support numbers between 0 and 16383. Any OIDs with larger values have their significant bits "truncated". This change supports BER encoding of OIDs containing numbers larger than 16383.

BER encodes OIDs in 8-bit chunks (octet) in big-endian. The first two octets encode the object type (06) and the length. Next, the first two values of the OID are combined using a function (value1 * 40 + value2). Subsequent numbers are encoded as base 128 or in 7-bit chunks with each octet's most-significant bit signifying whether the number is complete (0) or requires consuming another chunk (1).

For example, 16383 is encoded as 2 octets equaling (in hex) to `ff 7f`, whereas 16384 requires another octet `81 80 00`.

This implementation keeps the existing logic and simply writes the number to the byte array if less than 127 (0x7F). If larger, it calculates the required number of 7-bit chunks to represent the number, then iteratively writes each required chunk to the byte array with the most-significant bit set to 1 until the final chunk is written with the most-significant bit set to 0.

The includes some tests to verify the correct encoding output. The second and fourth tests will fail without the changes included in this commit.
@DougLau

DougLau commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

Looks good -- thanks for adding the tests.

@DougLau
DougLau merged commit cfed205 into mnit-rtmc:master Oct 1, 2026
2 checks passed
@djaeckel-wai
djaeckel-wai deleted the BER-support-large-oid-ints branch October 2, 2026 14:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BER - OID encoding does not support SubIDs larger than 16383

2 participants