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

# libressl-X509\_ATTRIBUTE\_set1\_object(3)

modify an X.501 Attribute

## NAME

**X509\_ATTRIBUTE\_set1\_object**, **X509\_ATTRIBUTE\_set1\_data**, **X509\_ATTRIBUTE\_create\_by\_OBJ**, **X509\_ATTRIBUTE\_create\_by\_NID**, **X509\_ATTRIBUTE\_create\_by\_txt** – modify an X.501 Attribute

## SYNOPSIS

Crypto Library (libcrypto, -lcrypto)

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

*int*\

**X509\_ATTRIBUTE\_set1\_object**(*X509\_ATTRIBUTE \*attr*, *const ASN1\_OBJECT \*obj*);

*int*\

**X509\_ATTRIBUTE\_set1\_data**(*X509\_ATTRIBUTE \*attr*, *int type*, *const void \*data*, *int len*);

*X509\_ATTRIBUTE* *\**\

**X509\_ATTRIBUTE\_create\_by\_OBJ**(*X509\_ATTRIBUTE \*\*pattr*, *const ASN1\_OBJECT \*obj*, *int type*, *const void \*data*, *int len*);

*X509\_ATTRIBUTE* *\**\

**X509\_ATTRIBUTE\_create\_by\_NID**(*X509\_ATTRIBUTE \*\*pattr*, *int nid*, *int type*, *const void \*data*, *int len*);

*X509\_ATTRIBUTE* *\**\

**X509\_ATTRIBUTE\_create\_by\_txt**(*X509\_ATTRIBUTE \*\*pattr*, *const char \*name*, *int type*, *const unsigned char \*data*, *int len*);

## DESCRIPTION

**X509\_ATTRIBUTE\_set1\_object**() sets the type of *attr* to *obj*. If *obj* is dynamically allocated, a deep copy is created. If the type of *attr* was already set, the old type is freed as far as it was dynamically allocated. After calling this function, *attr* may be in an inconsistent state because its values may not agree with the new attribute type.

**X509\_ATTRIBUTE\_set1\_data**() sets *attr* to be multi-valued and initializes its set of values to contain a single new ASN.1 ANY object representing the *data*.

The interpretation of the *data* depends on the values of the *type* and *len* arguments; there are four different cases.

If the *type* argument has the bit MBSTRING\_FLAG set, *data* is expected to point to a multibyte character string that is *len* bytes long and uses the encoding specified by the *type* argument, and it is expected that an attribute type was already assigned to *attr*, for example by calling **X509\_ATTRIBUTE\_set1\_object**() before calling **X509\_ATTRIBUTE\_set1\_data**(). In this case, an appropriate ASN.1 multibyte string type is chosen and a new object of that type is allocated and populated to represent the *data* by calling ASN1\_STRING\_set\_by\_NID(3). The type of that new ASN.1 string object is subsequently used instead of the *type* argument.

If the *type* argument does not have the bit MBSTRING\_FLAG set and the *len*, *argument* is not -1, the *type* argument is expected to be one of the types documented in ASN1\_STRING\_new(3) and *data* is expected to point to a buffer of *len* bytes. In this case, a new object is allocated with ASN1\_STRING\_type\_new(3) and populated with ASN1\_STRING\_set(3).

If the *type* argument does not have the bit MBSTRING\_FLAG set and the *len*, *argument* is -1, *data* is expected to point to an object of the given *type* rather than to a buffer. In this case, a deep copy of the existing object into the new ASN.1 ANY object is performed with ASN1\_TYPE\_set1(3).

If the *type* argument is 0, the *data* and *len* arguments are ignored and the set of values is left empty instead of adding a single ASN.1 ANY object to it. This violates section 8.2 of the X.501 standard, which requires every attribute to contain at least one value, but some attribute types used by the library use empty sets of values anyway.

**X509\_ATTRIBUTE\_create\_by\_OBJ**() sets the type of \*\**attr* to *obj* using **X509\_ATTRIBUTE\_set1\_object**() and copies the *data* into it using **X509\_ATTRIBUTE\_set1\_data**(). If *attr* or \**attr* is NULL, a new *X509\_ATTRIBUTE* object is allocated, populated, and returned.

**X509\_ATTRIBUTE\_create\_by\_NID**() is a wrapper around **X509\_ATTRIBUTE\_create\_by\_OBJ**() that obtains the required *obj* argument by calling OBJ\_nid2obj(3) on the *nid* argument.

**X509\_ATTRIBUTE\_create\_by\_txt**() is a similar wrapper that obtains *obj* by calling OBJ\_txt2obj(3) with the arguments *name* and 0, which means that long names, short names, and numerical OID strings are all acceptable.

## RETURN VALUES

**X509\_ATTRIBUTE\_set1\_object**() returns 1 if successful or 0 if *attr* or *obj* is NULL or if memory allocation fails.

**X509\_ATTRIBUTE\_set1\_data**() returns 1 if successful or 0 if *attr* is NULL or if ASN1\_STRING\_set\_by\_NID(3), ASN1\_STRING\_set(3), ASN1\_TYPE\_set1(3), or memory allocation fails.

**X509\_ATTRIBUTE\_create\_by\_OBJ**(), **X509\_ATTRIBUTE\_create\_by\_NID**(), and **X509\_ATTRIBUTE\_create\_by\_txt**() return a pointer to the changed or new object or NULL if obtaining *obj*, allocating memory, or copying fails.

## SEE ALSO

ASN1\_OBJECT\_new(3), ASN1\_STRING\_new(3), ASN1\_STRING\_set(3), ASN1\_STRING\_set\_by\_NID(3), ASN1\_TYPE\_new(3), OBJ\_nid2obj(3), X509\_ATTRIBUTE\_get0\_object(3), X509\_ATTRIBUTE\_new(3)

## HISTORY

These functions first appeared in OpenSSL 0.9.5 and have been available since OpenBSD 2.7.

## BUGS

If *attr* already contains one or more values, **X509\_ATTRIBUTE\_set1\_data**(), **X509\_ATTRIBUTE\_create\_by\_OBJ**(), **X509\_ATTRIBUTE\_create\_by\_NID**(), and **X509\_ATTRIBUTE\_create\_by\_txt**() silently overwrite the pointers to the old values and leak the memory used for them.
