rusticata / asn1-rs

Parsers/Encoders for ASN.1 BER/DER data
Apache License 2.0
10 stars 14 forks source link

Fix encoding integers #15

Closed kleinweby closed 1 year ago

kleinweby commented 2 years ago

When encoding unsigned integers we must prefix the representation with an extra 0x00 if the high bit is set. Otherwise it would be interpreted as a negative number.

Additionally we should remove any redundant leading 0xFF and 0x00 bytes.

Before this patch the code would mixed up these encodings. It would always add an 0x00 to signed negative numbers and remove leading 0x00 for positive numbers.

This patch introduces encode tests akin to the decode tests for integers and fixes the implementations for encoding.

Additionally we fixed to tests that tested for this wrong behaviour.

kleinweby commented 2 years ago

I've added an additional commit to make clippy happy with the current master.

chifflier commented 1 year ago

Hi, sorry for the long delay ... I can confirm the problem and will merge the commit after some additional tests. Thanks

chifflier commented 1 year ago

Merged in 22ebd425eec29477e12776c4edf9693b12e549da Thanks!