ASN1_GET_OBJECT(3)
π ASN1_GET_OBJECT(3) β parse identifier and length octets π
πΈ NAME πΈ
ASN1_get_object β parse identifier and length octets. yes bestie, that's the whole assignment: identifier octets and length octets, parsed with main character energy π
β¨ SYNOPSIS β¨
#include <openssl/asn1.h>
int
ASN1_get_object(const unsigned char **ber_in, long *plength, int *ptag,
int *pclass, long omax);
π¦ DESCRIPTION π¦
okay so 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. slay, pointer moved, that's literally the glow-up β¨
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 β that's the whole class menu, no substitutions π
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 β zero, bestie, not a typo π«Ά
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. So omax is your byte budget, and if the header doesn't finish inside it, it's giving β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 ifV_ASN1_CONSTRUCTEDis 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 intoomax, or parsing failed. UseERR_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 intoomax.
The bit combinations 0x01, 0x81, and 0xa1 cannot occur as return values β not now, not ever, not on this page π
ββοΈ
π«Ά 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) β those are your little error detectives π
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. it's giving βtoo many problems, one dramatic nameβ π
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 β so those stay exactly where they were, no sneaky updates π
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 chosenomaxargument was too small. On the other hand, outright BER syntax errors are also reported asASN1_R_HEADER_TOO_LONG. not me side-eyeing this error name, but the manual said it first π«
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 β so the pointer did move, the content is just too big for your omax budget, oop π
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. highkey βtoo longβ is doing a lot of emotional labor here π
π¦ SEE ALSO π¦
π 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. a true veteran, no cap πβ¨
Debian Β· July 11, 2021 Β· ASN1_GET_OBJECT(3) β okay bye bestie, that's the footer and this page ate ππ
π¦ where this page comes from
- opensuse-leap 16.0: libressl-devel-doc 4.1.0-bp160.1.1 Β· OpenSSL
- Copyright (c) 2021 Ingo Schwarze <schwarze@openbsd.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms