ASN1_STRING_NEW(3ssl)
π ASN1_STRING_NEW β the ASN1_STRING allocation girlies
okay so bestie, this is the 3ssl manual page for ASN1_STRING_NEW, and it's literally all about making and unmaking ASN1_STRING structures. allocation functions, that's the vibe. let's get into it β¨
πΈ SYNOPSIS πΈ
#include <openssl/asn1.h>
ASN1_STRING *ASN1_STRING_new(void);
ASN1_STRING *ASN1_STRING_type_new(int type);
ASN1_STRING *ASN1_STRING_new_not_owned(int type, const uint8_t *data, size_t length);
void ASN1_STRING_free(ASN1_STRING *a);
like, copy-paste it exactly pls, don't be out here retyping signatures from memory π
π DESCRIPTION π
ASN1_STRING_new()β hands you back an allocatedASN1_STRINGstructure. its type? undefined. literally no type. it's giving "figuring itself out" energy π¦ASN1_STRING_type_new()β same deal, an allocatedASN1_STRINGstructure, except this one is of typetype. you're deciding for it. main character move πASN1_STRING_new_not_owned()β returns an allocatedASN1_STRINGstructure of typetype, and sets the data of the returned string to the bytes atdataof lengthlen. and here's the key part, bestie β ownership ofdatais NOT transferred. it is the caller's responsibility to make suredataoutlives any successfully returned result. so like, keep it alive, don't let it get freed out from under you π
also the rules for this one, and they are strict:
- the provided
typemust not beV_ASN1_BIT_STRING - the provided
lengthmust be greater than 0 datamust not beNULL- and it is an error if the provided data size exceeds the internal limit of the
ASN1_STRINGimplementation π
ASN1_STRING_free()β freesa. and ifaisNULL, nothing is done. no drama, no crash, it just β¨nothingβ¨
π NOTES π
other string types call the ASN1_STRING functions, iykyk. for example, ASN1_OCTET_STRING_new() calls ASN1_STRING_type_new(V_ASN1_OCTET_STRING). see? they're all connected, it's a whole ecosystem π
ASN1_STRING_new_not_owned() does not automatically call strlen() to figure out a length, and it does not guarantee that the data is a C string. nope! the data contained in the string and the lifetime of it are 100% the responsibility of the caller. you're on your own with that one bestie, no cap π«Ά
β RETURN VALUES β
ASN1_STRING_new(), ASN1_STRING_type_new(), and ASN1_STRING_new_not_owned() return a valid ASN1_STRING structure β or NULL if an error occurred π so like, always check. always.
ASN1_STRING_free() does not return a value. it's a void girlie, she gives nothing back and that's fine π
π¦ SEE ALSO π¦
ERR_get_error(3)β go read it, it's how you find out what went wrong π
π₯ HISTORY π₯
ASN1_STRING_new_not_owned() was added in OpenSSL 4.1. new girl on the block, freshly iconic β¨
π COPYRIGHT π
Copyright 2002-2026 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 page bestie!! this one's from version 4.1.0, dated 2026-10-23, and it's the ASN1_STRING_NEW(3ssl) manual β go forth and allocate responsibly πππ§
π¦ where this page comes from
- nixos 26.05: openssl 4.1.0
- nixpkgs unstable: openssl 4.1.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms