ASN1_STRING_PRINT_EX(3SSL)
π ASN1_STRING_PRINT_EX β the OpenSSL manual, bestie edition β¨
okay so real quick, the manual name is ASN1_STRING_PRINT_EX(3SSL) and yes this whole page is from the OpenSSL crew π pull up a chair, we're talking about printing out ASN.1 strings and it's honestly more fun than it sounds. no cap.
πΈ NAME πΈ
ASN1_tag2str, ASN1_STRING_print_ex, ASN1_STRING_print_ex_fp, ASN1_STRING_print β the whole little squad of ASN1_STRING output routines π
β¨ SYNOPSIS β¨
#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 π¦
so basically these functions all print out an ASN1_STRING structure. and ASN1_STRING? that's the girl who represents literally every single ASN.1 string type. main character energy, truly π
ASN1_STRING_print_ex()outputsstrtoout, and the format is decided by the options inflags. it does whatever the flags tell it, and it does it iconically.ASN1_STRING_print_ex_fp()is the exact same thing, no difference at all, except it writes tofpinstead ofout.ASN1_STRING_print()printsstrtoouttoo, but it uses a different format thanASN1_STRING_print_ex(). what it does is replace unprintable characters with'.'β and when it says unprintable, that's every unprintable character exceptCRandLF. those two get to stay, periodt.ASN1_tag2str()hands you back a human-readable name for the ASN.1 tag you passed in. it's giving translator π«Ά
π NOTES π
ASN1_STRING_print()is deprecated, bestie. like, avoid it. useASN1_STRING_print_ex()instead, fr fr. don't be texting your ex.
okay so there are a large number of options β like, a lot β and it can be overwhelming, but the frequently-useful move is: ASN1_STRFLGS_RFC2253 is suitable. or, if you're on a UTF8 terminal, ASN1_STRFLGS_RFC2253 & ~ASN1_STRFLGS_ESC_MSB. slay. that's the cheat code iykyk.
the complete set of supported options for flags is listed below π
π€ escaping, but make it aesthetic π€
various characters can be escaped, and which ones depends on what you asked for:
- if
ASN1_STRFLGS_ESC_2253is set, the characters determined by RFC2253 get escaped. - if
ASN1_STRFLGS_ESC_CTRLis set, control characters get escaped. - if
ASN1_STRFLGS_ESC_MSBis set, characters with the MSB set get escaped. this option should not be used if the terminal correctly interprets UTF8 sequences β that's the literal warning, respect it π
escaping takes several forms, and this is the part where you have to pay attention, sorry gorgeous:
- if the character being escaped is a 16 bit character, then the form
"\UXXXX"is used, with exactly four characters for the hex representation. - if it's 32 bits, then
"\WXXXXXXXX"is used, with eight characters of its hex representation.
these forms will only be used if UTF8 conversion is not set (see below). no UTF8, no fancy form, that's the rule β¨
printable characters are normally escaped using the backslash '\' character. but if ASN1_STRFLGS_ESC_QUOTE is set, then instead the whole string gets surrounded by double quote characters. and honestly? that is arguably more readable than the backslash notation. it's giving glow-up π
other characters use the form "\XX" with exactly two characters of the hex representation.
if ASN1_STRFLGS_UTF8_CONVERT is set, then the characters are converted to UTF8 format first. and if your terminal supports displaying UTF8 sequences, this option will correctly display multi byte characters. gorgeous, correct, no notes π
if ASN1_STRFLGS_IGNORE_TYPE is set, then the string type is not interpreted at all β everything is just assumed to be one byte per character. this is primarily for debugging purposes and it can result in confusing output in multi character strings. so like, it's a vibe, but a chaotic one π
if ASN1_STRFLGS_SHOW_TYPE is set, then the string type itself gets printed out before its value (for example "BMPSTRING"). and fun fact, this actually uses ASN1_tag2str() to do it. teamwork makes the dream work π«Ά
π¦ dumping: the alternative reading π¦
the content of a string, instead of being interpreted, can be "dumped" β which just means it outputs the value of the string using the form #XXXX with hex format for each octet. very raw, very unfiltered, very demure.
- if
ASN1_STRFLGS_DUMP_ALLis set, then any type gets dumped. no exceptions, all of them, periodt. - normally, non character string types (like
OCTET STRING) are assumed to be one byte per character. but ifASN1_STRFLGS_DUMP_UNKNOWNis set, then they'll be dumped instead. - when a type is dumped, normally just the content octets are printed. if
ASN1_STRFLGS_DUMP_DERis set, then the complete encoding is dumped instead β that means the tag and length octets are included too. full package, no crumbs β¨
π the big combo π
ASN1_STRFLGS_RFC2253 includes all the flags required by RFC2253. 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. so if you see a-1, something went wrong, bestie, don't ignore it πASN1_STRING_print()returns1on success or0on error. classic binary, we love a simple girl.ASN1_tag2str()returns a human-readable name of the specified ASN.1 tag. yes, again, that's the whole job. iconic.
π SEE ALSO π
π COPYRIGHT π
Copyright 2002-2018 The OpenSSL Project Authors. All Rights Reserved.
Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at <https://www.openssl.org/source/license.html>.
and that's the whole page, bestie!! πβ¨ this was version 4.0.3, dated 2026-09-29, and the page itself is ASN1_STRING_PRINT_EX(3SSL) from the OpenSSL lineup. go forth and print your strings correctly, ily, bye ππ¦πΈ
π¦ where this page comes from
- ubuntu stonking: libssl-doc 4.0.3-1ubuntu1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms