Files
swift-asn1/Sources
aryan-25 a9a5efd40e Encode signed integers correctly (#124)
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.
2026-05-27 14:29:30 +01:00
..