mirror of
https://github.com/apple/swift-asn1
synced 2026-11-24 04:17:50 +00:00
Motivation: Currently, positive signed integers whose minimal big-endian representation exactly fills N bytes (`neededBits % 8 == 0`) have their top bit misread as the DER sign bit. `Int64(128)` is therefore encoded as `[0x80]` and decoded back as `-128`. We should fix this. Modifications: - Updated the `FixedWidthInteger.neededBytes` implementation to return `bytes + 1` for positive signed integers in this case, causing `IntegerBytesCollection` to emit the required `0x00` sign byte. - Added associated test cases. Result: Positive signed integers whose minimal big-endian representation exactly fills N bytes (`neededBits % 8 == 0`) are now encoded correctly.