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