Repository navigation
BER - Support OIDs with integers larger than 16383 - #307
Merged
Merged
Conversation
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.
Contributor
|
Looks good -- thanks for adding the tests. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 octet81 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