Menu

Zero-copy DER INTEGER: point at the positive, compute the negative
📰

Zero-copy DER INTEGER: point at the positive, compute the negative

DEV Community: cpp·polycratia·9 days ago
#aWVaOdcd
#devtocpp#devto#dev#0xff#0x00
Long article (2209 words) — no AI summary yet.
Reading 0:00
15s threshold

A DER INTEGER carries no width. A certificate serial number can be wider than any integer type your platform has, and it is written as two's complement, so the digits of a negative value are not in the document at all. A reader that allocates nothing cannot hand you "the number" uniformly: for one sign the bytes are already sitting there to point at, and for the other they have to be produced somewhere. The asymmetry lives in the format itself, so the API has one honest shape available and that is the one it takes.

I write this from the reading side. In payments and crypto work since 2018 I have spent more time parsing other people's encodings than designing my own, and the integers that matter (serial numbers, key material, ASN.1-wrapped amounts) are routinely wider than a register and not under my control.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.