scan_asn1derlength(3)

πŸ“¦
version 0.34 Β· 2 versions
  • 0.34 Β· alpine 3.24, debian bookworm, debian trixie, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking (latest)
  • 0.30 Β· fedora 43, fedora 44, ubuntu jammy
, in alpine 3.24, debian bookworm, debian trixie, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸ’– scan_asn1derlength(3) πŸ’–

okay bestie, so this is a page from the Library Functions Manual, and it's literally about one tiny little function that does one tiny little thing and does it flawlessly. periodt.


✨ NAME ✨

scan_asn1derlength β€” decode an unsigned integer from ASN.1 DER length encoding πŸŽ€


🌸 SYNTAX 🌸

#include <libowfat/scan.h>

size_t scan_asn1derlength(const char *src,size_t len,unsigned long long *dest);

like, that's the whole vibe. one include, one function, three args. slay.


πŸ¦‹ DESCRIPTION πŸ¦‹

scan_asn1derlength decodes an unsigned integer that's chillin' in ASN.1 DER length encoding, pulling it out of a memory area that's holding binary data. it drops the decoded value into dest and returns how many bytes it read from src. that's it. that's the job. πŸ’…

and she is so careful, omg. scan_asn1derlength never reads more than len bytes from src. like ever. if the sequence is longer than that, or if the memory area is out here containing an invalid sequence, she returns 0 and does not touch dest. not even a little. no cap.

🫢 bestie note: "does not touch dest" is a promise. your variable stays exactly how you left it.

so here's the tea on lengths: the length of the longest spec-compliant ASN.1 DER length is 128 bytes. BUT β€” and this is the part people get wrong β€” this implementation will return an error if the value doesn't fit into the target integer type. in practice, the largest sequence is sizeof(*dest)+1. remember that. it's giving "small but mighty." πŸ”₯

this implementation will reject values that are not encoded in the minimum amount of bytes. so if you rolled up with a lazy, padded-out encoding? she's not accepting it. minimum bytes or nothing. πŸ™ˆ

and in addition to reading the length value, this implementation will also validate the length value. if the length value is so large that the data would not fit in the source buffer, it will return a failure. so she's not just reading, she's checking, and honestly? main character energy. πŸ‘‘

but wait β€” what if you only want to parse the length value without this check? valid question, bestie. in that case, use scan_asn1derlengthvalue() instead. different function, different vibe, iykyk. ✨


πŸ‘€ SEE ALSO πŸ‘€


and that's the whole page, fr fr. this one came to you straight out of the Library Functions Manual β€” scan_asn1derlength(3), doing the most while reading the least. go decode something iconic. πŸ’–πŸŒˆβ­