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

# libressl-ASN1\_item\_new(3)

generic ASN.1 value constructor and destructor

## NAME

**ASN1\_item\_new**, **ASN1\_item\_free** – generic ASN.1 value constructor and destructor

## SYNOPSIS

Crypto Library (libcrypto, -lcrypto)

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

*ASN1\_VALUE* *\**\

**ASN1\_item\_new**(*const ASN1\_ITEM \*it*);

*void*\

**ASN1\_item\_free**(*ASN1\_VALUE \*val\_in*, *const ASN1\_ITEM \*it*);

## DESCRIPTION

**ASN1\_item\_new**() allocates and initializes an empty ASN.1 value of the type described by the global static object *it*.

If the item type described by *it* is reference counted, **ASN1\_item\_free**() decrements the reference count of *val\_in*. Otherwise, or if the reference count reaches 0, **ASN1\_item\_free**() frees *val\_in*, assuming that it is of the type described by *it*. If the true type of *val\_in* fails to match the specified *it*, buffer overflows and segmentation faults are likely to occur. It is not possible to recover the type of an *ASN1\_VALUE* object by inspecting it; the type always needs to be remembered separately.

*ASN1\_VALUE* is an incomplete type, and pointers to it always require casting to the correct complete type before they can be dereferenced. For all practical purposes, a pointer to *ASN1\_VALUE* is equivalent to a *void* pointer.

Depending on *it*, there are more than 150 different types that **ASN1\_item\_new**() may return. Most of them are pointers to structures or pointers to arrays of structures, but there are a few exceptions, for example: If *it* is ASN1\_NULL\_it, **ASN1\_item\_new**() returns a specific invalid pointer representing the unique *ASN1\_NULL* object. If *it* is LONG\_it, **ASN1\_item\_new**() does not return a pointer at all, but a *long* value cast to *ASN1\_VALUE* *\**.

## RETURN VALUES

The **ASN1\_item\_new**() function returns the new *ASN1\_VALUE* object if successful; otherwise NULL is returned and an error code can be retrieved with ERR\_get\_error(3).

## SEE ALSO

ASN1\_get\_object(3), ASN1\_item\_d2i(3), ASN1\_item\_digest(3), ASN1\_item\_pack(3), ASN1\_item\_sign(3), ASN1\_item\_verify(3), ASN1\_NULL\_new(3), ASN1\_TYPE\_new(3), d2i\_ASN1\_NULL(3), OBJ\_nid2obj(3)

## HISTORY

**ASN1\_item\_new**() and **ASN1\_item\_free**() first appeared in OpenSSL 0.9.7 and have been available since OpenBSD 3.2.

## BUGS

The *ASN1\_VALUE* type compromises type safety and invites programming mistakes that will typically have severe consequences.
