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() outputs str to out, and the format is decided by the options in flags. 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 to fp instead of out.
  • ASN1_STRING_print() prints str to out too, but it uses a different format than ASN1_STRING_print_ex(). what it does is replace unprintable characters with '.' β€” and when it says unprintable, that's every unprintable character except CR and LF. 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. use ASN1_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_2253 is set, the characters determined by RFC2253 get escaped.
  • if ASN1_STRFLGS_ESC_CTRL is set, control characters get escaped.
  • if ASN1_STRFLGS_ESC_MSB is 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_ALL is 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 if ASN1_STRFLGS_DUMP_UNKNOWN is set, then they'll 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 β€” 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() and ASN1_STRING_print_ex_fp() return the number of characters written, or -1 if an error occurred. so if you see a -1, something went wrong, bestie, don't ignore it 😭
  • ASN1_STRING_print() returns 1 on success or 0 on 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 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