9f175f7336311773be70defa64763a0e44c7df96
[openssl.git] / doc / man3 / ASN1_TYPE_get.pod
1 =pod
2
3 =head1 NAME
4
5 ASN1_TYPE_get, ASN1_TYPE_set, ASN1_TYPE_set1, ASN1_TYPE_cmp, ASN1_TYPE_unpack_sequence, ASN1_TYPE_pack_sequence - ASN1_TYPE utility
6 functions
7
8 =head1 SYNOPSIS
9
10  #include <openssl/asn1.h>
11
12  int ASN1_TYPE_get(const ASN1_TYPE *a);
13  void ASN1_TYPE_set(ASN1_TYPE *a, int type, void *value);
14  int ASN1_TYPE_set1(ASN1_TYPE *a, int type, const void *value);
15  int ASN1_TYPE_cmp(const ASN1_TYPE *a, const ASN1_TYPE *b);
16
17  void *ASN1_TYPE_unpack_sequence(const ASN1_ITEM *it, const ASN1_TYPE *t);
18  ASN1_TYPE *ASN1_TYPE_pack_sequence(const ASN1_ITEM *it, void *s,
19                                     ASN1_TYPE **t);
20
21 =head1 DESCRIPTION
22
23 These functions allow an B<ASN1_TYPE> structure to be manipulated. The
24 B<ASN1_TYPE> structure can contain any ASN.1 type or constructed type
25 such as a SEQUENCE: it is effectively equivalent to the ASN.1 ANY type.
26
27 ASN1_TYPE_get() returns the type of I<a>.
28
29 ASN1_TYPE_set() sets the value of I<a> to I<type> and I<value>. This
30 function uses the pointer I<value> internally so it must B<not> be freed
31 up after the call.
32
33 ASN1_TYPE_set1() sets the value of I<a> to I<type> a copy of I<value>.
34
35 ASN1_TYPE_cmp() compares ASN.1 types I<a> and I<b> and returns 0 if
36 they are identical and non-zero otherwise.
37
38 ASN1_TYPE_unpack_sequence() attempts to parse the SEQUENCE present in
39 I<t> using the ASN.1 structure I<it>. If successful it returns a pointer
40 to the ASN.1 structure corresponding to I<it> which must be freed by the
41 caller. If it fails it return NULL.
42
43 ASN1_TYPE_pack_sequence() attempts to encode the ASN.1 structure I<s>
44 corresponding to I<it> into an B<ASN1_TYPE>. If successful the encoded
45 B<ASN1_TYPE> is returned. If I<t> and I<*t> are not NULL the encoded type
46 is written to I<t> overwriting any existing data. If I<t> is not NULL
47 but I<*t> is NULL the returned B<ASN1_TYPE> is written to I<*t>.
48
49 =head1 NOTES
50
51 The type and meaning of the I<value> parameter for ASN1_TYPE_set() and
52 ASN1_TYPE_set1() is determined by the I<type> parameter.
53 If I<type> is B<V_ASN1_NULL> I<value> is ignored. If I<type> is
54 B<V_ASN1_BOOLEAN>
55 then the boolean is set to TRUE if I<value> is not NULL. If I<type> is
56 B<V_ASN1_OBJECT> then value is an B<ASN1_OBJECT> structure. Otherwise I<type>
57 is and B<ASN1_STRING> structure. If I<type> corresponds to a primitive type
58 (or a string type) then the contents of the B<ASN1_STRING> contain the content
59 octets of the type. If I<type> corresponds to a constructed type or
60 a tagged type (B<V_ASN1_SEQUENCE>, B<V_ASN1_SET> or B<V_ASN1_OTHER>) then the
61 B<ASN1_STRING> contains the entire ASN.1 encoding verbatim (including tag and
62 length octets).
63
64 ASN1_TYPE_cmp() may not return zero if two types are equivalent but have
65 different encodings. For example the single content octet of the boolean TRUE
66 value under BER can have any non-zero encoding but ASN1_TYPE_cmp() will
67 only return zero if the values are the same.
68
69 If either or both of the parameters passed to ASN1_TYPE_cmp() is NULL the
70 return value is non-zero. Technically if both parameters are NULL the two
71 types could be absent OPTIONAL fields and so should match, however passing
72 NULL values could also indicate a programming error (for example an
73 unparseable type which returns NULL) for types which do B<not> match. So
74 applications should handle the case of two absent values separately.
75
76 =head1 RETURN VALUES
77
78 ASN1_TYPE_get() returns the type of the B<ASN1_TYPE> argument.
79
80 ASN1_TYPE_set() does not return a value.
81
82 ASN1_TYPE_set1() returns 1 for success and 0 for failure.
83
84 ASN1_TYPE_cmp() returns 0 if the types are identical and non-zero otherwise.
85
86 ASN1_TYPE_unpack_sequence() returns a pointer to an ASN.1 structure or
87 NULL on failure.
88
89 ASN1_TYPE_pack_sequence() return an B<ASN1_TYPE> structure if it succeeds or
90 NULL on failure.
91
92 =head1 COPYRIGHT
93
94 Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
95
96 Licensed under the Apache License 2.0 (the "License").  You may not use
97 this file except in compliance with the License.  You can obtain a copy
98 in the file LICENSE in the source distribution or at
99 L<https://www.openssl.org/source/license.html>.
100
101 =cut