ASN1_INTEGER_GET_INT64(3ossl)
β¨ NAME β¨
ASN1_INTEGER_get_uint64, ASN1_INTEGER_set_uint64, ASN1_INTEGER_get_int64, ASN1_INTEGER_get, ASN1_INTEGER_set_int64, ASN1_INTEGER_set, 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, ASN1_ENUMERATED_to_BN β bestie, these are the ASN.1 INTEGER and ENUMERATED utilities π
okay so this whole page lives in the OpenSSL manual, section 3ossl, and it's basically the friend group of little functions that get numbers in and out of ASN1_INTEGER and ASN1_ENUMERATED. it's giving "conversion station" energy, fr fr. π₯
π SYNOPSIS π
#include <openssl/asn1.h>
int ASN1_INTEGER_get_int64(int64_t *pr, const ASN1_INTEGER *a);
long ASN1_INTEGER_get(const ASN1_INTEGER *a);
int ASN1_INTEGER_set_int64(ASN1_INTEGER *a, int64_t r);
int ASN1_INTEGER_set(ASN1_INTEGER *a, long v);
int ASN1_INTEGER_get_uint64(uint64_t *pr, const ASN1_INTEGER *a);
int ASN1_INTEGER_set_uint64(ASN1_INTEGER *a, uint64_t r);
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 *pr, const ASN1_ENUMERATED *a);
long ASN1_ENUMERATED_get(const ASN1_ENUMERATED *a);
int ASN1_ENUMERATED_set_int64(ASN1_ENUMERATED *a, int64_t r);
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 π¦
so the whole vibe here is convert to and from ASN1_INTEGER and ASN1_ENUMERATED structures. that's it, that's the job. π
π the INTEGER getters
ASN1_INTEGER_get_int64()converts anASN1_INTEGERinto anint64_ttype. if it slays (success) it returns1and sets*prto the value ofa. if it fails β and it fails because of an invalid type or because the value is too big to fit into anint64_ttype β it returns0. no cap.ASN1_INTEGER_get_uint64()is similar toASN1_INTEGER_get_int64_t()except it converts to auint64_ttype, and an error is returned if the passed integer is negative. π«ASN1_INTEGER_get()also returns the value ofa, but plot twist: it returns0ifaisNULLand-1on error. and that's ambiguous bestie, because-1is a legitimate value for anASN1_INTEGERπ. new applications should useASN1_INTEGER_get_int64()instead. periodt.
β¨ the INTEGER setters
ASN1_INTEGER_set_int64()sets the value ofASN1_INTEGERato theint64_tvaluer.ASN1_INTEGER_set_uint64()sets the value ofASN1_INTEGERato theuint64_tvaluer.ASN1_INTEGER_set()sets the value ofASN1_INTEGERato thelongvaluev.
πΈ the BIGNUM glow-ups
BN_to_ASN1_INTEGER()convertsBIGNUMbnto anASN1_INTEGER. ifaiisNULL, a newASN1_INTEGERstructure is returned. ifaiis notNULL, then the existing structure will be used instead. reusing structures, we love to see it π«ΆASN1_INTEGER_to_BN()convertsASN1_INTEGERaiinto aBIGNUM. ifbnisNULL, a newBIGNUMstructure is returned. ifbnis notNULL, then the existing structure will be used instead.
π§ and now the ENUMERATED girlies
ASN1_ENUMERATED_get_int64(), ASN1_ENUMERATED_set_int64(), ASN1_ENUMERATED_set(), BN_to_ASN1_ENUMERATED() and ASN1_ENUMERATED_to_BN() behave in an identical way to their ASN1_INTEGER counterparts, except they operate on an ASN1_ENUMERATED value. same energy, different type. π«
ASN1_ENUMERATED_get() returns the value of a in a similar way to ASN1_INTEGER_get(), but it returns 0xffffffffL if the value of a will not fit in a long type. new applications should use ASN1_ENUMERATED_get_int64() instead. πββοΈ
π NOTES π
in general, an ASN1_INTEGER or ASN1_ENUMERATED type can contain an integer of almost arbitrary size, and so it cannot always be represented by a C int64_t type. that's just how it is, bestie.
however β and this is the important part β in many cases (for example version numbers) they represent small integers which can be more easily manipulated if converted to an appropriate C integer type. so like, usually it's fine. usually. π
π BUGS π
the ambiguous return values of ASN1_INTEGER_get() and ASN1_ENUMERATED_get() mean these functions should be avoided if possible. they are retained for compatibility. normally the ambiguous return values are not legitimate values for the fields they represent β but "normally" is doing a lot of heavy lifting in that sentence and that's exactly the problem π«
bestie. if there's an alternative, take the alternative.ASN1_INTEGER_get_int64()andASN1_ENUMERATED_get_int64()are right there. π
πΈ RETURN VALUES πΈ
ASN1_INTEGER_set_int64(),ASN1_INTEGER_set(),ASN1_ENUMERATED_set_int64()andASN1_ENUMERATED_set()return1for success and0for failure. they will only fail if a memory allocation error occurs.ASN1_INTEGER_get_int64()andASN1_ENUMERATED_get_int64()return1for success and0for failure. they will fail if the passed type is incorrect (this will only happen if there is a programming error) or if the value exceeds the range of anint64_ttype.BN_to_ASN1_INTEGER()andBN_to_ASN1_ENUMERATED()return anASN1_INTEGERorASN1_ENUMERATEDstructure respectively, orNULLif an error occurs. they will only fail due to a memory allocation error.ASN1_INTEGER_to_BN()andASN1_ENUMERATED_to_BN()return aBIGNUMstructure orNULLif an error occurs. they can fail if the passed type is incorrect (due to programming error) or due to a memory allocation failure.
π SEE ALSO π
ERR_get_error(3) β go read that one next, it's the one that tells you why things went sideways π΅οΈββοΈ
π HISTORY π
ASN1_INTEGER_set_int64(), ASN1_INTEGER_get_int64(), ASN1_ENUMERATED_set_int64() and ASN1_ENUMERATED_get_int64() were added in OpenSSL 1.1.0. iconic behavior honestly. β
π COPYRIGHT π
Copyright 2015-2026 The OpenSSL Project Authors. All Rights Reserved.
Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy of the License in the file LICENSE in the source distribution or at <https://www.openssl.org/source/license.html>.
and that's the whole page bestie, we ate and left no crumbs π this was ASN1_INTEGER_GET_INT64(3ossl) from OpenSSL version 3.5.9, dated 2026-09-29 β mwah, go forth and convert your integers responsibly π
πβ¨
π¦ where this page comes from
- fedora 43: openssl-devel 1:3.5.9-1.fc43 Β· Apache-2.0
- fedora 43: openssl-devel 1:3.5.9-1.fc43 Β· Apache-2.0
- fedora 44: openssl-devel 1:3.5.9-1.fc44 Β· Apache-2.0
- fedora 44: openssl-devel 1:3.5.9-1.fc44 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms