ASN1_STRING_PRINT_EX(3ossl)
π ASN1_STRING_PRINT_EX(3ossl) β like, the ASN1_STRING output routines, bestie
okay so this is a page from the OpenSSL manual, and it's genuinely a little gem: it's all about how to print out an ASN1_STRING. yes, that's the struct that gets used to represent, like, every ASN1 string type. iconic of it honestly. π
β¨ NAME β¨
ASN1_tag2str, ASN1_STRING_print_ex, ASN1_STRING_print_ex_fp, ASN1_STRING_print β the 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 these functions output an ASN1_STRING structure. and ASN1_STRING is the thing that's used to represent all the ASN1 string types. one struct to rule them all, main character energy fr fr π
ASN1_STRING_print_ex()β outputsstrtoout, and the format is decided by the options inflags. you're in control, bestie. πASN1_STRING_print_ex_fp()β literally identical, except it outputs tofpinstead.ASN1_STRING_print()β printsstrtoout, but with a different format thanASN1_STRING_print_ex(). specifically, it replaces unprintable characters (other thanCRandLF, those stay) with.. simple, lowkey charming.ASN1_tag2str()β returns a human-readable name of the specified ASN.1 tag. a little translator for your tag, we love a helpful icon. π
β NOTES β
π¨ASN1_STRING_print()is a deprecated function and you should avoid it β useASN1_STRING_print_ex()instead. don't be that girl using the deprecated one, ok? π
okay so there are, like, a large number of options. but here's the tea: most of the time ASN1_STRFLGS_RFC2253 is suitable. or, if you're on a UTF8 terminal, ASN1_STRFLGS_RFC2253 & ~ASN1_STRFLGS_ESC_MSB. write that down π
The complete set of supported options for flags is listed below. π
π 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. noted, no cap.
π The forms of escaping
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. But if ASN1_STRFLGS_ESC_QUOTE is set, then the whole string is instead surrounded by double quote characters β which is arguably more readable than the backslash notation. other characters use the "\XX" form, using exactly two characters of the hex representation. β¨
π§ UTF8 conversion
If ASN1_STRFLGS_UTF8_CONVERT is set, then characters are converted to UTF8 format first. and if your terminal supports the display of UTF8 sequences, then this option will correctly display multi byte characters. slay. π₯
π Ignoring the type
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 it can result in confusing output in multi character strings. you've been warned bestie π
π« Showing the type
If ASN1_STRFLGS_SHOW_TYPE is set, then the string type itself is printed out before its value (for example "BMPSTRING"). and fun fact: this actually uses ASN1_tag2str(). full circle moment π«Ά
π Dumping instead of interpreting
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. but ifASN1_STRFLGS_DUMP_UNKNOWNis set, then they will be dumped instead. - When a type is dumped, normally just the content octets are printed. but if
ASN1_STRFLGS_DUMP_DERis set, then the complete encoding is dumped instead (including tag and length octets). the whole package, periodt. π
π The RFC2253 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.ASN1_STRING_print()returns1on success or0on error.ASN1_tag2str()returns a human-readable name of the specified ASN.1 tag. (yes, it's in here twice, the page said it twice, I'm not gonna gatekeep the lore π)
π 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 3.5.6, dated 2026-04-07, from the ASN1_STRING_PRINT_EX(3ossl) manual β go forth and print your strings correctly, mwah πβ¨
π¦ where this page comes from
- freebsd 15.1: base 15.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms