简体   繁体   中英

ASN.1 REAL - BER decoding

I was given the task on the subject ASN.1 decoding formats. I passed something storing structure tag is REAL, and I have to disassemble it and put in the type double. Problem is that very little information on the Internet. The number that I need to convert decimal form.

Here's an example:

first-man NUMBER ::= 
{  
    numb 11.987
}

The result is a number:

30098007 0231312E 393837

Immediately a lot of questions, the standard BER states:

A BER encoded "tag" is made up of several bit fields:

---------------------------------
| 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 |
---------------------------------
|Class  |P/C| Tag Number        |
---------------------------------

If I know that I will come exactly the type REAL, then why do I parse this structure, because it only selects the tag. Well, we got the number 30098007 0231312E 393837 . So what? What part of me can drop to decode back 11.987 , because I know that it is a floating point number. And in general, whether there is any structure in Microsoft for this coding?

Or if I know that my number in decimal form. I just used to decode the string? Such as the number 5.65 in the form of NR2 = "+5.65"? Just like that?

Unpacking the nested blocks:

30 09     -- SEQUENCE, of length 9
   80 07  -- [0], context-specific Tag 0 of length 7
      02 31 31 2E 39 38 37 -- ?? "11.987"

Context-specific means that its meaning is supposed to be known from the context. For instance, I haven't a clue what it means, because I don't have any context for it. As for that 02 byte -- it could be anything.

So this can't be decoded without further information. Where did it come from?

See ITU-T X.690 , §8.5, which describes the contents encoding for the REAL type. In practice, the REAL value is only rarely used.

Tony has provided a good breakdown of the encoding, which is a tag-length-value triad, but the encoding 02 31 31 2E 39 38 37 could use a little clarification. To understand the 02 prefix, we need to consult §8.5.6:

Bit 8 of the first contents octet shall be set as follows:

a) if bit 8 = 1, then the binary encoding specified in 8.5.7 applies;

b) if bit 8 = 0 and bit 7 = 0, then the decimal encoding specified in 8.5.8 applies;

c) if bit 8 = 0 and bit 7 = 1, then either a "SpecialRealValue" (see ITU-T Rec. X.680 | ISO/IEC 8824-1) or the value minus zero is encoded as in 8.5.9).

0x02 is 0b00000010 , so (b) applies here. 8.5.8 describes three possible forms, further specified in ISO 6093. Since that's an ISO standard, you won't find one freely available. These formats are, I believe, all ASCII character strings.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM