1e71b7053SJung-uk Kim=pod 2e71b7053SJung-uk Kim 3e71b7053SJung-uk Kim=head1 NAME 4e71b7053SJung-uk Kim 5e71b7053SJung-uk KimASN1_INTEGER_get_uint64, ASN1_INTEGER_set_uint64, 6e71b7053SJung-uk KimASN1_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 7e71b7053SJung-uk Kim- ASN.1 INTEGER and ENUMERATED utilities 8e71b7053SJung-uk Kim 9e71b7053SJung-uk Kim=head1 SYNOPSIS 10e71b7053SJung-uk Kim 11e71b7053SJung-uk Kim #include <openssl/asn1.h> 12e71b7053SJung-uk Kim 13e71b7053SJung-uk Kim int ASN1_INTEGER_get_int64(int64_t *pr, const ASN1_INTEGER *a); 14e71b7053SJung-uk Kim long ASN1_INTEGER_get(const ASN1_INTEGER *a); 15e71b7053SJung-uk Kim 16e71b7053SJung-uk Kim int ASN1_INTEGER_set_int64(ASN1_INTEGER *a, int64_t r); 17*b077aed3SPierre Pronchery int ASN1_INTEGER_set(ASN1_INTEGER *a, long v); 18e71b7053SJung-uk Kim 19e71b7053SJung-uk Kim int ASN1_INTEGER_get_uint64(uint64_t *pr, const ASN1_INTEGER *a); 20e71b7053SJung-uk Kim int ASN1_INTEGER_set_uint64(ASN1_INTEGER *a, uint64_t r); 21e71b7053SJung-uk Kim 22e71b7053SJung-uk Kim ASN1_INTEGER *BN_to_ASN1_INTEGER(const BIGNUM *bn, ASN1_INTEGER *ai); 23e71b7053SJung-uk Kim BIGNUM *ASN1_INTEGER_to_BN(const ASN1_INTEGER *ai, BIGNUM *bn); 24e71b7053SJung-uk Kim 2517f01e99SJung-uk Kim int ASN1_ENUMERATED_get_int64(int64_t *pr, const ASN1_ENUMERATED *a); 26e71b7053SJung-uk Kim long ASN1_ENUMERATED_get(const ASN1_ENUMERATED *a); 27e71b7053SJung-uk Kim 2817f01e99SJung-uk Kim int ASN1_ENUMERATED_set_int64(ASN1_ENUMERATED *a, int64_t r); 29e71b7053SJung-uk Kim int ASN1_ENUMERATED_set(ASN1_ENUMERATED *a, long v); 30e71b7053SJung-uk Kim 31*b077aed3SPierre Pronchery ASN1_ENUMERATED *BN_to_ASN1_ENUMERATED(const BIGNUM *bn, ASN1_ENUMERATED *ai); 32*b077aed3SPierre Pronchery BIGNUM *ASN1_ENUMERATED_to_BN(const ASN1_ENUMERATED *ai, BIGNUM *bn); 33e71b7053SJung-uk Kim 34e71b7053SJung-uk Kim=head1 DESCRIPTION 35e71b7053SJung-uk Kim 36e71b7053SJung-uk KimThese functions convert to and from B<ASN1_INTEGER> and B<ASN1_ENUMERATED> 37e71b7053SJung-uk Kimstructures. 38e71b7053SJung-uk Kim 39e71b7053SJung-uk KimASN1_INTEGER_get_int64() converts an B<ASN1_INTEGER> into an B<int64_t> type 40*b077aed3SPierre ProncheryIf successful it returns 1 and sets I<*pr> to the value of I<a>. If it fails 41e71b7053SJung-uk Kim(due to invalid type or the value being too big to fit into an B<int64_t> type) 42e71b7053SJung-uk Kimit returns 0. 43e71b7053SJung-uk Kim 44e71b7053SJung-uk KimASN1_INTEGER_get_uint64() is similar to ASN1_INTEGER_get_int64_t() except it 45e71b7053SJung-uk Kimconverts to a B<uint64_t> type and an error is returned if the passed integer 46e71b7053SJung-uk Kimis negative. 47e71b7053SJung-uk Kim 48*b077aed3SPierre ProncheryASN1_INTEGER_get() also returns the value of I<a> but it returns 0 if I<a> is 49e71b7053SJung-uk KimNULL and -1 on error (which is ambiguous because -1 is a legitimate value for 50e71b7053SJung-uk Kiman B<ASN1_INTEGER>). New applications should use ASN1_INTEGER_get_int64() 51e71b7053SJung-uk Kiminstead. 52e71b7053SJung-uk Kim 53*b077aed3SPierre ProncheryASN1_INTEGER_set_int64() sets the value of B<ASN1_INTEGER> I<a> to the 54*b077aed3SPierre ProncheryB<int64_t> value I<r>. 55e71b7053SJung-uk Kim 56*b077aed3SPierre ProncheryASN1_INTEGER_set_uint64() sets the value of B<ASN1_INTEGER> I<a> to the 57*b077aed3SPierre ProncheryB<uint64_t> value I<r>. 58e71b7053SJung-uk Kim 59*b077aed3SPierre ProncheryASN1_INTEGER_set() sets the value of B<ASN1_INTEGER> I<a> to the I<long> value 60*b077aed3SPierre ProncheryI<v>. 61e71b7053SJung-uk Kim 62*b077aed3SPierre ProncheryBN_to_ASN1_INTEGER() converts B<BIGNUM> I<bn> to an B<ASN1_INTEGER>. If I<ai> 63*b077aed3SPierre Proncheryis NULL a new B<ASN1_INTEGER> structure is returned. If I<ai> is not NULL then 64e71b7053SJung-uk Kimthe existing structure will be used instead. 65e71b7053SJung-uk Kim 66*b077aed3SPierre ProncheryASN1_INTEGER_to_BN() converts ASN1_INTEGER I<ai> into a B<BIGNUM>. If I<bn> is 67*b077aed3SPierre ProncheryNULL a new B<BIGNUM> structure is returned. If I<bn> is not NULL then the 68e71b7053SJung-uk Kimexisting structure will be used instead. 69e71b7053SJung-uk Kim 70e71b7053SJung-uk KimASN1_ENUMERATED_get_int64(), ASN1_ENUMERATED_set_int64(), 71e71b7053SJung-uk KimASN1_ENUMERATED_set(), BN_to_ASN1_ENUMERATED() and ASN1_ENUMERATED_to_BN() 72e71b7053SJung-uk Kimbehave in an identical way to their ASN1_INTEGER counterparts except they 73e71b7053SJung-uk Kimoperate on an B<ASN1_ENUMERATED> value. 74e71b7053SJung-uk Kim 75*b077aed3SPierre ProncheryASN1_ENUMERATED_get() returns the value of I<a> in a similar way to 76*b077aed3SPierre ProncheryASN1_INTEGER_get() but it returns B<0xffffffffL> if the value of I<a> will not 77e71b7053SJung-uk Kimfit in a long type. New applications should use ASN1_ENUMERATED_get_int64() 78e71b7053SJung-uk Kiminstead. 79e71b7053SJung-uk Kim 80e71b7053SJung-uk Kim=head1 NOTES 81e71b7053SJung-uk Kim 82e71b7053SJung-uk KimIn general an B<ASN1_INTEGER> or B<ASN1_ENUMERATED> type can contain an 83e71b7053SJung-uk Kiminteger of almost arbitrary size and so cannot always be represented by a C 8458f35182SJung-uk KimB<int64_t> type. However, in many cases (for example version numbers) they 85e71b7053SJung-uk Kimrepresent small integers which can be more easily manipulated if converted to 86e71b7053SJung-uk Kiman appropriate C integer type. 87e71b7053SJung-uk Kim 88e71b7053SJung-uk Kim=head1 BUGS 89e71b7053SJung-uk Kim 90e71b7053SJung-uk KimThe ambiguous return values of ASN1_INTEGER_get() and ASN1_ENUMERATED_get() 91e71b7053SJung-uk Kimmean these functions should be avoided if possible. They are retained for 92e71b7053SJung-uk Kimcompatibility. Normally the ambiguous return values are not legitimate 93e71b7053SJung-uk Kimvalues for the fields they represent. 94e71b7053SJung-uk Kim 95e71b7053SJung-uk Kim=head1 RETURN VALUES 96e71b7053SJung-uk Kim 97e71b7053SJung-uk KimASN1_INTEGER_set_int64(), ASN1_INTEGER_set(), ASN1_ENUMERATED_set_int64() and 98e71b7053SJung-uk KimASN1_ENUMERATED_set() return 1 for success and 0 for failure. They will only 99e71b7053SJung-uk Kimfail if a memory allocation error occurs. 100e71b7053SJung-uk Kim 101e71b7053SJung-uk KimASN1_INTEGER_get_int64() and ASN1_ENUMERATED_get_int64() return 1 for success 102e71b7053SJung-uk Kimand 0 for failure. They will fail if the passed type is incorrect (this will 103e71b7053SJung-uk Kimonly happen if there is a programming error) or if the value exceeds the range 104e71b7053SJung-uk Kimof an B<int64_t> type. 105e71b7053SJung-uk Kim 106e71b7053SJung-uk KimBN_to_ASN1_INTEGER() and BN_to_ASN1_ENUMERATED() return an B<ASN1_INTEGER> or 107e71b7053SJung-uk KimB<ASN1_ENUMERATED> structure respectively or NULL if an error occurs. They will 108e71b7053SJung-uk Kimonly fail due to a memory allocation error. 109e71b7053SJung-uk Kim 110e71b7053SJung-uk KimASN1_INTEGER_to_BN() and ASN1_ENUMERATED_to_BN() return a B<BIGNUM> structure 111e71b7053SJung-uk Kimof NULL if an error occurs. They can fail if the passed type is incorrect 112e71b7053SJung-uk Kim(due to programming error) or due to a memory allocation failure. 113e71b7053SJung-uk Kim 114e71b7053SJung-uk Kim=head1 SEE ALSO 115e71b7053SJung-uk Kim 116e71b7053SJung-uk KimL<ERR_get_error(3)> 117e71b7053SJung-uk Kim 118e71b7053SJung-uk Kim=head1 HISTORY 119e71b7053SJung-uk Kim 120e71b7053SJung-uk KimASN1_INTEGER_set_int64(), ASN1_INTEGER_get_int64(), 121e71b7053SJung-uk KimASN1_ENUMERATED_set_int64() and ASN1_ENUMERATED_get_int64() 1226935a639SJung-uk Kimwere added in OpenSSL 1.1.0. 123e71b7053SJung-uk Kim 124e71b7053SJung-uk Kim=head1 COPYRIGHT 125e71b7053SJung-uk Kim 126*b077aed3SPierre ProncheryCopyright 2015-2021 The OpenSSL Project Authors. All Rights Reserved. 127e71b7053SJung-uk Kim 128*b077aed3SPierre ProncheryLicensed under the Apache License 2.0 (the "License"). You may not use 129e71b7053SJung-uk Kimthis file except in compliance with the License. You can obtain a copy 130e71b7053SJung-uk Kimin the file LICENSE in the source distribution or at 131e71b7053SJung-uk KimL<https://www.openssl.org/source/license.html>. 132e71b7053SJung-uk Kim 133e71b7053SJung-uk Kim=cut 134