ASN1_STRING_LENGTH(3)
β¨ NAME β¨
okay so bestie, you found ASN1_STRING_LENGTH(3) from the Library Functions Manual β and yes, it's giving "one page, entire friend group" energy π
. The name tag says ASN1_STRING utility functions, and the whole squad is: ASN1_STRING_cmp, ASN1_OCTET_STRING_cmp, ASN1_STRING_dup, ASN1_OCTET_STRING_dup, ASN1_STRING_get0_data, ASN1_STRING_length, ASN1_STRING_length_set, ASN1_STRING_set0, ASN1_STRING_set, ASN1_OCTET_STRING_set, ASN1_STRING_copy, ASN1_STRING_to_UTF8, ASN1_STRING_type, and ASN1_STRING_data.
πΈ SYNOPSIS πΈ
the exact signatures, no cap, no edits:
library βlibcryptoβ #include <openssl/asn1.h>
int
ASN1_STRING_cmp(const ASN1_STRING *a, const ASN1_STRING *b);
int
ASN1_OCTET_STRING_cmp(const ASN1_OCTET_STRING *a,
const ASN1_OCTET_STRING *b);
ASN1_STRING *
ASN1_STRING_dup(const ASN1_STRING *a);
ASN1_OCTET_STRING *
ASN1_OCTET_STRING_dup(const ASN1_OCTET_STRING *a);
const unsigned char *
ASN1_STRING_get0_data(const ASN1_STRING *x);
int
ASN1_STRING_length(const ASN1_STRING *x);
void
ASN1_STRING_length_set(ASN1_STRING *x, int len);
void
ASN1_STRING_set0(ASN1_STRING *str, void *data, int len);
int
ASN1_STRING_set(ASN1_STRING *str, const void *data, int len);
int
ASN1_OCTET_STRING_set(ASN1_OCTET_STRING *str, const unsigned char *data,
int len);
int
ASN1_STRING_copy(ASN1_STRING *dst, const ASN1_STRING *src);
int
ASN1_STRING_to_UTF8(unsigned char **out, const ASN1_STRING *in);
int
ASN1_STRING_type(const ASN1_STRING *x);
Deprecated:
unsigned char *
ASN1_STRING_data(ASN1_STRING *x);
π DESCRIPTION π
These functions manipulate ASN1_STRING structures. That's the whole mood. Here's the function-by-function tea β:
ASN1_STRING_cmp()β compares the type, the length, and the content ofaandb.ASN1_OCTET_STRING_cmp()β does exactly the same asASN1_STRING_cmp()without providing any type safety. πASN1_STRING_dup()β allocates a newASN1_STRINGobject and copies the type, length, data, and flags fromainto it.ASN1_OCTET_STRING_dup()β does exactly the same asASN1_STRING_dup()without providing any type safety.ASN1_STRING_get0_data()β returns an internal pointer to the data ofx. It should not be freed or modified in any way. like, hands off the merchandise bestie π ββοΈASN1_STRING_length()β returns the length attribute ofx, measured in bytes.ASN1_STRING_length_set()β sets the length attribute ofxtolen.
π¨ It may put x into an inconsistent internal state. so, like, be aware.
ASN1_STRING_set0()β frees any data stored instr, sets the length attribute tolenbytes, and sets the data attribute todata, transferring ownership, without doing any validation. ownership moves, no validation, chaotic but iconic πASN1_STRING_set()β sets the length attribute ofstrtolenand copies that number of bytes fromdataintostr, overwriting any previous data. Iflenis-1, thenstrlen(data)is used instead oflen. IfdataisNULL, the content ofstrremains uninitialized; that is not considered an error unlesslenis negative.ASN1_OCTET_STRING_set()β does exactly the same asASN1_STRING_set()without providing any type safety.ASN1_STRING_copy()β copies the length and data ofsrcintodstusingASN1_STRING_set()and changes the type and flags ofdstto match the type and flags ofsrc.ASN1_STRING_to_UTF8()β converts the stringinto UTF-8 format. The converted data is copied into a newly allocated buffer*out. The buffer*outshould be freed usingfree(3).ASN1_STRING_type()β returns the type ofx. If the bitV_ASN1_NEGis set in the return value,xis an ASN.1 INTEGER or ENUMERATED object with a negative value.ASN1_STRING_data()β is similar toASN1_STRING_get0_data()except that the returned value is not constant. This function is deprecated. Applications should useASN1_STRING_get0_data()instead.
Almost all ASN.1 types are represented as ASN1_STRING structures. Other types such as ASN1_OCTET_STRING are simply typedefed to ASN1_STRING and the functions call the ASN1_STRING equivalents. ASN1_STRING is also used for some CHOICE types which consist entirely of primitive string types such as DirectoryString and Time.
π¨ Real talk: these functions should not be used to examine or modifyASN1_INTEGERorASN1_ENUMERATEDtypes: the relevant INTEGER or ENUMERATED utility functions should be used instead.
In general it cannot be assumed that the data returned by ASN1_STRING_get0_data() and ASN1_STRING_data() is NUL terminated, and it may contain embedded NUL characters. The format of the data depends on the string type: for example for an IA5String the data contains ASCII characters, for a BMPString two bytes per character in big endian format, and for a UTF8String UTF-8 characters.
Similar care should be taken to ensure the data is in the correct format when calling ASN1_STRING_set() or ASN1_STRING_set0().
π RETURN VALUES π
ASN1_STRING_cmp()andASN1_OCTET_STRING_cmp()β return0if the type, the length, and the content ofaandbagree, or a non-zero value otherwise. In contrast tostrcmp(3), the sign of the return value does not indicate lexicographical ordering. π important.ASN1_STRING_get0_data()andASN1_STRING_data()β return an internal pointer to the data ofx.ASN1_STRING_dup()andASN1_OCTET_STRING_dup()β return a pointer to a newly allocatedASN1_STRINGstructure orNULLif an error occurred.ASN1_STRING_length()β returns a number of bytes.ASN1_STRING_set(),ASN1_OCTET_STRING_set(), andASN1_STRING_copy()β return1on success or0on failure. They fail if memory allocation fails.ASN1_STRING_set()andASN1_OCTET_STRING_set()also fail ifdataisNULLandlenis-1in the same call.ASN1_STRING_copy()also fails ifsrcisNULL.ASN1_STRING_to_UTF8()β returns the number of bytes in the output buffer*out, or a negative number if an error occurred.ASN1_STRING_type()β returns an integer constant, for exampleV_ASN1_OCTET_STRINGorV_ASN1_NEG_INTEGER.
In some cases of failure of ASN1_STRING_dup(), ASN1_STRING_set(), and ASN1_STRING_to_UTF8(), the reason can be determined with ERR_get_error(3).
π¦ SEE ALSO π¦
a2i_ASN1_STRING(3)a2i_ipadd(3)ASN1_BIT_STRING_set(3)ASN1_mbstring_copy(3)ASN1_PRINTABLE_type(3)ASN1_STRING_new(3)ASN1_UNIVERSALSTRING_to_string(3)s2i_ASN1_INTEGER(3)
π HISTORY π
ASN1_STRING_cmp(),ASN1_STRING_dup(),ASN1_STRING_set(), andASN1_OCTET_STRING_set()first appeared in SSLeay 0.6.5.ASN1_OCTET_STRING_cmp(),ASN1_STRING_data(),ASN1_OCTET_STRING_dup(), andASN1_STRING_type()first appeared in SSLeay 0.8.0.ASN1_STRING_length()first appeared in SSLeay 0.9.0. All these functions have been available since OpenBSD 2.4.ASN1_STRING_length_set()first appeared in OpenSSL 0.9.5 and has been available since OpenBSD 2.7.ASN1_STRING_to_UTF8()first appeared in OpenSSL 0.9.6 and has been available since OpenBSD 2.9.ASN1_STRING_set0()first appeared in OpenSSL 0.9.8h and has been available since OpenBSD 4.5.ASN1_STRING_copy()first appeared in OpenSSL 1.0.0 and has been available since OpenBSD 4.9.ASN1_STRING_get0_data()first appeared in OpenSSL 1.1.0 and has been available since OpenBSD 6.3.
π BUGS π
not me discovering that ASN1_OCTET_STRING_cmp(), ASN1_OCTET_STRING_dup(), and ASN1_OCTET_STRING_set() do not check whether their arguments are really of the type V_ASN1_OCTET_STRING. They may report success even if their arguments are of a wrong type. Consequently, even in case of success, the return value of ASN1_OCTET_STRING_dup() is not guaranteed to be of the type V_ASN1_OCTET_STRING either. π
Cute sign-off, bestie: source/version Debian, date August 23, 2026 β that's the footer tea, and yes the page is still ASN1_STRING_LENGTH(3) πβ¨
π¦ where this page comes from
- arch rolling: libressl 4.4.0-1 Β· ISC AND custom:OpenSSL
- Copyright (c) 2018, 2019, 2021 Ingo Schwarze <schwarze@openbsd.org>
- Copyright (c) 2002, 2006, 2013, 2015, 2016, 2017 The OpenSSL Project
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms