1e71b7053SJung-uk Kim=pod 2e71b7053SJung-uk Kim 3e71b7053SJung-uk Kim=head1 NAME 4e71b7053SJung-uk Kim 5e71b7053SJung-uk KimASN1_STRING_dup, ASN1_STRING_cmp, ASN1_STRING_set, ASN1_STRING_length, 6e71b7053SJung-uk KimASN1_STRING_type, ASN1_STRING_get0_data, ASN1_STRING_data, 7e71b7053SJung-uk KimASN1_STRING_to_UTF8 - ASN1_STRING utility functions 8e71b7053SJung-uk Kim 9e71b7053SJung-uk Kim=head1 SYNOPSIS 10e71b7053SJung-uk Kim 11e71b7053SJung-uk Kim #include <openssl/asn1.h> 12e71b7053SJung-uk Kim 13e71b7053SJung-uk Kim int ASN1_STRING_length(ASN1_STRING *x); 14e71b7053SJung-uk Kim const unsigned char *ASN1_STRING_get0_data(const ASN1_STRING *x); 15e71b7053SJung-uk Kim unsigned char *ASN1_STRING_data(ASN1_STRING *x); 16e71b7053SJung-uk Kim 17*b077aed3SPierre Pronchery ASN1_STRING *ASN1_STRING_dup(const ASN1_STRING *a); 18e71b7053SJung-uk Kim 19e71b7053SJung-uk Kim int ASN1_STRING_cmp(ASN1_STRING *a, ASN1_STRING *b); 20e71b7053SJung-uk Kim 21e71b7053SJung-uk Kim int ASN1_STRING_set(ASN1_STRING *str, const void *data, int len); 22e71b7053SJung-uk Kim 23e71b7053SJung-uk Kim int ASN1_STRING_type(const ASN1_STRING *x); 24e71b7053SJung-uk Kim 25e71b7053SJung-uk Kim int ASN1_STRING_to_UTF8(unsigned char **out, const ASN1_STRING *in); 26e71b7053SJung-uk Kim 27e71b7053SJung-uk Kim=head1 DESCRIPTION 28e71b7053SJung-uk Kim 29e71b7053SJung-uk KimThese functions allow an B<ASN1_STRING> structure to be manipulated. 30e71b7053SJung-uk Kim 31*b077aed3SPierre ProncheryASN1_STRING_length() returns the length of the content of I<x>. 32e71b7053SJung-uk Kim 33*b077aed3SPierre ProncheryASN1_STRING_get0_data() returns an internal pointer to the data of I<x>. 34e71b7053SJung-uk KimSince this is an internal pointer it should B<not> be freed or 35e71b7053SJung-uk Kimmodified in any way. 36e71b7053SJung-uk Kim 37e71b7053SJung-uk KimASN1_STRING_data() is similar to ASN1_STRING_get0_data() except the 38e71b7053SJung-uk Kimreturned value is not constant. This function is deprecated: 39e71b7053SJung-uk Kimapplications should use ASN1_STRING_get0_data() instead. 40e71b7053SJung-uk Kim 41*b077aed3SPierre ProncheryASN1_STRING_dup() returns a copy of the structure I<a>. 42e71b7053SJung-uk Kim 43*b077aed3SPierre ProncheryASN1_STRING_cmp() compares I<a> and I<b> returning 0 if the two 44e71b7053SJung-uk Kimare identical. The string types and content are compared. 45e71b7053SJung-uk Kim 46*b077aed3SPierre ProncheryASN1_STRING_set() sets the data of string I<str> to the buffer 47*b077aed3SPierre ProncheryI<data> or length I<len>. The supplied data is copied. If I<len> 48e71b7053SJung-uk Kimis -1 then the length is determined by strlen(data). 49e71b7053SJung-uk Kim 50*b077aed3SPierre ProncheryASN1_STRING_type() returns the type of I<x>, using standard constants 51e71b7053SJung-uk Kimsuch as B<V_ASN1_OCTET_STRING>. 52e71b7053SJung-uk Kim 53*b077aed3SPierre ProncheryASN1_STRING_to_UTF8() converts the string I<in> to UTF8 format, the 54*b077aed3SPierre Proncheryconverted data is allocated in a buffer in I<*out>. The length of 55*b077aed3SPierre ProncheryI<out> is returned or a negative error code. The buffer I<*out> 56e71b7053SJung-uk Kimshould be freed using OPENSSL_free(). 57e71b7053SJung-uk Kim 58e71b7053SJung-uk Kim=head1 NOTES 59e71b7053SJung-uk Kim 60e71b7053SJung-uk KimAlmost all ASN1 types in OpenSSL are represented as an B<ASN1_STRING> 61e71b7053SJung-uk Kimstructure. Other types such as B<ASN1_OCTET_STRING> are simply typedef'ed 62e71b7053SJung-uk Kimto B<ASN1_STRING> and the functions call the B<ASN1_STRING> equivalents. 63e71b7053SJung-uk KimB<ASN1_STRING> is also used for some B<CHOICE> types which consist 64e71b7053SJung-uk Kimentirely of primitive string types such as B<DirectoryString> and 65e71b7053SJung-uk KimB<Time>. 66e71b7053SJung-uk Kim 67e71b7053SJung-uk KimThese functions should B<not> be used to examine or modify B<ASN1_INTEGER> 68e71b7053SJung-uk Kimor B<ASN1_ENUMERATED> types: the relevant B<INTEGER> or B<ENUMERATED> 69e71b7053SJung-uk Kimutility functions should be used instead. 70e71b7053SJung-uk Kim 71e71b7053SJung-uk KimIn general it cannot be assumed that the data returned by ASN1_STRING_data() 72e71b7053SJung-uk Kimis null terminated or does not contain embedded nulls. The actual format 73e71b7053SJung-uk Kimof the data will depend on the actual string type itself: for example 74e71b7053SJung-uk Kimfor an IA5String the data will be ASCII, for a BMPString two bytes per 7558f35182SJung-uk Kimcharacter in big endian format, and for a UTF8String it will be in UTF8 format. 76e71b7053SJung-uk Kim 77e71b7053SJung-uk KimSimilar care should be take to ensure the data is in the correct format 78e71b7053SJung-uk Kimwhen calling ASN1_STRING_set(). 79e71b7053SJung-uk Kim 80e71b7053SJung-uk Kim=head1 RETURN VALUES 81e71b7053SJung-uk Kim 82*b077aed3SPierre ProncheryASN1_STRING_length() returns the length of the content of I<x>. 83e71b7053SJung-uk Kim 84e71b7053SJung-uk KimASN1_STRING_get0_data() and ASN1_STRING_data() return an internal pointer to 85*b077aed3SPierre Proncherythe data of I<x>. 86e71b7053SJung-uk Kim 87*b077aed3SPierre ProncheryASN1_STRING_dup() returns a valid B<ASN1_STRING> structure or NULL if an 88e71b7053SJung-uk Kimerror occurred. 89e71b7053SJung-uk Kim 90e71b7053SJung-uk KimASN1_STRING_cmp() returns an integer greater than, equal to, or less than 0, 91*b077aed3SPierre Proncheryaccording to whether I<a> is greater than, equal to, or less than I<b>. 92e71b7053SJung-uk Kim 93e71b7053SJung-uk KimASN1_STRING_set() returns 1 on success or 0 on error. 94e71b7053SJung-uk Kim 95*b077aed3SPierre ProncheryASN1_STRING_type() returns the type of I<x>. 96e71b7053SJung-uk Kim 97*b077aed3SPierre ProncheryASN1_STRING_to_UTF8() returns the number of bytes in output string I<out> or a 98e71b7053SJung-uk Kimnegative value if an error occurred. 99e71b7053SJung-uk Kim 100e71b7053SJung-uk Kim=head1 SEE ALSO 101e71b7053SJung-uk Kim 102e71b7053SJung-uk KimL<ERR_get_error(3)> 103e71b7053SJung-uk Kim 104e71b7053SJung-uk Kim=head1 COPYRIGHT 105e71b7053SJung-uk Kim 10658f35182SJung-uk KimCopyright 2002-2020 The OpenSSL Project Authors. All Rights Reserved. 107e71b7053SJung-uk Kim 108*b077aed3SPierre ProncheryLicensed under the Apache License 2.0 (the "License"). You may not use 109e71b7053SJung-uk Kimthis file except in compliance with the License. You can obtain a copy 110e71b7053SJung-uk Kimin the file LICENSE in the source distribution or at 111e71b7053SJung-uk KimL<https://www.openssl.org/source/license.html>. 112e71b7053SJung-uk Kim 113e71b7053SJung-uk Kim=cut 114