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

# libressl-ASN1\_TYPE\_get(3)

ASN.1 objects of arbitrary type

## NAME

**ASN1\_TYPE\_new**, **ASN1\_TYPE\_free**, **ASN1\_TYPE\_get**, **ASN1\_TYPE\_set**, **ASN1\_TYPE\_set1**, **ASN1\_TYPE\_set\_octetstring**, **ASN1\_TYPE\_get\_octetstring**, **ASN1\_TYPE\_set\_int\_octetstring**, **ASN1\_TYPE\_get\_int\_octetstring**, **ASN1\_TYPE\_cmp** – ASN.1 objects of arbitrary type

## SYNOPSIS

Crypto Library (libcrypto, -lcrypto)

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

*ASN1\_TYPE* *\**\

**ASN1\_TYPE\_new**(*void*);

*void*\

**ASN1\_TYPE\_free**(*ASN1\_TYPE \*a*);

*int*\

**ASN1\_TYPE\_get**(*const ASN1\_TYPE \*a*);

*void*\

**ASN1\_TYPE\_set**(*ASN1\_TYPE \*a*, *int type*, *void \*value*);

*int*\

**ASN1\_TYPE\_set1**(*ASN1\_TYPE \*a*, *int type*, *const void \*value*);

*int*\

**ASN1\_TYPE\_set\_octetstring**(*ASN1\_TYPE \*a*, *const unsigned char \*data*, *int len*);

*int*\

**ASN1\_TYPE\_get\_octetstring**(*const ASN1\_TYPE \*a*, *unsigned char \*buffer*, *int buflen*);

*int*\

**ASN1\_TYPE\_set\_int\_octetstring**(*ASN1\_TYPE \*a*, *long num*, *const unsigned char \*data*, *int len*);

*int*\

**ASN1\_TYPE\_get\_int\_octetstring**(*const ASN1\_TYPE \*a*, *long \*num*, *unsigned char \*buffer*, *int buflen*);

*int*\

**ASN1\_TYPE\_cmp**(*const ASN1\_TYPE \*a*, *const ASN1\_TYPE \*b*);

## DESCRIPTION

The *ASN1\_TYPE* data type and the V\_ASN1\_ANY type identifier constant represent the ASN.1 ANY type. An *ASN1\_TYPE* object can store an ASN.1 value of arbitrary type, including constructed types such as a SEQUENCE. It also remembers internally which type it currently holds.

**ASN1\_TYPE\_new**() allocates and initializes an empty *ASN1\_TYPE* object of type V\_ASN1\_UNDEF.

**ASN1\_TYPE\_free**() frees *a* including the value stored in it, if any. If *a* is a NULL pointer, no action occurs.

**ASN1\_TYPE\_get**() returns the type currently held by *a*, represented by one of the V\_ASN1\_\* constants defined in ⟨openssl/asn1.h⟩.

**ASN1\_TYPE\_set**() frees the value contained in *a*, if any, and sets the *value* and *type* now held in *a*. This function uses the pointer *value* internally so it must **not** be freed up after the call.

**ASN1\_TYPE\_set1**() sets the type held by *a* to *type* and its value to a copy of *value*. If copying succeeds, the previous value that was contained in *a* is freed. If copying fails, *a* remains unchanged.

The type and meaning of the *value* argument of **ASN1\_TYPE\_set**() and **ASN1\_TYPE\_set1**() is determined by the *type* argument. If *type* is V\_ASN1\_NULL, *value* is ignored. If *type* is V\_ASN1\_BOOLEAN, then the boolean is set to TRUE if *value* is not NULL. If *type* is V\_ASN1\_OBJECT, then *value* is an *ASN1\_OBJECT* structure. Otherwise *type* is an *ASN1\_STRING* structure. If *type* corresponds to a primitive type or a string type, then the contents of the *ASN1\_STRING* contains the content octets of the type. If *type* corresponds to a constructed type or a tagged type (V\_ASN1\_SEQUENCE, V\_ASN1\_SET, or V\_ASN1\_OTHER), then the *ASN1\_STRING* contains the entire ASN.1 encoding verbatim, including tag and length octets.

**ASN1\_TYPE\_set\_octetstring**() allocates a new *ASN1\_OCTET\_STRING* object, copies *len* bytes of *data* into it using ASN1\_STRING\_set(3), and replaces the value of *a* with it by calling **ASN1\_TYPE\_set**() with a type of V\_ASN1\_OCTET\_STRING.

**ASN1\_TYPE\_get\_octetstring**() copies the contents of the *ASN1\_OCTET\_STRING* object contained in *a*, but not more than *buflen* bytes, into the *buffer* provided by the caller.

**ASN1\_TYPE\_set\_int\_octetstring**() frees the value contained in *a*, if any, sets its type to V\_ASN1\_SEQUENCE, and sets its value to a two-element ASN.1 sequence consisting of an ASN.1 INTEGER object with the value *num* and an ASN.1 OCTET STRING object containing a copy of the *len* bytes pointed to by *data*.

**ASN1\_TYPE\_get\_int\_octetstring**() copies the integer value from the first element of the ASN.1 sequence *a* to \**num* unless *num* is a NULL pointer and copies the octet string value from the second element, but not more than *buflen* bytes, into the *buffer* provided by the caller unless *buffer* is a NULL pointer.

**ASN1\_TYPE\_cmp**() checks that *a* and *b* hold the same type, the same value, and are encoded in the same way.

If the types agree and the values have the same meaning but are encoded differently, they are considered different. For example, a boolean value is represented using a single content octet. Under BER, any non-zero octet represents the TRUE value, but **ASN1\_TYPE\_cmp**() will only report a match if the content octet is the same.

If either or both of the arguments passed to **ASN1\_TYPE\_cmp**() is NULL, the result is a mismatch. Technically, if both arguments are NULL, the two types could be absent OPTIONAL fields and so should match, however passing NULL values could also indicate a programming error (for example an unparsable type which returns NULL) for types which do **not** match. So applications should handle the case of two absent values separately.

## RETURN VALUES

**ASN1\_TYPE\_new**() returns the new *ASN1\_TYPE* object or NULL if an error occurs.

**ASN1\_TYPE\_get**() returns the type currently held by *a* or 0 if an error occurs. The latter can happen if *a* does not contain a value even though its type is not V\_ASN1\_NULL. For example, it will always happen for empty objects newly constructed with **ASN1\_TYPE\_new**().

**ASN1\_TYPE\_set1**(), **ASN1\_TYPE\_set\_octetstring**(), and **ASN1\_TYPE\_set\_int\_octetstring**() return 1 on success or 0 on failure.

**ASN1\_TYPE\_get\_octetstring**() returns the number of data bytes contained in the *ASN1\_OCTET\_STRING* object contained in *a* or -1 if *a* is not of the type V\_ASN1\_OCTET\_STRING or does not contain any object. If the return value is greater than the *buflen* argument, the content was truncated when copied to the *buffer*.

**ASN1\_TYPE\_get\_int\_octetstring**() returns the number of data bytes contained in the *ASN1\_OCTET\_STRING* object that is the second element of the ASN.1 sequence *a* or -1 if *a* is not of the type V\_ASN1\_SEQUENCE or if decoding fails. If the return value is greater than the *buflen* argument, the content was truncated when copied to the *buffer*.

**ASN1\_TYPE\_cmp**() returns 0 for a match or non-zero for a mismatch.

## SEE ALSO

ASN1\_generate\_nconf(3), ASN1\_get\_object(3), ASN1\_item\_free(3), ASN1\_OBJECT\_new(3), ASN1\_parse\_dump(3), ASN1\_put\_object(3), ASN1\_STRING\_dup(3), ASN1\_STRING\_new(3), [crypto(3)](/crypto/3.md), d2i\_ASN1\_NULL(3), d2i\_ASN1\_SEQUENCE\_ANY(3), d2i\_ASN1\_TYPE(3), OBJ\_dup(3)

## HISTORY

**ASN1\_TYPE\_new**() and **ASN1\_TYPE\_free**() first appeared in SSLeay 0.5.1, **ASN1\_TYPE\_get**() and **ASN1\_TYPE\_set**() in SSLeay 0.8.0, and **ASN1\_TYPE\_set\_octetstring**(), **ASN1\_TYPE\_get\_octetstring**(), **ASN1\_TYPE\_set\_int\_octetstring**(), and **ASN1\_TYPE\_get\_int\_octetstring**() in SSLeay 0.9.0. These functions have been available since OpenBSD 2.4.

**ASN1\_TYPE\_set1**() first appeared in OpenSSL 0.9.8h and has been available since OpenBSD 4.5.

**ASN1\_TYPE\_cmp**() first appeared in OpenSSL 0.9.8zd, 1.0.0p, and 1.0.1k and has been available since OpenBSD 4.9.
