The integers in BER are variable length.
That is a value that can fit into 24 bits will do so and not be encoded in 32 bits. We don't know the size of the integer until we see two things: the length in octets of the integer and its twos-complement sign bit. Side effect: this function, on a successful parsing of the integer, also skips the value field in the buffer. The sign bit determine if the resulting value is positive or negative.
NOTE, that "pBuffer[ index ]" MUST point to the start of the length field of the INTEGER type. That is the tag associated with the ASN.1 type should have already been processed by the caller and skipped. This function does not understand BER tags, but assumes that the caller does and has positioned pBuffer[ index ] to decode the length and value of the INTEGER.
- Parameters
-
pBuffer | [ in ] Byte array containg the ASN.1 encoded data to decode |
bufSize | [ in ] the amount of data (in bytes) pointed to by pBuffer |
index | [ in ] current offset into pBuffer, should be pointing to the length field of an integer tagged value [ out ] this index moves down the pBuffer data as the data is decoded |
value | [ out ] the calculated integer value which can be negative or a postive value |
- Returns
Success | P6R::eOk | |
Failure | P6R::eNotInitialized | A successful call to initialize was not made before this call. |
P6R::eInvalidArg | pBuffer is set to NULL. |
P6R::eTooBig | Any integer larger than 8 octets (64 bits) is not handled. |
errors from decodeLength() | This function calls decodeLength. |