]> git.ipfire.org Git - thirdparty/openssl.git/commit
Prepare a now opaque ASN1_STRING for the size_t rapture.
authorBob Beck <beck@openssl.org>
Mon, 11 May 2026 16:30:04 +0000 (10:30 -0600)
committerNorbert Pocs <norbertp@openssl.org>
Sat, 18 Jul 2026 13:00:57 +0000 (15:00 +0200)
commit28179061bfcdfe579f63a129bf0b97766a5d90a7
treed5e59196d2ab062e7e44a6c258dd1c277203095e
parentd8bf6cdd4849925c30e4f1911c7acb49cb34b702
Prepare a now opaque ASN1_STRING for the size_t rapture.

Now that ASN1_STRING is opaque, we can finally move away
from an int for the length internally. The remaining problematic
piece for this is that ASN1_STRING_length() returns an int
and is public API.

Therefore, we deprecate ASN1_STRING_length() and provide a
replacement ASN1_STRING_length_ex() that returns a size_t length.

We also provide setting functions that take size_t lengths,
they are ASN1_STRING_set_data() which takes a uint8_t data
pointer and a size_t length, and ASN1_STRING_set_string() which
takes a argument that must be a c string and will use strlen
to determine the length. (This replaces th previous arcane
behaviour of calling "strlen" on a magical input length value
of -1, which leads to bugs.)  We then deprecate ASN1_STRING_set().

ASN1_STRING_set_string() requires a valid C string argument that
may not be NULL - refer to the documentation.

Both new functions do not magically add 0 bytes on the end of
values, as ASN1_STRING has already been documented for a long
time to not depend on this behaviour.

Both new functions do not allow the setting of values on an
ASN1_BIT_STRING, as ASN1_BIT_STRING_set1 must be used for that.

Note that this does *NOT* yet change ASN1_STRING to use size_t
internally, this must wait until the integer-returning ASN1_STRING_length()
has been deprecated, and then removed in future major. Once
ASN1_STRING_length() has been removed then ASN1_STRING internally
can change to using a size_t for the length of the data.
(And the setters will no longer return an error if the provided
size_t length exceeds INT_MAX)

Reviewed-by: Milan Broz <mbroz@openssl.org>
Reviewed-by: Norbert Pocs <norbertp@openssl.org>
MergeDate: Sat Jul 18 13:01:15 2026
(Merged from https://github.com/openssl/openssl/pull/31194)
crypto/asn1/a_octet.c
crypto/asn1/asn1_lib.c
doc/man3/ASN1_STRING_length.pod
include/openssl/asn1.h.in
test/asn1_string_test.c
util/libcrypto.num