ASN1_STRING_PRINT_EX(3)
π ASN1_STRING_PRINT_EX(3) π
okay so bestie, welcome to the Library Functions Manual era β this whole page is about the ASN1_STRING output routines, and honestly it's giving βniche but iconic.β We're gonna print, escape, dump, and vibe-check ASN.1 strings. No cap. π
πΈ NAME πΈ
ASN1_STRING_print_ex, ASN1_STRING_print_ex_fp, ASN1_STRING_print, and ASN1_tag2str β the ASN1_STRING output routines. periodt.
β¨ SYNOPSIS β¨
You're in libcrypto land, and you pull in <openssl/asn1.h>. The whole lineup is literally:
library βlibcryptoβ
#include <openssl/asn1.h>
int
ASN1_STRING_print_ex(BIO *out, const ASN1_STRING *str,
unsigned long flags);
int
ASN1_STRING_print_ex_fp(FILE *fp, const ASN1_STRING *str,
unsigned long flags);
int
ASN1_STRING_print(BIO *out, const ASN1_STRING *str);
const char *
ASN1_tag2str(int tag);
π DESCRIPTION π
These functions output an ASN1_STRING structure. And bestie, ASN1_STRING is used to represent all the ASN.1 string types. So yeah, main-character energy for string types. π«Ά
ASN1_STRING_print_ex()β outputsstrtoout, with the format being determined by the options inflags. Very choose-your-own-adventure.ASN1_STRING_print_ex_fp()β identical, except it outputs tofpinstead. Same vibe, different destination.ASN1_STRING_print()β printsstrtooutbut uses a different format thanASN1_STRING_print_ex(). It replaces unprintable characters (other thanCR,LF) with..ASN1_tag2str()β returns a human-readable name of the specified ASN.1tag. Slay, labels.
warning bestie:ASN1_STRING_print()is a deprecated function which should be avoided; useASN1_STRING_print_ex()instead. Not me using the deprecated oneβ¦ don't do it. π
Although there are a large number of options, ASN1_STRFLGS_RFC2253 is often suitable, or on UTF-8 terminals ASN1_STRFLGS_RFC2253 and ~ASN1_STRFLGS_ESC_MSB. That's the lowkey recommendation, fr fr.
The complete set of supported options for flags is listed below. Buckle up, because the flag lore is deep. π
ASN1_STRFLGS_ESC_2253β if set, the characters determined by RFC 2253 are escaped.ASN1_STRFLGS_ESC_CTRLβ if set, control characters are escaped.ASN1_STRFLGS_ESC_MSBβ if set, characters with the MSB set are escaped. This option should not be used if the terminal correctly interprets UTF-8 sequences.ASN1_STRFLGS_ESC_QUOTEβ if set, the whole string is surrounded by double quote characters instead of using backslash notation. This is arguably more readable. β¨ASN1_STRFLGS_UTF8_CONVERTβ if set, characters are converted to UTF-8 format first. If the terminal supports the display of UTF-8 sequences, then this option will correctly display multi-byte characters.ASN1_STRFLGS_IGNORE_TYPEβ if set, the string type is not interpreted at all: everything is assumed to be one byte per character. This is primarily for debugging purposes and can result in confusing output in multi-character strings. πASN1_STRFLGS_SHOW_TYPEβ if set, the string type itself is printed before its value (for example"BMPSTRING"), usingASN1_tag2str().ASN1_STRFLGS_DUMP_ALLβ if set, any type is dumped.ASN1_STRFLGS_DUMP_UNKNOWNβ normally non-character string types (such asOCTET STRING) are assumed to be one byte per character; if set, then they will be dumped instead.ASN1_STRFLGS_DUMP_DERβ when a type is dumped, normally just the content octets are printed; if set, then the complete encoding is dumped instead (including tag and length octets).ASN1_STRFLGS_RFC2253β includes all the flags required by RFC 2253. It is equivalent to:
ASN1_STRFLGS_ESC_2253 | ASN1_STRFLGS_ESC_CTRL |
ASN1_STRFLGS_ESC_MSB | ASN1_STRFLGS_UTF8_CONVERT |
ASN1_STRFLGS_DUMP_UNKNOWN | ASN1_STRFLGS_DUMP_DER
Now for the escaping tea β: escaping takes several forms. If the character being escaped is a 16-bit character, then the form "\UXXXX" is used using exactly four characters for the hex representation. If it is 32 bits, then "\WXXXXXXXX" is used using eight characters of its hex representation. These forms will only be used if UTF-8 conversion is not set (see above).
Printable characters are normally escaped using the backslash (\) character. If ASN1_STRFLGS_ESC_QUOTE is set, then the whole string is instead surrounded by double quote characters: this is arguably more readable than the backslash notation. Other characters use "\XX" using exactly two characters of the hex representation. iykyk.
If ASN1_STRFLGS_UTF8_CONVERT is set, then characters are converted to UTF-8 format first. If the terminal supports the display of UTF-8 sequences, then this option will correctly display multi-byte characters. π¦
If ASN1_STRFLGS_IGNORE_TYPE is set, then the string type is not interpreted at all: everything is assumed to be one byte per character. This is primarily for debugging purposes and can result in confusing output in multi-character strings.
If ASN1_STRFLGS_SHOW_TYPE is set, then the string type itself is printed before its value (for example "BMPSTRING"), using ASN1_tag2str().
Instead of being interpreted, the contents of a string can be βdumpedβ: this just outputs the value of the string using the form #XXXX using hex format for each octet. It's giving raw hex realness. π
If ASN1_STRFLGS_DUMP_ALL is set, then any type is dumped.
Normally non-character string types (such as OCTET STRING) are assumed to be one byte per character; if ASN1_STRFLGS_DUMP_UNKNOWN is set, then they will be dumped instead.
When a type is dumped, normally just the content octets are printed; if ASN1_STRFLGS_DUMP_DER is set, then the complete encoding is dumped instead (including tag and length octets).
ASN1_STRFLGS_RFC2253 includes all the flags required by RFC 2253. It is equivalent to ASN1_STRFLGS_ESC_2253 | ASN1_STRFLGS_ESC_CTRL | ASN1_STRFLGS_ESC_MSB | ASN1_STRFLGS_UTF8_CONVERT | ASN1_STRFLGS_DUMP_UNKNOWN | ASN1_STRFLGS_DUMP_DER.
π«Ά RETURN VALUES π«Ά
ASN1_STRING_print_ex()andASN1_STRING_print_ex_fp()β return the number of characters written, or-1if an error occurred.ASN1_STRING_print()β returns1on success or0on error.ASN1_tag2str()β returns a static string.
π SEE ALSO π
ASN1_parse_dump(3), ASN1_STRING_new(3), X509_NAME_print_ex(3), X509_signature_dump(3) β go read these too, bestie. The lore continues. π
π§ HISTORY π§
ASN1_STRING_print()first appeared in SSLeay 0.6.5 and has been available since OpenBSD 2.4.ASN1_tag2str()first appeared in OpenSSL 0.9.5 and has been available since OpenBSD 2.7.ASN1_STRING_print_ex()andASN1_STRING_print_ex_fp()first appeared in OpenSSL 0.9.6 and have been available since OpenBSD 2.9.
okay that's the whole page, bestie β iconic behavior from the ASN.1 string output girlies. This one is from Debian, dated June 8, 2025. xoxo, manual page π β¨
π¦ where this page comes from
- alpine 3.24: libressl-doc 4.3.1-r0 Β· custom
- arch rolling: libressl 4.4.0-1 Β· ISC AND custom:OpenSSL
- Copyright (c) 2002, 2004, 2007, 2013, 2016, 2017 The OpenSSL Project
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms