ASN1_MBSTRING_COPY(3)
π ASN1_MBSTRING_COPY(3) π
okay bestie, this is the ASN1_MBSTRING_COPY(3) page from the Library Functions Manual β and it's all about copying a multibyte string into an ASN.1 string object. no cap, the vibes are immaculate. β¨
πΈ NAME πΈ
ASN1_mbstring_copy,ASN1_mbstring_ncopy,ASN1_STRING_set_by_NID,ASN1_STRING_set_default_mask,ASN1_STRING_set_default_mask_asc,ASN1_STRING_get_default_mask,ASN1_tag2bitβ these cuties copy a multibyte string into an ASN.1 string object. π«Ά
β¨ SYNOPSIS β¨
#include <openssl/asn1.h>
int
ASN1_mbstring_copy(ASN1_STRING **out, const unsigned char *in,
int inbytes, int inform, unsigned long mask);
int
ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in,
int inbytes, int inform, unsigned long mask, long minchars,
long maxchars);
ASN1_STRING *
ASN1_STRING_set_by_NID(ASN1_STRING **out, const unsigned char *in,
int inbytes, int inform, int nid);
void
ASN1_STRING_set_default_mask(unsigned long mask);
int
ASN1_STRING_set_default_mask_asc(const char *maskname);
unsigned long
ASN1_STRING_get_default_mask(void);
unsigned long
ASN1_tag2bit(int tag);
π DESCRIPTION π
ASN1_mbstring_copy() interprets inbytes bytes starting at in as a multibyte string and copies it to *out, optionally changing the encoding. If the inbytes argument is negative, the strlen(3) of in is used instead. π
The inform argument specifies the character encoding of in:
MBSTRING_ASCβ ISO-Latin-1MBSTRING_BMPβ UTF-16MBSTRING_UNIVβ UTF-32MBSTRING_UTF8β UTF-8
The bit mask specifies a set of ASN.1 string types that the user is willing to accept:
B_ASN1_PRINTABLESTRINGβ acceptable output typeASN1_PRINTABLESTRINGβ default: yesB_ASN1_IA5STRINGβ acceptable output typeASN1_IA5STRINGβ default: noB_ASN1_T61STRINGβ acceptable output typeASN1_T61STRINGβ default: yesB_ASN1_BMPSTRINGβ acceptable output typeASN1_BMPSTRINGβ default: yesB_ASN1_UNIVERSALSTRINGβ acceptable output typeASN1_UNIVERSALSTRINGβ default: no- any other bit β acceptable output type
ASN1_UTF8STRINGβ default: yes
The first type from the above table that is included in the mask argument and that can represent in is used as the output type. The default column indicates whether the type is considered acceptable if the mask argument has the special value 0. π
The following bit mask constants each include several of the bits listed above:
B_ASN1_DIRECTORYSTRINGβ PRI yes, IA5 no, T61 yes, BMP yes, UNI yes, UTF8 yesDIRSTRING_TYPEβ PRI yes, IA5 no, T61 yes, BMP yes, UNI no, UTF8 yesPKCS9STRING_TYPEβ PRI yes, IA5 yes, T61 yes, BMP yes, UNI no, UTF8 yes
If out is NULL, inform, inbytes, and in are validated and the output type is determined and returned, but nothing is copied. π«§
Otherwise, if *out is NULL, a new output object of the output type is allocated and a pointer to it is stored in *out.
Otherwise, **out is used as the output object. Any data already stored in it is freed and its type is changed to the output type. π₯
Finally, in is copied to the output object, changing the character encoding if inform does not match the encoding used by the output type.
ASN1_mbstring_ncopy() is similar except that the number of characters in in is restricted to the range from minchars to maxchars, inclusive. If maxchars is 0, no upper limit is enforced on the number of characters. π
ASN1_STRING_set_by_NID() is similar with the following differences:
- If
outisNULL, a new output object is allocated and returned instead of skipping the copying. - If
nidhas a global string table entry that can be retrieved withASN1_STRING_TABLE_get(3),mask,minchars, andmaxcharsare taken from that string table entry. For some values ofnid, an additional global mask is AND'ed into themaskbefore using it. The default value of the global mask isB_ASN1_UTF8STRING. - If
nidhas no global string table entry,B_ASN1_PRINTABLESTRING | B_ASN1_T61STRING | B_ASN1_BMPSTRING | B_ASN1_UTF8STRINGis used instead of the mask taken from the table, and the global mask is also AND'ed into it. - Even though success and failure happen in the same situations, the return value is different.
ASN1_STRING_type(3)can be used to determine the type of the return value.
ASN1_STRING_set_default_mask() sets the global mask used by ASN1_STRING_set_by_NID() to the mask argument.
ASN1_STRING_set_default_mask_asc() sets the global mask as follows:
"default"β anything"nombstr"β anything exceptB_ASN1_BMPSTRING | B_ASN1_UTF8STRING"pkix"β anything exceptB_ASN1_T61STRING"utf8only"βB_ASN1_UTF8STRING
If the maskname argument starts with the substring "MASK:", the rest of it is interpreted as an unsigned long value using strtoul(3). π¦
ASN1_tag2bit() translates ASN.1 data types to type bits as follows:
V_ASN1_BIT_STRINGβB_ASN1_BIT_STRINGV_ASN1_BMPSTRINGβB_ASN1_BMPSTRINGV_ASN1_BOOLEANβ0V_ASN1_ENUMERATEDβB_ASN1_UNKNOWNV_ASN1_EOCβ0V_ASN1_EXTERNALβB_ASN1_UNKNOWNV_ASN1_GENERALIZEDTIMEβB_ASN1_GENERALIZEDTIMEV_ASN1_GENERALSTRINGβB_ASN1_GENERALSTRINGV_ASN1_GRAPHICSTRINGβB_ASN1_GRAPHICSTRINGV_ASN1_IA5STRINGβB_ASN1_IA5STRINGV_ASN1_INTEGERβ0V_ASN1_ISO64STRINGβB_ASN1_ISO64STRINGV_ASN1_NULLβ0V_ASN1_NUMERICSTRINGβB_ASN1_NUMERICSTRINGV_ASN1_OBJECTβ0V_ASN1_OBJECT_DESCRIPTORβB_ASN1_UNKNOWNV_ASN1_OCTET_STRINGβB_ASN1_OCTET_STRINGV_ASN1_PRINTABLESTRINGβB_ASN1_PRINTABLESTRINGV_ASN1_REALβB_ASN1_UNKNOWNV_ASN1_SEQUENCEβB_ASN1_SEQUENCEV_ASN1_SETβ0V_ASN1_T61STRINGβB_ASN1_T61STRINGV_ASN1_TELETEXSTRINGβB_ASN1_TELETEXSTRINGV_ASN1_UNDEFβ0V_ASN1_UNIVERSALSTRINGβB_ASN1_UNIVERSALSTRINGV_ASN1_UTCTIMEβB_ASN1_UTCTIMEV_ASN1_UTF8STRINGβB_ASN1_UTF8STRINGV_ASN1_VIDEOTEXSTRINGβB_ASN1_VIDEOTEXSTRINGV_ASN1_VISIBLESTRINGβB_ASN1_VISIBLESTRING11,13,14,15,29βB_ASN1_UNKNOWN- other (
< 0,> 30) β0
In typical usage, the calling code calculates the bitwise AND of the return value and a mask describing data types that the calling code is willing to use. If the result of the AND operation is non-zero, the data type is adequate; otherwise, the calling code may need to raise an error. π
π RETURN VALUES π
ASN1_mbstring_copy()andASN1_mbstring_ncopy()return theV_ASN1_*constant representing the output type or-1ifinformis invalid, ifinbytesorinis invalid for theinformencoding, ifincontains an UTF-16 surrogate, which is unsupported even for input using the UTF-16 encoding, or if memory allocation fails.ASN1_mbstring_ncopy()also returns-1ifincontains fewer thanmincharsor more thanmaxcharscharacters.ASN1_STRING_set_by_NID()returns the new or changed ASN.1 string object orNULLon failure.ASN1_STRING_set_default_mask_asc()returns1if successful or0if"MASK:"is not followed by a number, if the number is followed by a non-numeric character, or if themasknameis invalid.ASN1_STRING_get_default_mask()returns the global mask.ASN1_tag2bit()returns aB_ASN1_*constant or0.
π¦ SEE ALSO π¦
ASN1_PRINTABLE_type(3),ASN1_STRING_new(3),ASN1_STRING_set(3),ASN1_STRING_TABLE_get(3),ASN1_UNIVERSALSTRING_to_string(3)
π HISTORY π
ASN1_mbstring_copy(),ASN1_mbstring_ncopy(),ASN1_STRING_set_by_NID(),ASN1_STRING_set_default_mask(),ASN1_STRING_set_default_mask_asc(), andASN1_STRING_get_default_mask()first appeared in OpenSSL 0.9.5 and have been available since OpenBSD 2.7.ASN1_tag2bit()first appeared in OpenSSL 0.9.7 and has been available since OpenBSD 3.2.
π BUGS π
- If integer overflow occurs in
ASN1_STRING_set_default_mask_asc()while parsing a number following"MASK:", the function succeeds, essentially behaving in the same way as for"default". - Passing
"default"toASN1_STRING_set_default_mask_asc()does not restore the default mask. Instead, passing"utf8only"does that. π
mwah π that's the whole page, bestie β brought to you by Debian, dated February 21, 2022, and officially titled ASN1_MBSTRING_COPY(3). π
π¦ where this page comes from
- opensuse-leap 16.0: libressl-devel-doc 4.1.0-bp160.1.1 Β· OpenSSL
- Copyright (c) 2021 Ingo Schwarze <schwarze@openbsd.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms