maxime-esa / asn1scc

ASN1SCC: An open source ASN.1 compiler for embedded systems

Home Page:https://www.thanassis.space/asn1.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Named bit string positions with UPER

aosterhage opened this issue · comments

I'm utilizing asn1scc with UPER encodings in C. I can't find the appropriate information in the ITU-T X.691 document about encoding bit strings but examining several different ASN.1 compilers it seems that bit strings are flipped in UPER from how they are defined. E.g. given this definition of a bit string:

BitString BIT STRING ::= {
  first(0),
  second(1),
  third(2)
} (SIZE(3))

this data:

someBitString BitString ::= { first, second, third }

will be encoded to:
0x e0 or 0b 1110 0000

My confusion comes from the included bit string names provided by asn1scc (per #196). It will provide something similar to:

#define BitString_first 0x1  /*(1 << 0)*/
#define BitString_second 0x2  /*(1 << 1)*/
#define BitString_third 0x4  /*(1 << 2)*/

which seemingly are unusable for constructing or examining any BitString types because the C library doesn't seem to do any conversions. Is this expected or do I have a misunderstanding somewhere?

@usr3-1415 will correct me if I am wrong but I think you are right and this is what I reported in this comment : #196 (comment)

Thanks for the link, I missed that comment when going through the thread

A new set of functions is now generated that help programmer to set the bit string.
In this case, these functions will be called BitString_set_first(), BitString_set_second() etc.
There functions are not called during the encoding or decoding process.