NAME
ASN1_STRING_cmp
,
ASN1_OCTET_STRING_cmp
,
ASN1_STRING_data
,
ASN1_STRING_dup
,
ASN1_OCTET_STRING_dup
,
ASN1_STRING_get0_data
,
ASN1_STRING_length
,
ASN1_STRING_length_set
,
ASN1_STRING_set
,
ASN1_OCTET_STRING_set
,
ASN1_STRING_to_UTF8
,
ASN1_STRING_type
—
ASN1_STRING utility
functions
SYNOPSIS
#include
<openssl/asn1.h>
int
ASN1_STRING_cmp
(const ASN1_STRING
*a, const ASN1_STRING *b);
int
ASN1_OCTET_STRING_cmp
(const
ASN1_OCTET_STRING *a, const ASN1_OCTET_STRING
*b);
unsigned char *
ASN1_STRING_data
(ASN1_STRING
*x);
ASN1_STRING *
ASN1_STRING_dup
(const ASN1_STRING
*a);
ASN1_OCTET_STRING *
ASN1_OCTET_STRING_dup
(const
ASN1_OCTET_STRING *a);
const unsigned char *
ASN1_STRING_get0_data
(const
ASN1_STRING *x);
int
ASN1_STRING_length
(const ASN1_STRING
*x);
void
ASN1_STRING_length_set
(ASN1_STRING
*x, int len);
int
ASN1_STRING_set
(ASN1_STRING
*str, const void *data, int
len);
int
ASN1_OCTET_STRING_set
(ASN1_OCTET_STRING
*str, const unsigned char *data,
int len);
int
ASN1_STRING_to_UTF8
(unsigned char
**out, const ASN1_STRING *in);
int
ASN1_STRING_type
(const ASN1_STRING
*x);
DESCRIPTION
These functions manipulate ASN1_STRING structures.
ASN1_STRING_cmp
()
and
ASN1_OCTET_STRING_cmp
()
compare the type, the length, and the content of a and
b.
ASN1_STRING_data
()
is similar to ASN1_STRING_get0_data
() except that
the returned value is not constant. This function is deprecated.
Applications should use ASN1_STRING_get0_data
()
instead.
ASN1_STRING_dup
()
and
ASN1_OCTET_STRING_dup
()
copy a.
ASN1_STRING_get0_data
()
returns an internal pointer to the data of x. It
should not be freed or modified in any way.
ASN1_STRING_length
()
returns the length attribute of x, measured in
bytes.
ASN1_STRING_length_set
()
sets the length attribute of x to
len. It may put x into an
inconsistent internal state.
ASN1_STRING_set
()
and
ASN1_OCTET_STRING_set
()
set the length attribute of str to
len and copy that number of bytes from
data into str. If
len is -1, then
strlen
(data)
is used instead of len. If data
is NULL
, the content of str
remains uninitialized; that is not considered an error unless
len is negative.
ASN1_STRING_to_UTF8
()
converts the string in to UTF-8 format. The converted
data is copied into a newly allocated buffer *out. The
buffer *out should be freed using
free(3).
ASN1_STRING_type
()
returns the type of x.
Almost all ASN.1 types are represented as ASN1_STRING structures. Other types such as ASN1_OCTET_STRING are simply typedefed to ASN1_STRING and the functions call the ASN1_STRING equivalents. ASN1_STRING is also used for some CHOICE types which consist entirely of primitive string types such as DirectoryString and Time.
These functions should not be used to examine or modify ASN1_INTEGER or ASN1_ENUMERATED types: the relevant INTEGER or ENUMERATED utility functions should be used instead.
In general it cannot be assumed that
the data returned by
ASN1_STRING_get0_data
()
and ASN1_STRING_data
() is NUL terminated, and it may
contain embedded NUL characters. The format of the data depends on the
string type: for example for an IA5String the data
contains ASCII characters, for a BMPString two bytes
per character in big endian format, and for a
UTF8String UTF-8 characters.
Similar care should be taken to ensure the
data is in the correct format when calling
ASN1_STRING_set
().
RETURN VALUES
ASN1_STRING_cmp
() and
ASN1_OCTET_STRING_cmp
() return 0 if the type, the
length, and the content of a and
b agree, or a non-zero value otherwise. In contrast to
strcmp(3), the sign of the return value does not indicate
lexicographical ordering.
ASN1_STRING_data
() and
ASN1_STRING_get0_data
() return an internal pointer
to the data of x.
ASN1_STRING_dup
() and
ASN1_OCTET_STRING_dup
() return a pointer to a newly
allocated ASN1_STRING structure or
NULL
if an error occurred.
ASN1_STRING_length
() returns a number of
bytes.
ASN1_STRING_set
() and
ASN1_OCTET_STRING_set
() return 1 on success or 0 on
failure.
ASN1_STRING_to_UTF8
() returns the number
of bytes in the output buffer *out, or a negative
number if an error occurred.
ASN1_STRING_type
() returns an integer
constant, for example V_ASN1_OCTET_STRING
.
In some cases of failure of
ASN1_STRING_dup
(),
ASN1_STRING_set
(), and
ASN1_STRING_to_UTF8
(), the reason can be determined
with
ERR_get_error(3).
SEE ALSO
HISTORY
ASN1_STRING_cmp
(),
ASN1_STRING_dup
(),
ASN1_STRING_set
(), and
ASN1_OCTET_STRING_set
() first appeared in SSLeay
0.6.5. ASN1_OCTET_STRING_cmp
(),
ASN1_STRING_data
(),
ASN1_OCTET_STRING_dup
(), and
ASN1_STRING_type
() first appeared in SSLeay 0.8.0.
ASN1_STRING_length
() first appeared in SSLeay 0.9.0.
All these functions have been available since OpenBSD
2.4.
ASN1_STRING_length_set
() first appeared in
OpenSSL 0.9.5 and has been available since OpenBSD
2.7.
ASN1_STRING_to_UTF8
() first appeared in
OpenSSL 0.9.6 and has been available since OpenBSD
2.9.
ASN1_STRING_get0_data
() first appeared in
OpenSSL 1.1.0 and has been available since OpenBSD
6.3.