---
name: "libressl-ASN1_STRING_print_ex"
section: "3"
platform: "linux"
package: "libressl"
version: "4.4.0-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/libressl-ASN1_STRING_print_ex"
---

# libressl-ASN1\_STRING\_print\_ex(3)

ASN1\_STRING output routines

## NAME

**ASN1\_STRING\_print\_ex**, **ASN1\_STRING\_print\_ex\_fp**, **ASN1\_STRING\_print**, **ASN1\_tag2str** – ASN1\_STRING output routines

## SYNOPSIS

Crypto Library (libcrypto, -lcrypto)

**#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. *ASN1\_STRING* is used to represent all the ASN.1 string types.

**ASN1\_STRING\_print\_ex**() outputs *str* to *out*, the format being determined by the options *flags*. **ASN1\_STRING\_print\_ex\_fp**() is identical except it outputs to *fp* instead.

**ASN1\_STRING\_print**() prints *str* to *out* but using a different format to **ASN1\_STRING\_print\_ex**(). It replaces unprintable characters (other than CR, LF) with ‘.’.

**ASN1\_tag2str**() returns a human-readable name of the specified ASN.1 *tag*.

**ASN1\_STRING\_print**() is a deprecated function which should be avoided; use **ASN1\_STRING\_print\_ex**() instead.

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.

The complete set of supported options for *flags* is listed below.

Various characters can be escaped. If ASN1\_STRFLGS\_ESC\_2253 is set, the characters determined by RFC 2253 are escaped. If ASN1\_STRFLGS\_ESC\_CTRL is set, control characters are escaped. If ASN1\_STRFLGS\_ESC\_MSB is set, characters with the MSB set are escaped: this option should *not* be used if the terminal correctly interprets UTF-8 sequences.

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 below).

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 the "\\XX" using exactly two characters of the hex representation.

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.

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**() and **ASN1\_STRING\_print\_ex\_fp**() return the number of characters written or -1 if an error occurred.

**ASN1\_STRING\_print**() returns 1 on success or 0 on 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)

## 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**() and **ASN1\_STRING\_print\_ex\_fp**() first appeared in OpenSSL 0.9.6 and have been available since OpenBSD 2.9.
