---
name: "libressl-d2i_X509_NAME"
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-d2i_X509_NAME"
---

# libressl-d2i\_X509\_NAME(3)

decode and encode X.501 Name objects

## NAME

**d2i\_X509\_NAME**, **i2d\_X509\_NAME**, **X509\_NAME\_get0\_der**, **X509\_NAME\_dup**, **X509\_NAME\_set**, **d2i\_X509\_NAME\_ENTRY**, **i2d\_X509\_NAME\_ENTRY**, **X509\_NAME\_ENTRY\_dup** – decode and encode X.501 Name objects

## SYNOPSIS

Crypto Library (libcrypto, -lcrypto)

**#include \<openssl/x509.h\>**

*X509\_NAME* *\**\

**d2i\_X509\_NAME**(*X509\_NAME \*\*val\_out*, *const unsigned char \*\*der\_in*, *long length*);

*int*\

**i2d\_X509\_NAME**(*X509\_NAME \*val\_in*, *unsigned char \*\*der\_out*);

*int*\

**X509\_NAME\_get0\_der**(*X509\_NAME \*val\_in*, *const unsigned char \*\*der\_out*, *size\_t \*out\_len*);

*X509\_NAME* *\**\

**X509\_NAME\_dup**(*X509\_NAME \*val\_in*);

*int*\

**X509\_NAME\_set**(*X509\_NAME \*\*val\_out*, *X509\_NAME \*val\_in*);

*X509\_NAME\_ENTRY* *\**\

**d2i\_X509\_NAME\_ENTRY**(*X509\_NAME\_ENTRY \*\*val\_out*, *const unsigned char \*\*der\_in*, *long length*);

*int*\

**i2d\_X509\_NAME\_ENTRY**(*X509\_NAME\_ENTRY \*val\_in*, *unsigned char \*\*der\_out*);

*X509\_NAME\_ENTRY* *\**\

**X509\_NAME\_ENTRY\_dup**(*X509\_NAME\_ENTRY \*val\_in*);

## DESCRIPTION

These functions decode and encode X.501 *Name* objects using DER format. For details about the semantics, examples, caveats, and bugs, see ASN1\_item\_d2i(3).

**d2i\_X509\_NAME**() and **i2d\_X509\_NAME**() decode and encode an ASN.1 *Name* structure defined in RFC 5280 section 4.1.2.4.

**X509\_NAME\_get0\_der**() is a variant of **i2d\_X509\_NAME**() that does not copy the encoded output but instead returns a pointer to the internally cached DER-encoded version of the name. Also, it does not return the length of the output in bytes, but instead stores it in *out\_len*. If the cached encoded form happens to be out of date, both functions update it before copying it or returning a pointer to it.

**X509\_NAME\_dup**() copies *val\_in* by calling **i2d\_X509\_NAME**() and **d2i\_X509\_NAME**().

**X509\_NAME\_set**() makes sure that \**val\_out* contains the same data as *val\_in* after the call, except that it fails if *val\_in* is NULL. If \**val\_out* is the same pointer as *val\_in*, the function succeeds without changing anything. Otherwise, it copies *val\_in* using **X509\_NAME\_dup**(), and in case of success, it frees \**val\_out* and sets it to a pointer to the new object. When the function fails, it never changes anything. In any case, *val\_in* remains valid and may or may not be the same pointer as \**val\_out* after the call.

**d2i\_X509\_NAME\_ENTRY**() and **i2d\_X509\_NAME\_ENTRY**() decode and encode an ASN.1 *RelativeDistinguishedName* structure defined in RFC 5280 section 4.1.2.4.

**X509\_NAME\_ENTRY\_dup**() copies *val\_in* by calling **i2d\_X509\_NAME\_ENTRY**() and **d2i\_X509\_NAME\_ENTRY**().

## RETURN VALUES

**d2i\_X509\_NAME**() and **X509\_NAME\_dup**() return the new *X509\_NAME* object or NULL if an error occurs.

**X509\_NAME\_set**() and **X509\_NAME\_get0\_der**() return 1 on success or 0 if an error occurs.

**d2i\_X509\_NAME\_ENTRY**() and **X509\_NAME\_ENTRY\_dup**() return the new *X509\_NAME\_ENTRY* object or NULL if an error occurs.

**i2d\_X509\_NAME**() and **i2d\_X509\_NAME\_ENTRY**() return the number of bytes successfully encoded or a negative value if an error occurs.

## SEE ALSO

ASN1\_item\_d2i(3), X509\_NAME\_ENTRY\_new(3), X509\_NAME\_new(3), X509\_NAME\_print\_ex(3)

## STANDARDS

RFC 5280: Internet X.509 Public Key Infrastructure Certificate and Certificate Revocation List (CRL) Profile

ITU-T Recommendation X.690, also known as ISO/IEC 8825-1: Information technology - ASN.1 encoding rules: Specification of Basic Encoding Rules (BER), Canonical Encoding Rules (CER) and Distinguished Encoding Rules (DER).

## HISTORY

**X509\_NAME\_dup**() first appeared in SSLeay 0.4.4. **d2i\_X509\_NAME**(), **i2d\_X509\_NAME**(), **d2i\_X509\_NAME\_ENTRY**(), **i2d\_X509\_NAME\_ENTRY**(), and **X509\_NAME\_ENTRY\_dup**() first appeared in SSLeay 0.5.1. **X509\_NAME\_set**() first appeared in SSLeay 0.8.0. These functions have been available since OpenBSD 2.4.

**X509\_NAME\_get0\_der**() first appeared in OpenSSL 1.1.0 and has been available since OpenBSD 6.3.
