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

# libressl-ASN1\_get\_object(3)

parse identifier and length octets

## NAME

**ASN1\_get\_object** – parse identifier and length octets

## SYNOPSIS

Crypto Library (libcrypto, -lcrypto)

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

*int*\

**ASN1\_get\_object**(*const unsigned char \*\*ber\_in*, *long \*plength*, *int \*ptag*, *int \*pclass*, *long omax*);

## DESCRIPTION

**ASN1\_get\_object**() parses the identifier and length octets of a BER-encoded value. On function entry, \**ber\_in* is expected to point to the first identifier octet. If the identifier and length octets turn out to be valid, the function advances \**ber\_in* to the first content octet before returning.

If the identifier octets are valid, **ASN1\_get\_object**() stores the tag number in \**ptag* and the class of the tag in \**pclass*. The class is either V\_ASN1\_UNIVERSAL or V\_ASN1\_APPLICATION or V\_ASN1\_CONTEXT\_SPECIFIC or V\_ASN1\_PRIVATE.

If the length octets are valid, too, **ASN1\_get\_object**() stores the number encoded in the length octets in \**plength*. If the length octet indicates the indefinite form, \**plength* is set to 0.

**ASN1\_get\_object**() inspects at most *omax* bytes. If parsing of the length octets remains incomplete after inspecting that number of bytes, parsing fails with ASN1\_R\_HEADER\_TOO\_LONG.

## RETURN VALUES

Bits set in the return value of **ASN1\_get\_object**() have the following meanings:

- 0x80

  An error occurred. One of the ERRORS described below has been set.

- 0x20 = V\_ASN1\_CONSTRUCTED

  The encoding is constructed rather than primitive, and the identifier and length octets are valid.

- 0x01

  The length octet indicates the indefinite form. This bit can only occur if V\_ASN1\_CONSTRUCTED is also set.

Consequently, the following combinations can occur:

- 0x00

  A valid primitive encoding.

- 0x20

  A valid constructed encoding, definite form.

- 0x21

  A valid constructed encoding, indefinite form.

- 0x80

  Either a primitive encoding with a valid tag and definite length, but the content octets won't fit into *omax*, or parsing failed. Use ERR\_GET\_REASON(3) to distinguish the two cases.

- 0xa0

  A constructed encoding with a valid tag and definite length, but the content octets won't fit into *omax*.

The bit combinations 0x01, 0x81, and 0xa1 cannot occur as return values.

## ERRORS

If the bit 0x80 is set in the return value, diagnostics can be retrieved with ERR\_get\_error(3), ERR\_GET\_REASON(3), and ERR\_reason\_error\_string(3):

- ASN1\_R\_HEADER\_TOO\_LONG "header too long"

  Inspecting *omax* bytes was insufficient to finish parsing, the tag number encoded in the identifier octets exceeds INT\_MAX, the number encoded in the length octets exceeds LONG\_MAX, or using the indefinite form for the length octets is attempted even though the encoding is primitive.

  In this case, the return value is exactly 0x80; no other bits are set.

  If the problem occurred while parsing the identifier octets, \**ptag* and \**pclass* remain unchanged. If the problem occurred while parsing the length octets, \**ptag* and \**pclass* are set according to the identifier octets. In both cases, \**ber\_in* and \**plength* remain unchanged.

  The wording of the error message is confusing. On the one hand, the header might be just fine, and the root cause of the problem could be that the chosen *omax* argument was too small. On the other hand, outright BER syntax errors are also reported as ASN1\_R\_HEADER\_TOO\_LONG.

- ASN1\_R\_TOO\_LONG "too long"

  The identifier and length octets are valid, but the content octets won't fit into *omax*. The following have been set as appropriate and can safely be inspected: \*pclass, \*ptag, \*plength, and the bits V\_ASN1\_CONSTRUCTED and 0x01 in the return value. The parse pointer \*ber\_in has been advanced to the first content octet.

  Again, the error message may occasionally sound confusing. The length of the content may be reasonable, and the root cause of the problem could be that the chosen *omax* argument was too small.

## SEE ALSO

ASN1\_item\_d2i(3), ASN1\_item\_new(3), ASN1\_parse\_dump(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.1.2: Identifier octets

- Section 8.1.3: Length octets

## HISTORY

**ASN1\_get\_object**() first appeared in SSLeay 0.5.1 and has been available since OpenBSD 2.4.
