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

# libressl-X509\_NAME\_add\_entry\_by\_txt(3)

X509\_NAME modification functions

## NAME

**X509\_NAME\_add\_entry\_by\_txt**, **X509\_NAME\_add\_entry\_by\_OBJ**, **X509\_NAME\_add\_entry\_by\_NID**, **X509\_NAME\_add\_entry**, **X509\_NAME\_delete\_entry** – X509\_NAME modification functions

## SYNOPSIS

Crypto Library (libcrypto, -lcrypto)

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

*int*\

**X509\_NAME\_add\_entry\_by\_txt**(*X509\_NAME \*name*, *const char \*field*, *int type*, *const unsigned char \*bytes*, *int len*, *int loc*, *int set*);

*int*\

**X509\_NAME\_add\_entry\_by\_OBJ**(*X509\_NAME \*name*, *const ASN1\_OBJECT \*obj*, *int type*, *const unsigned char \*bytes*, *int len*, *int loc*, *int set*);

*int*\

**X509\_NAME\_add\_entry\_by\_NID**(*X509\_NAME \*name*, *int nid*, *int type*, *const unsigned char \*bytes*, *int len*, *int loc*, *int set*);

*int*\

**X509\_NAME\_add\_entry**(*X509\_NAME \*name*, *const X509\_NAME\_ENTRY \*ne*, *int loc*, *int set*);

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

**X509\_NAME\_delete\_entry**(*X509\_NAME \*name*, *int loc*);

## DESCRIPTION

**X509\_NAME\_add\_entry\_by\_txt**(), **X509\_NAME\_add\_entry\_by\_OBJ**(), and **X509\_NAME\_add\_entry\_by\_NID**() add a field whose name is defined by a string *field*, an object *obj* or a NID *nid*, respectively. The field value to be added is in *bytes* of length *len*. If *len* is -1 then the field length is calculated internally using **strlen**(*bytes*).

The type of field is determined by *type* which can either be a definition of the type of *bytes* (such as MBSTRING\_ASC) or a standard ASN.1 type (such as V\_ASN1\_IA5STRING). The new entry is added to a position determined by *loc* and *set*.

**X509\_NAME\_add\_entry**() adds a copy of an *X509\_NAME\_ENTRY* structure *ne* to *name*. The new entry is added to a position determined by *loc* and *set*. Since a copy of *ne* is added, *ne* must be freed up after the call.

**X509\_NAME\_delete\_entry**() deletes an entry from *name* at position *loc*. The deleted entry is returned and must be freed up.

The use of string types such as MBSTRING\_ASC or MBSTRING\_UTF8 is strongly recommended for the *type* parameter. This allows the internal code to correctly determine the type of the field and to apply length checks according to the relevant standards.

If instead an ASN.1 type is used, no checks are performed and the supplied data in *bytes* is used directly.

In **X509\_NAME\_add\_entry\_by\_txt**() the *field* string represents the field name using **OBJ\_txt2obj**(*field*, *0*).

The *loc* and *set* parameters determine where a new entry should be added. For almost all applications, *loc* can be set to -1 and *set* to 0. This adds a new entry to the end of *name* as a single valued *RelativeDistinguishedName* (RDN).

*loc* actually determines the index where the new entry is inserted: if it is -1 it is appended.

*set* determines how the new type is added. If it is zero, a new RDN is created.

If *set* is -1 or 1, it is added to the previous or next RDN structure respectively. This will then be a multivalued RDN: since multivalue RDNs are very seldom used, *set* is almost always set to zero.

## RETURN VALUES

**X509\_NAME\_add\_entry\_by\_txt**(), **X509\_NAME\_add\_entry\_by\_OBJ**(), **X509\_NAME\_add\_entry\_by\_NID**(), and **X509\_NAME\_add\_entry**() return 1 for success or 0 if an error occurred.

**X509\_NAME\_delete\_entry**() returns either the deleted *X509\_NAME\_ENTRY* structure or NULL if an error occurred.

In some cases of failure, the reason can be determined with ERR\_get\_error(3).

## EXAMPLES

Create an *X509\_NAME* structure:

```
C=UK, O=Disorganized Organization, CN=Joe Bloggs
X509_NAME *nm;
nm = X509_NAME_new();
if (nm == NULL)
	/* Some error */
if (!X509_NAME_add_entry_by_txt(nm, "C", MBSTRING_ASC,
		"UK", -1, -1, 0))
	/* Error */
if (!X509_NAME_add_entry_by_txt(nm, "O", MBSTRING_ASC,
		"Disorganized Organization", -1, -1, 0))
	/* Error */
if (!X509_NAME_add_entry_by_txt(nm, "CN", MBSTRING_ASC,
		"Joe Bloggs", -1, -1, 0))
	/* Error */
```

## SEE ALSO

d2i\_X509\_NAME(3), X509\_NAME\_ENTRY\_get\_object(3), X509\_NAME\_get\_index\_by\_NID(3), X509\_NAME\_new(3)

## HISTORY

**X509\_NAME\_add\_entry**() and **X509\_NAME\_delete\_entry**() first appeared in SSLeay 0.8.0 and have been available since OpenBSD 2.4.

**X509\_NAME\_add\_entry\_by\_txt**(), **X509\_NAME\_add\_entry\_by\_OBJ**(), and **X509\_NAME\_add\_entry\_by\_NID**() first appeared in OpenSSL 0.9.5 and have been available since OpenBSD 2.7.
