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