[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Bit String Error



Hello,
 
I am using SNACC to encode a simple bit string whose maximum length is 4 bits.  If only bit zero is set (corresponding to a hex value of 0x80), the bit string encodes as:
 
0x03, 0x01, 0x80
 
In my understanding, I believe that it should encode as
 
0x03, 0x02, 0x07, 0x80
 
Is my understanding correct?  If so, I think there is a bug in the asn-bits.c module.  The offending code is located in BEncAsnBitsContent:
 
/* check for special DER encoding rules to return 03 01 00 not
03 02 07 00 RWC */
if (((bits->bits[0] != 0) || (byteLen > 1)) && (unusedBits != 7))
{
BufPutByteRvs (b, (unsigned char)unusedBits);
return byteLen + 1;
}
else
return byteLen;
 
While I can't comment on what the code is trying to avoid here, it looks to me like the "(unusedBits != 7)" check is erroneously keeping the code from writing out the number of unused bits for this case.
 
Can you please advise?
 
Regards,
 
Chris