ASN1_STRING_LENGTH(3SSL)
β¨ ASN1_STRING_LENGTH β¨
okay bestie, welcome to the 3SSL manual, this one's all about the OpenSSL ASN1_STRING utility functions π and honestly? it's giving "small but mighty" and i'm obsessed π
so the whole girl squad here is: ASN1_STRING_dup, ASN1_STRING_cmp, ASN1_STRING_set, ASN1_STRING_length, ASN1_STRING_type, ASN1_STRING_get0_data, and ASN1_STRING_to_UTF8 π
πΈ SYNOPSIS πΈ
#include <openssl/asn1.h>
int ASN1_STRING_length(ASN1_STRING *x);
const unsigned char *ASN1_STRING_get0_data(const ASN1_STRING *x);
ASN1_STRING *ASN1_STRING_dup(const ASN1_STRING *a);
int ASN1_STRING_cmp(ASN1_STRING *a, ASN1_STRING *b);
int ASN1_STRING_set(ASN1_STRING *str, const void *data, int len);
int ASN1_STRING_type(const ASN1_STRING *x);
int ASN1_STRING_to_UTF8(unsigned char **out, const ASN1_STRING *in);
like, write it down, screenshot it, whatever β just don't paraphrase it β¨
π DESCRIPTION π
so basically these functions let you mess with an ASN1_STRING structure π«Ά here's the rundown, one by one:
ASN1_STRING_length()β returns the length of the content ofx. andxMUST NOT be NULL okay?? that's not a vibe, that's a rule πASN1_STRING_get0_data()β hands you an internal pointer to the data ofx. and the0in the name is lowkey a warning fr fr: since it's an internal pointer, you should not free it and you should not modify it in any way π same energy:xMUST NOT be NULL.ASN1_STRING_dup()β returns a copy of the structureaπ¦ clone her, respectfully.ASN1_STRING_cmp()β comparesaandband returns0if the two are identical. it compares the string types AND the content, no shortcuts π€ASN1_STRING_set()β sets the data of stringstrto the bufferdataor lengthlen. the supplied data gets copied (no aliasing drama here π) and iflenis-1then the length is determined bystrlen(data)β¨ASN1_STRING_type()β returns the type ofx, using the standard constants such asV_ASN1_OCTET_STRINGπASN1_STRING_to_UTF8()β converts the stringinto UTF8 format, and the converted data gets allocated in a buffer in*out. it returns the length ofout, or a negative error code if it's not giving π and bestie, the buffer*outshould be freed usingOPENSSL_free()β do not forget, i'm literally begging π
π NOTES π
okay this part matters, listen up:
- almost all ASN1 types in OpenSSL are represented as an
ASN1_STRINGstructure. other types such asASN1_OCTET_STRINGare simplytypedef'ed toASN1_STRINGand the functions call theASN1_STRINGequivalents. no cap π ASN1_STRINGis also used for someCHOICEtypes which consist entirely of primitive string types such asDirectoryStringandTimeβ¨- these functions should NOT be used to examine or modify
ASN1_INTEGERorASN1_ENUMERATEDtypes β the relevant INTEGER or ENUMERATED utility functions should be used instead. stay in your lane, bestie π - in general it cannot be assumed that the data returned by
ASN1_STRING_get0_data()is null terminated or does not contain embedded nulls β οΈ the actual format of the data will depend on the actual string type itself:- for an
IA5Stringthe data will be ASCII - for a
BMPString, two bytes per character in big endian format - and for a
UTF8Stringit will be in UTF8 format π¦
- for an
- similar care should be taken to ensure the data is in the correct format when calling
ASN1_STRING_set()πΈ
the way that embedded nulls can just β¨appearβ¨ in your data and ruin your whole strlen-based day... be careful out there π
β RETURN VALUES β
ASN1_STRING_length()β returns the length of the content ofxπASN1_STRING_get0_data()β returns an internal pointer to the data ofxπ«ΆASN1_STRING_dup()β returns a validASN1_STRINGstructure orNULLif an error occurred πASN1_STRING_cmp()β returns an integer greater than, equal to, or less than0, according to whetherais greater than, equal to, or less thanbβοΈASN1_STRING_set()β returns1on success or0on error πASN1_STRING_type()β returns the type ofxπ·οΈASN1_STRING_to_UTF8()β returns the number of bytes in output stringout, or a negative value if an error occurred π
π SEE ALSO π
ERR_get_error(3)β go read her next, she's iconic π
π COPYRIGHT π
Copyright 2002-2020 The OpenSSL Project Authors. All Rights Reserved. π«Ά
Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at <https://www.openssl.org/source/license.html>. πβ¨
and that's the whole page, bestie!! this one shipped in OpenSSL 4.0.3, dated 2026-09-29, and it's the ASN1_STRING_LENGTH(3SSL) manual β go forth and OPENSSL_free() responsibly π
ππ
π¦ where this page comes from
- ubuntu stonking: libssl-doc 4.0.3-1ubuntu1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms