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