ASN1_INTEGER_GET_INT64(3ossl)

πŸ“¦
version 15.1 Β· 3 versions
, in freebsd 15.1

πŸ’… ASN1_INTEGER_GET_INT64(3ossl) β€” the OpenSSL integer/enumerated glow-up page

okay bestie, so this is from the 3ossl manual, and it's literally all about converting between ASN1_INTEGER / ASN1_ENUMERATED and the regular C number types you actually know and love. no cap, it's giving "small numbers deserve nice homes" πŸŽ€

✨ 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 these functions are the little go-betweens for ASN1_INTEGER and ASN1_ENUMERATED structs. they convert in, they convert out, they slay πŸ’…

  • ASN1_INTEGER_get_int64() β€” takes an ASN1_INTEGER and turns it into an int64_t type. if it works you get 1 back and *pr gets set to the value of a. if it fails (invalid type, or the value is too big to fit into an int64_t) you get 0. simple as that 🫢
  • ASN1_INTEGER_get_uint64() β€” basically the same vibe as ASN1_INTEGER_get_int64_t(), except it converts to a uint64_t, and you get an error if the integer you passed in is negative. no sneaky negatives allowed πŸ™ˆ
  • ASN1_INTEGER_get() β€” also hands you the value of a, BUT it returns 0 if a is NULL and -1 on error. and yeah… that's ambiguous, because -1 is a legit value for an ASN1_INTEGER 😭 new applications should use ASN1_INTEGER_get_int64() instead. periodt.
  • ASN1_INTEGER_set_int64() β€” sets the value of the ASN1_INTEGER a to the int64_t value r.
  • ASN1_INTEGER_set_uint64() β€” sets the value of ASN1_INTEGER a to the uint64_t value r.
  • ASN1_INTEGER_set() β€” sets the value of ASN1_INTEGER a to the long value v.
  • BN_to_ASN1_INTEGER() β€” converts the BIGNUM bn into an ASN1_INTEGER. if ai is NULL, a brand new ASN1_INTEGER structure is returned ✨. if ai is not NULL, the existing structure gets used instead (reuse era πŸ‘‘).
  • ASN1_INTEGER_to_BN() β€” converts the ASN1_INTEGER ai into a BIGNUM. if bn is NULL, a new BIGNUM structure is returned. if bn is not NULL, the existing structure is used instead.
  • 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 struct πŸ’–
  • 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, iykyk.

🌸 NOTES 🌸

in general, an ASN1_INTEGER or ASN1_ENUMERATED type can contain an integer of almost arbitrary size, so it can't always be represented by a C int64_t type. that's just how it is bestie. BUT β€” in many cases (for example version numbers), they represent small integers, and those are way easier to manipulate if you convert them to an appropriate C integer type. so like, vibe check the size first 😌


πŸ’€ BUGS πŸ’€

the ambiguous return values of ASN1_INTEGER_get() and ASN1_ENUMERATED_get() mean these functions should be avoided if possible. they're retained for compatibility only. normally the ambiguous return values are not legitimate values for the fields they represent β€” but "normally" is doing a lot of work there, so like… be careful πŸ₯΄


πŸ”₯ RETURN VALUES πŸ”₯

  • ASN1_INTEGER_set_int64(), ASN1_INTEGER_set(), ASN1_ENUMERATED_set_int64() and ASN1_ENUMERATED_set() β€” return 1 for success and 0 for failure. they will only fail if a memory allocation error occurs. that's it, that's the whole drama.
  • ASN1_INTEGER_get_int64() and ASN1_ENUMERATED_get_int64() β€” return 1 for success and 0 for failure. they'll fail if the passed type is incorrect (which only happens if there's a programming error) or if the value exceeds the range of an int64_t type. so… overflow is not it 🫠
  • BN_to_ASN1_INTEGER() and BN_to_ASN1_ENUMERATED() β€” return an ASN1_INTEGER or ASN1_ENUMERATED structure respectively, or NULL if an error occurs. they will only fail due to a memory allocation error.
  • ASN1_INTEGER_to_BN() and ASN1_ENUMERATED_to_BN() β€” return a BIGNUM structure of NULL if an error occurs. they can fail if the passed type is incorrect (due to programming error) or due to a memory allocation failure. yes, the page literally says "structure of NULL" β€” we don't fix, we report πŸ“‹πŸ’…

⭐ SEE ALSO ⭐

ERR_get_error(3)


🧚 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. so they're not new new, but they're still iconic ✨


Copyright 2015-2020 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 in the file LICENSE in the source distribution or at <https://www.openssl.org/source/license.html>.


okay that's the whole page bestie, go forth and convert responsibly πŸ«ΆπŸ’–

mwah πŸ’‹ β€” this was 3.5.6, dated 2026-04-07, and the manual is ASN1_INTEGER_GET_INT64(3ossl). catch you in the next manpage, love u, bye πŸŽ€

πŸ“¦ where this page comes from