ASN1_STRING_PRINT_EX(3ossl)
π ASN1_STRING_PRINT_EX π
hii bestie, welcome to the 3ossl manual page β¨ this is literally the whole glow-up guide for printing out ASN1_STRING structures, and yes we're gonna get through every single flag together π«Ά
πΈ NAME πΈ
ASN1_tag2str, ASN1_STRING_print_ex, ASN1_STRING_print_ex_fp, ASN1_STRING_print β the ASN1_STRING output routines, aka the little crew that makes your ASN.1 strings printable π
β¨ 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 these functions output an ASN1_STRING structure, and ASN1_STRING is the thing used to represent, like, all the ASN1 string types π one struct, every string vibe.
ASN1_STRING_print_ex() outputs str to out, and the format is determined by the options in flags. ASN1_STRING_print_ex_fp() is literally identical except it outputs to fp instead π
ASN1_STRING_print() prints str to out but uses a different format than ASN1_STRING_print_ex(). it replaces unprintable characters (other than CR, LF) with . β that's the whole trick, no cap.
ASN1_tag2str() returns a human-readable name of the specified ASN.1 tag π
π NOTES π
π¨ okay important:ASN1_STRING_print()is a deprecated function and should be avoided β useASN1_STRING_print_ex()instead, bestie, it's the main character here π
so even though there are a large number of options, frequently ASN1_STRFLGS_RFC2253 is suitable, or on UTF8 terminals ASN1_STRFLGS_RFC2253 & ~ASN1_STRFLGS_ESC_MSB π
the complete set of supported options for flags is listed below, and yes we're doing all of them π
π escaping characters
various characters can be escaped:
- if
ASN1_STRFLGS_ESC_2253is set, the characters determined by RFC2253 are escaped. - if
ASN1_STRFLGS_ESC_CTRLis set, control characters are escaped. - if
ASN1_STRFLGS_ESC_MSBis set, characters with the MSB set are escaped. this option should not be used if the terminal correctly interprets UTF8 sequences π
escaping takes several forms, so let's break it down:
- 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's 32 bits, then"\WXXXXXXXX"is used, using eight characters of its hex representation. these forms will only be used if UTF8 conversion is not set (see below) β¨ - printable characters are normally escaped using the backslash
'\'character. ifASN1_STRFLGS_ESC_QUOTEis set, then the whole string is instead surrounded by double quote characters β this is arguably more readable than the backslash notation. other characters use the"\XX"form, using exactly two characters of the hex representation π
π the conversion flags
- if
ASN1_STRFLGS_UTF8_CONVERTis set, characters are converted to UTF8 format first. if the terminal supports the display of UTF8 sequences, then this option will correctly display multi byte characters π - if
ASN1_STRFLGS_IGNORE_TYPEis 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_TYPEis set, then the string type itself is printed out before its value (for example"BMPSTRING") β this actually usesASN1_tag2str()π¦
π dumping
the content of a string, instead of being interpreted, can be "dumped": this just outputs the value of the string using the form #XXXX, using hex format for each octet.
- if
ASN1_STRFLGS_DUMP_ALLis set, then any type is dumped. - normally non character string types (such as
OCTET STRING) are assumed to be one byte per character; ifASN1_STRFLGS_DUMP_UNKNOWNis set, then they will 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 (including tag and length octets) β¨
π the combo flag
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.ASN1_STRING_print()returns1on success or0on error.ASN1_tag2str()returns a human-readable name of the specified ASN.1 tag.
π«Ά SEE ALSO π«Ά
X509_NAME_print_ex(3), ASN1_tag2str(3)
π 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>.
okay that's the whole page bestie, go print some strings, slay π β¨
version 3.5.0 Β· dated 2026-09-25 Β· mwah, thanks for reading, ily π«Άπ
π¦ where this page comes from
- opensuse-leap 16.0: openssl-3-doc 3.5.0-160000.11.1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms