ASN1_INTEGER_GET(3)
π NAME π
Okay bestie, welcome to the ASN1_INTEGER_GET(3) page β it's from the Library Functions Manual, and it's lowkey the whole ASN.1 INTEGER/ENUMERATED utility squad. The full lineup is ASN1_INTEGER_get_uint64, ASN1_INTEGER_get_int64, ASN1_INTEGER_get, ASN1_INTEGER_set_uint64, ASN1_INTEGER_set_int64, ASN1_INTEGER_set, ASN1_INTEGER_cmp, ASN1_INTEGER_dup, BN_to_ASN1_INTEGER, ASN1_INTEGER_to_BN, ASN1_ENUMERATED_get_int64, ASN1_ENUMERATED_get, ASN1_ENUMERATED_set_int64, ASN1_ENUMERATED_set, BN_to_ASN1_ENUMERATED, and ASN1_ENUMERATED_to_BN β and they're all about ASN.1 INTEGER and ENUMERATED utilities. Periodt. π
β¨ SYNOPSIS β¨
#include <openssl/asn1.h>
int
ASN1_INTEGER_get_uint64(uint64_t *out_val, const ASN1_INTEGER *a);
int
ASN1_INTEGER_get_int64(int64_t *out_val, const ASN1_INTEGER *a);
long
ASN1_INTEGER_get(const ASN1_INTEGER *a);
int
ASN1_INTEGER_set_uint64(ASN1_INTEGER *a, uint64_t v);
int
ASN1_INTEGER_set_int64(ASN1_INTEGER *a, int64_t v);
int
ASN1_INTEGER_set(ASN1_INTEGER *a, long v);
int
ASN1_INTEGER_cmp(const ASN1_INTEGER *a1, const ASN1_INTEGER *a2);
ASN1_INTEGER *
ASN1_INTEGER_dup(const ASN1_INTEGER *a);
ASN1_INTEGER *
BN_to_ASN1_INTEGER(const BIGNUM *bn, ASN1_INTEGER *ai);
BIGNUM *
ASN1_INTEGER_to_BN(const ASN1_INTEGER *ai, BIGNUM *bn);
int
ASN1_ENUMERATED_get_int64(int64_t *out_val, const ASN1_ENUMERATED *a);
long
ASN1_ENUMERATED_get(const ASN1_ENUMERATED *a);
int
ASN1_ENUMERATED_set_int64(ASN1_ENUMERATED *a, int64_t v);
int
ASN1_ENUMERATED_set(ASN1_ENUMERATED *a, long v);
ASN1_ENUMERATED *
BN_to_ASN1_ENUMERATED(const BIGNUM *bn, ASN1_ENUMERATED *ai);
BIGNUM *
ASN1_ENUMERATED_to_BN(const ASN1_ENUMERATED *ai, BIGNUM *bn);
πΈ DESCRIPTION πΈ
These functions convert to and from ASN1_INTEGER and ASN1_ENUMERATED objects. It's giving "glow-up between C types and ASN.1 types," and honestly? Iconic.
ASN1_INTEGER_get_uint64()andASN1_INTEGER_get_int64()store the value ofain*out_valif successful. Slay. β¨- The deprecated function
ASN1_INTEGER_get()convertsato thelongtype. Bestie, it's giving "legacy energy" β tread carefully. ASN1_INTEGER_set_uint64(),ASN1_INTEGER_set_int64(), andASN1_INTEGER_set()set the type ofatoV_ASN1_INTEGERorV_ASN1_NEG_INTEGERdepending on the sign ofv, and set the value ofatov.ASN1_INTEGER_cmp()compares the signed integer numbers represented bya1anda2. It's a whole vibe check between two integers.ASN1_INTEGER_dup()does exactly the same asASN1_STRING_dup(3)without providing any type safety, except that it fails if theASN1_STRING_length(3)ofais 0. Not me pointing out that "no type safety" detail β it's literally right there. πBN_to_ASN1_INTEGER()convertsbnto anASN1_INTEGER. IfaiisNULL, a newASN1_INTEGERobject is returned. Otherwise, the existing objectaiis used instead.ASN1_INTEGER_to_BN()convertsaiinto aBIGNUM. IfbnisNULL, a newBIGNUMobject is returned. Otherwise, the existing objectbnis used instead.ASN1_ENUMERATED_get_int64(),ASN1_ENUMERATED_get(),ASN1_ENUMERATED_set_int64(),ASN1_ENUMERATED_set(),BN_to_ASN1_ENUMERATED(), andASN1_ENUMERATED_to_BN()behave like theirASN1_INTEGERcounterparts except that they operate on anASN1_ENUMERATEDobject. Same energy, different wrapper. π¦
π RETURN VALUES π
ASN1_INTEGER_get_uint64()returns1in case of success or0ifais not of the typeV_ASN1_INTEGERor greater thanUINT64_MAX.ASN1_INTEGER_get_int64()returns1in case of success or0ifais not of the typeV_ASN1_INTEGERorV_ASN1_NEG_INTEGER, less thanINT64_MIN, or greater thanINT64_MAX.ASN1_INTEGER_get()andASN1_ENUMERATED_get()return the converted value,0ifaisNULL, or-1on error, which is ambiguous because-1is a legitimate value for anASN1_INTEGER. Yes, that's the messy part. πASN1_INTEGER_set_uint64(),ASN1_INTEGER_set_int64(),ASN1_INTEGER_set(),ASN1_ENUMERATED_set_int64(), andASN1_ENUMERATED_set()return1for success or0for failure. They only fail if a memory allocation error occurs.ASN1_INTEGER_cmp()returns a value greater than, equal to, or less than0if the signed integer number represented bya1is greater than, equal to, or less than the signed integer number represented bya2, respectively.ASN1_INTEGER_dup()returns a pointer to a newly allocatedASN1_STRINGstructure orNULLifais aNULLpointer, if the length ofais0, or if memory allocation fails.BN_to_ASN1_INTEGER()andBN_to_ASN1_ENUMERATED()return anASN1_INTEGERorASN1_ENUMERATEDobject, respectively, orNULLif an error occurs. They only fail due to memory allocation errors.ASN1_INTEGER_to_BN()andASN1_ENUMERATED_to_BN()return aBIGNUMobject orNULLif an error occurs. They can fail if the passed type is incorrect (due to a programming error) or due to memory allocation failures.
π«Ά SEE ALSO π«Ά
π HISTORY π
ASN1_INTEGER_set()first appeared in SSLeay0.5.1.ASN1_INTEGER_get(),BN_to_ASN1_INTEGER(), andASN1_INTEGER_to_BN()first appeared in SSLeay0.6.0.ASN1_INTEGER_cmp()andASN1_INTEGER_dup()first appeared in SSLeay0.6.5.- These functions have been available since OpenBSD
2.3. ASN1_ENUMERATED_get(),ASN1_ENUMERATED_set(),BN_to_ASN1_ENUMERATED(), andASN1_ENUMERATED_to_BN()first appeared in OpenSSL0.9.2band have been available since OpenBSD2.6.ASN1_INTEGER_get_uint64(),ASN1_INTEGER_get_int64(),ASN1_INTEGER_set_uint64(),ASN1_INTEGER_set_int64(),ASN1_ENUMERATED_get_int64(), andASN1_ENUMERATED_set_int64()first appeared in OpenSSL1.1.0and have been available since OpenBSD7.2.
β CAVEATS β
In general anASN1_INTEGERorASN1_ENUMERATEDtype can contain an integer of almost arbitrary size and so cannot always be represented by a Clongtype. The ambiguous return values ofASN1_INTEGER_get()andASN1_ENUMERATED_get()imply that these functions should be avoided if possible.
Like, no cap β big ASN.1 integers can absolutely humble a plain long, and those ambiguous return values are not the moment. Avoid if you can, bestie. π
π BUGS π
ASN1_INTEGER_cmp(), ASN1_INTEGER_dup(), and ASN1_INTEGER_to_BN() do not check whether their arguments are really of the type V_ASN1_INTEGER or V_ASN1_NEG_INTEGER. They may report success even if their arguments are of a wrong type. Consequently, even in case of success, the return value of ASN1_INTEGER_dup() is not guaranteed to be of the type V_ASN1_INTEGER or V_ASN1_NEG_INTEGER either.
Similarly, ASN1_ENUMERATED_to_BN() does not check whether its argument is really of the type V_ASN1_ENUMERATED or V_ASN1_NEG_ENUMERATED and may report success even if the argument is of a wrong type.
π That's the whole page, bestie β Debian build, dated May 22, 2023. Now go forth and slay those ASN.1 conversions. πβ¨
π¦ where this page comes from
- opensuse-leap 16.0: libressl-devel-doc 4.1.0-bp160.1.1 Β· OpenSSL
- Copyright (c) 2018, 2021, 2022 Ingo Schwarze <schwarze@openbsd.org>
- Copyright (c) 2015 The OpenSSL Project. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms