3

Here is what my structure looks like:

 SET OF
  SEQUENCE:
     INTEGER: XX
     INTEGER: YY

My encoding looks like this:

11 08 10 06 02 01 XX 02 01 YY        

11 08 -- SET OF
10 06 -- SEQUENCE 

However, when I decode with openssl, I don't see the expected output. It looks like

  0:d=0  hl=2 l=   8 prim: SET               
      0000 - 10 06 02 01 XX 02 01 YY-  

This is not what I expected to see. (Look at the structure I wanted it to look like)

I am not sure what I am missing. Any help would be much appreciated.

ExceptionHandler
  • 213
  • 1
  • 8
  • 24

1 Answers1

3

A SET and SEQUENCE are constructed types. That means that the bit that indicates a constructed type in the tag needs to be set. That would be bit 5 or 6 (depending if you start with bit 0 or 1). If the bit isn't set then the parser will view it as a primitive type, which means it has a single value instead of children. This is why you get prim in your output. The tag number is still 17 or 16 which denotes a SET OF or SEQUENCE, so the structure is still seen to be a SET.

So instead of 11 and 10 you should be using values 31 and 30. Then your code should parse correctly.

Maarten Bodewes
  • 90,524
  • 13
  • 150
  • 263
  • Note that there are ASN.1 editors out there that you can use to build BER structures with a nice GUI interface. You could use those to create some test structures. "ASN.1 editor" is just one of them. – Maarten Bodewes Jan 25 '16 at 18:12
  • Was trying to write my own little encoder for integers. But the thing that I don't understand is what would be the scenario in which one would use 11 or 10? – ExceptionHandler Jan 26 '16 at 11:54
  • Basically never. That combination of primitive bit and tag number doesn't make sense. You can however split some primitive types such as OCTET STRING. So tag 24 may make sense... – Maarten Bodewes Jan 26 '16 at 12:42