We stand with Ukraine
In most protocols, a receiver should rarely need to decode an OBJECT IDENTIFIER value. OBJECT IDENTIFIER values are constants usually tied to processing semantics (as with an algorithm identifier) and used as a switch in an application.
Once you've encoded each OID (OBJECT IDENTIFIER), and defined these encodings in your application as a list of known hex strings, you expect that in your application all you need to do is to determine that a given OID hex string you received in a message is some particular OID value by simply comparing the encoded OID value received against your encoded OID values.
So if you have the OBJECT IDENTIFIER values in encoded form, decoding the OBJECT IDENTIFIER value you receive is a waste of effort. It gains you little unless you perhaps intend to display the value or reformat it, say, from ASN.1 value notation to dotted format, and then pass it along for further processing.
Let's consider the details. Suppose you have the OID value:
then according to BER the encoded form would be:
The arcs of an OID value are encoded by a series of octets. In all but the last octet, bit 8 is set to 1. The last octet has bit 8 set to 0 indicating that it is the last octet for a given OID arc. Because the OID tree has only a limited number of branches near the top, an optimization is used when encoding the first two arcs. Instead of following the scheme above, the first two arcs are encoded in a single octet. The actual encoded number is derived according to the formula:
X*40 + Y
where X is the first arc and Y is the second. Thus, in the case above the number would be:
2 * 40 + 154 = 234 or 0xEA
Since the above number is too big to fit into a 7-bit number (bit #8 is set to 1) it is encoded as:
0xEA = 1110 1010 ==> 1 110 1010 ==> 1000 0001 0110 1010 = 0x816A
Since the encoder expects that you will pass an already encoded value (the default representation for OID values), it just copies what it is given.
Before calling the encoder you need to first call ossAsnValToEncodedOid() or ossDotValToEncodedOid() to convert an OID value from a value notation/dot notation to encoded form. The encoded form is a value of OBJECT IDENTIFIER type with the --<OBJECTID ENCODED>-- ASN.1 compiler directive (default).
As you can see, the ENCODED form permits the representation of OBJECT IDENTIFIER types with arc values exceeding the maximum integer representation on a given machine. The encoded value is derived according to the Rec. ITU-T X.690 (2008) document (clause 8.19).
The samples included with some of the Knowledge Center answers are meant for your general understanding of the OSS products. Different versions of the products might produce slightly different outputs. Consult the products documentation and samples for the most up-to-date products information and code examples.
Test drive the OSS Nokalva ASN.1, LTE, and XML Tools now! Your trial includes complete software, documentation, sample programs, free 24x7 technical support and more.
Our expert personnel can help you learn ASN.1!
We offer 4-day ASN.1 courses at our headquarters or your premises.