ASN1_PRINTABLE_TYPE(3)

πŸ“¦ version 4.4.0, in alpine 3.24, arch rolling

πŸ’… ASN1_PRINTABLE_TYPE(3) πŸ’…

okay so bestie, this is a page from the Library Functions Manual (yes the section 3 girlies, we love a library function) β€” and it's all about ASN1_PRINTABLE_type, which is lowkey just a little detective that looks at your string and goes "hmm, what kind of string are you?" πŸ•΅οΈβ€β™€οΈβœ¨


✨ SYNOPSIS ✨

you pull it out of libcrypto, and it looks like this:

#include <openssl/asn1.h>

int
ASN1_PRINTABLE_type(const unsigned char *string, int len);

that's it. that's the whole vibe check. πŸŽ€


🌸 DESCRIPTION 🌸

So ASN1_PRINTABLE_type() assumes your string is made of single-byte characters (no fancy multi-byte nonsense, we're being strict here) and then it classifies it based on which kinds of characters show up in it. πŸ¦‹

About that len, tho:

  • if len is greater than 0, it inspects at most len characters β€” like, it will literally not look further than that, respectfully πŸ™ˆ
  • otherwise (len is 0 or less), your string needs to be NUL-terminated, no cap, that's the deal

πŸ‘‘ RETURN VALUES πŸ‘‘

this is the part where it tells you who it thinks you are. three possible answers, and the order genuinely matters:

  1. if your string contains a character outside the ascii(7) range, it returns V_ASN1_T61STRING πŸ’€
  2. otherwise, if it contains a character that is neither a letter nor a digit nor the space character (' ', ASCII 0x20) nor the apostrophe quote ('\'', ASCII 0x27) nor contained in the set "()+,-./:=?" β€” then it returns V_ASN1_IA5STRING 😭
  3. otherwise β€” including if string is a NULL pointer or points to an empty string β€” it returns V_ASN1_PRINTABLESTRING πŸ’–

so yes, the coolest answer is also the fallback. main character energy fr fr. πŸ‘‘


🫢 SEE ALSO 🫢

go read these next, they're iconic:


🧚 HISTORY 🧚

ASN1_PRINTABLE_type() first appeared in SSLeay 0.4.5d, has been part of the public API since SSLeay 0.5.1, and has been available since OpenBSD 2.4. so she's been out here slaying since before most of us were born, periodt. ⭐


⚠️ CAVEATS ⚠️

ngl this one's important: the ASN.1 notion of what constitutes a PrintableString is more restrictive than what the C library function isprint(3) considers printable. so don't go assuming isprint(3) saying "yeah that's printable" means ASN.1 agrees, because she does not. πŸ’…

and that's the whole page, bestie 🌈 β€” brought to you by the Debian girlies, dated June 8, 2025, in manual section 3. now go classify some strings, you absolute icon πŸ’œπŸ¦‹πŸ“

πŸ“¦ where this page comes from