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

# libressl-d2i\_ASN1\_OBJECT(3)

decode and encode ASN.1 object identifiers

## NAME

**d2i\_ASN1\_OBJECT**, **i2d\_ASN1\_OBJECT**, **OBJ\_get0\_data**, **OBJ\_length** – decode and encode ASN.1 object identifiers

## SYNOPSIS

Crypto Library (libcrypto, -lcrypto)

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

*ASN1\_OBJECT* *\**\

**d2i\_ASN1\_OBJECT**(*ASN1\_OBJECT \*\*val\_out*, *const unsigned char \*\*der\_in*, *long length*);

*int*\

**i2d\_ASN1\_OBJECT**(*const ASN1\_OBJECT \*val\_in*, *unsigned char \*\*der\_out*);

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

*const* *unsigned* *char* *\**\

**OBJ\_get0\_data**(*const ASN1\_OBJECT \*val\_in*);

*size\_t*\

**OBJ\_length**(*const ASN1\_OBJECT \*val\_in*);

## DESCRIPTION

These functions decode and encode ASN.1 object identifiers. For details about the semantics, examples, caveats, and bugs, see ASN1\_item\_d2i(3).

The LibreSSL implementation of **d2i\_ASN1\_OBJECT**() always calls ASN1\_OBJECT\_free(3) if an existing object is passed in via *val\_out* and it always creates a new object from scratch. Other implementations may attempt to reuse an existing object, which is fragile and prone to bugs. Consequently, always passing NULL for the *val\_out* argument is recommended.

The objects returned from **d2i\_ASN1\_OBJECT**() and the data contained in them are always marked as dynamically allocated, so when they are no longer needed, ASN1\_OBJECT\_free(3) can be called on them.

**i2d\_ASN1\_OBJECT**() encodes the object identifier pointed to by *val\_in* into DER format. **OBJ\_get0\_data**() and **OBJ\_length**() only deal with the content octets of that DER encoding, without taking the identifier and length octets into account.

## RETURN VALUES

**d2i\_ASN1\_OBJECT**() returns a pointer to the new *ASN1\_OBJECT* object or NULL if an error occurs. With other implementations, it might return a pointer to the reused *ASN1\_OBJECT*.

**i2d\_ASN1\_OBJECT**() returns the number of octets successfully encoded or a value \<= 0 if an error occurs.

**OBJ\_get0\_data**() returns an internal pointer to the first content octet of the DER encoding of *val\_in*. The other content octets follow the returned pointer contiguously. **OBJ\_length**() returns the number of content octets contained in the DER encoding of *val\_in*. This number is always smaller than the total length of the encoding returned by ASN1\_object\_size(3).

If *val\_in* is a NULL pointer or points to an empty object, for example one freshly created with ASN1\_OBJECT\_new(3), **OBJ\_get0\_data**() returns NULL and **OBJ\_length**() returns zero.

## SEE ALSO

a2d\_ASN1\_OBJECT(3), ASN1\_item\_d2i(3), ASN1\_OBJECT\_new(3), ASN1\_put\_object(3), OBJ\_nid2obj(3)

## STANDARDS

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), section 8.19: Encoding of an object identifier value

## HISTORY

**d2i\_ASN1\_OBJECT**() and **i2d\_ASN1\_OBJECT**() first appeared in SSLeay 0.5.1 and have been available since OpenBSD 2.4.

**OBJ\_get0\_data**() and **OBJ\_length**() first appeared in OpenSSL 1.1.0 and have been available since OpenBSD 7.1.

## CAVEATS

**d2i\_ASN1\_OBJECT**() never sets the long and short names of the object, not even if the object identifier matches one that is built into the library. To find the names of an object identifier parsed from DER or BER input, call OBJ\_obj2nid(3) on the returned object, and then OBJ\_nid2sn(3) and OBJ\_nid2ln(3) on the result.

Calling **OBJ\_get0\_data**() and then accessing memory in front of the returned pointer results in undefined behaviour. In particular, it is not possible to find the identifier or length octets in that way; use ASN1\_put\_object(3) or **i2d\_ASN1\_OBJECT**() instead.
