blob: d60ca0daa9fb4b90cfd577030025e4fbb275d071 [file] [log] [blame]
Paul Bakkerbdb912d2012-02-13 23:11:30 +00001/**
2 * \file asn1write.h
3 *
4 * \brief ASN.1 buffer writing functionality
Darryl Greena40a1012018-01-05 15:33:17 +00005 */
6/*
Bence Szépkúti1e148272020-08-07 13:07:28 +02007 * Copyright The Mbed TLS Contributors
Manuel Pégourié-Gonnard37ff1402015-09-04 14:21:07 +02008 * SPDX-License-Identifier: Apache-2.0
9 *
10 * Licensed under the Apache License, Version 2.0 (the "License"); you may
11 * not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
13 *
14 * http://www.apache.org/licenses/LICENSE-2.0
15 *
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
18 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
Paul Bakkerbdb912d2012-02-13 23:11:30 +000021 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020022#ifndef MBEDTLS_ASN1_WRITE_H
23#define MBEDTLS_ASN1_WRITE_H
Paul Bakkerbdb912d2012-02-13 23:11:30 +000024
Bence Szépkútic662b362021-05-27 11:25:03 +020025#include "mbedtls/build_info.h"
Ron Eldor8b0cf2e2018-02-14 16:02:41 +020026
Jaeden Ameroc49fbbf2019-07-04 20:01:14 +010027#include "mbedtls/asn1.h"
Paul Bakkerbdb912d2012-02-13 23:11:30 +000028
Hanno Becker55177552018-10-24 12:29:53 +010029#define MBEDTLS_ASN1_CHK_ADD(g, f) \
Hanno Becker1eeca412018-10-15 12:01:35 +010030 do \
31 { \
32 if( ( ret = (f) ) < 0 ) \
Hanno Becker55177552018-10-24 12:29:53 +010033 return( ret ); \
34 else \
Hanno Becker1eeca412018-10-15 12:01:35 +010035 (g) += ret; \
Hanno Becker55177552018-10-24 12:29:53 +010036 } while( 0 )
Paul Bakkerbdb912d2012-02-13 23:11:30 +000037
Paul Bakker407a0da2013-06-27 14:29:21 +020038#ifdef __cplusplus
39extern "C" {
40#endif
41
Paul Bakker7accbce2013-08-26 17:34:53 +020042/**
Hanno Becker55177552018-10-24 12:29:53 +010043 * \brief Write a length field in ASN.1 format.
Paul Bakker7accbce2013-08-26 17:34:53 +020044 *
Hanno Becker55177552018-10-24 12:29:53 +010045 * \note This function works backwards in data buffer.
Paul Bakker7accbce2013-08-26 17:34:53 +020046 *
Hanno Becker55177552018-10-24 12:29:53 +010047 * \param p The reference to the current position pointer.
48 * \param start The start of the buffer, for bounds-checking.
49 * \param len The length value to write.
50 *
51 * \return The number of bytes written to \p p on success.
52 * \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure.
Paul Bakker7accbce2013-08-26 17:34:53 +020053 */
Mateusz Starzyk4e300d02021-01-27 15:37:12 +010054int mbedtls_asn1_write_len( unsigned char **p, const unsigned char *start,
Hanno Becker55177552018-10-24 12:29:53 +010055 size_t len );
Paul Bakker7accbce2013-08-26 17:34:53 +020056/**
Hanno Becker55177552018-10-24 12:29:53 +010057 * \brief Write an ASN.1 tag in ASN.1 format.
Paul Bakker7accbce2013-08-26 17:34:53 +020058 *
Hanno Becker55177552018-10-24 12:29:53 +010059 * \note This function works backwards in data buffer.
Paul Bakker7accbce2013-08-26 17:34:53 +020060 *
Hanno Becker55177552018-10-24 12:29:53 +010061 * \param p The reference to the current position pointer.
62 * \param start The start of the buffer, for bounds-checking.
63 * \param tag The tag to write.
64 *
65 * \return The number of bytes written to \p p on success.
66 * \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure.
Paul Bakker7accbce2013-08-26 17:34:53 +020067 */
Mateusz Starzyk4e300d02021-01-27 15:37:12 +010068int mbedtls_asn1_write_tag( unsigned char **p, const unsigned char *start,
Hanno Becker55177552018-10-24 12:29:53 +010069 unsigned char tag );
Paul Bakker7accbce2013-08-26 17:34:53 +020070
Paul Bakker9852d002013-08-26 17:56:37 +020071/**
Hanno Becker55177552018-10-24 12:29:53 +010072 * \brief Write raw buffer data.
Paul Bakker9852d002013-08-26 17:56:37 +020073 *
Hanno Becker55177552018-10-24 12:29:53 +010074 * \note This function works backwards in data buffer.
Paul Bakker9852d002013-08-26 17:56:37 +020075 *
Hanno Becker55177552018-10-24 12:29:53 +010076 * \param p The reference to the current position pointer.
77 * \param start The start of the buffer, for bounds-checking.
78 * \param buf The data buffer to write.
79 * \param size The length of the data buffer.
80 *
81 * \return The number of bytes written to \p p on success.
82 * \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure.
Paul Bakker9852d002013-08-26 17:56:37 +020083 */
Mateusz Starzyk4e300d02021-01-27 15:37:12 +010084int mbedtls_asn1_write_raw_buffer( unsigned char **p, const unsigned char *start,
Hanno Becker55177552018-10-24 12:29:53 +010085 const unsigned char *buf, size_t size );
Paul Bakker9852d002013-08-26 17:56:37 +020086
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020087#if defined(MBEDTLS_BIGNUM_C)
Paul Bakker7accbce2013-08-26 17:34:53 +020088/**
Hanno Becker55177552018-10-24 12:29:53 +010089 * \brief Write a arbitrary-precision number (#MBEDTLS_ASN1_INTEGER)
90 * in ASN.1 format.
Paul Bakker7accbce2013-08-26 17:34:53 +020091 *
Hanno Becker55177552018-10-24 12:29:53 +010092 * \note This function works backwards in data buffer.
Paul Bakker7accbce2013-08-26 17:34:53 +020093 *
Hanno Becker55177552018-10-24 12:29:53 +010094 * \param p The reference to the current position pointer.
95 * \param start The start of the buffer, for bounds-checking.
96 * \param X The MPI to write.
Gilles Peskine105031b2019-03-01 19:28:41 +010097 * It must be non-negative.
Hanno Becker55177552018-10-24 12:29:53 +010098 *
99 * \return The number of bytes written to \p p on success.
100 * \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure.
Paul Bakker7accbce2013-08-26 17:34:53 +0200101 */
Mateusz Starzyk4e300d02021-01-27 15:37:12 +0100102int mbedtls_asn1_write_mpi( unsigned char **p, const unsigned char *start,
Hanno Becker55177552018-10-24 12:29:53 +0100103 const mbedtls_mpi *X );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200104#endif /* MBEDTLS_BIGNUM_C */
Paul Bakker7accbce2013-08-26 17:34:53 +0200105
106/**
Hanno Becker55177552018-10-24 12:29:53 +0100107 * \brief Write a NULL tag (#MBEDTLS_ASN1_NULL) with zero data
108 * in ASN.1 format.
Paul Bakker7accbce2013-08-26 17:34:53 +0200109 *
Hanno Becker55177552018-10-24 12:29:53 +0100110 * \note This function works backwards in data buffer.
Paul Bakker7accbce2013-08-26 17:34:53 +0200111 *
Hanno Becker55177552018-10-24 12:29:53 +0100112 * \param p The reference to the current position pointer.
113 * \param start The start of the buffer, for bounds-checking.
114 *
115 * \return The number of bytes written to \p p on success.
116 * \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure.
Paul Bakker7accbce2013-08-26 17:34:53 +0200117 */
Mateusz Starzyk4e300d02021-01-27 15:37:12 +0100118int mbedtls_asn1_write_null( unsigned char **p, const unsigned char *start );
Paul Bakker7accbce2013-08-26 17:34:53 +0200119
120/**
Hanno Becker55177552018-10-24 12:29:53 +0100121 * \brief Write an OID tag (#MBEDTLS_ASN1_OID) and data
122 * in ASN.1 format.
Paul Bakker7accbce2013-08-26 17:34:53 +0200123 *
Hanno Becker55177552018-10-24 12:29:53 +0100124 * \note This function works backwards in data buffer.
Paul Bakker7accbce2013-08-26 17:34:53 +0200125 *
Hanno Becker55177552018-10-24 12:29:53 +0100126 * \param p The reference to the current position pointer.
127 * \param start The start of the buffer, for bounds-checking.
128 * \param oid The OID to write.
129 * \param oid_len The length of the OID.
130 *
131 * \return The number of bytes written to \p p on success.
132 * \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure.
Paul Bakker7accbce2013-08-26 17:34:53 +0200133 */
Mateusz Starzyk4e300d02021-01-27 15:37:12 +0100134int mbedtls_asn1_write_oid( unsigned char **p, const unsigned char *start,
Hanno Becker55177552018-10-24 12:29:53 +0100135 const char *oid, size_t oid_len );
Paul Bakker7accbce2013-08-26 17:34:53 +0200136
137/**
Hanno Becker55177552018-10-24 12:29:53 +0100138 * \brief Write an AlgorithmIdentifier sequence in ASN.1 format.
Paul Bakker7accbce2013-08-26 17:34:53 +0200139 *
Hanno Becker55177552018-10-24 12:29:53 +0100140 * \note This function works backwards in data buffer.
141 *
142 * \param p The reference to the current position pointer.
143 * \param start The start of the buffer, for bounds-checking.
144 * \param oid The OID of the algorithm to write.
145 * \param oid_len The length of the algorithm's OID.
146 * \param par_len The length of the parameters, which must be already written.
Manuel Pégourié-Gonnardedda9042013-09-12 02:17:54 +0200147 * If 0, NULL parameters are added
Paul Bakker7accbce2013-08-26 17:34:53 +0200148 *
Hanno Becker55177552018-10-24 12:29:53 +0100149 * \return The number of bytes written to \p p on success.
150 * \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure.
Paul Bakker7accbce2013-08-26 17:34:53 +0200151 */
Hanno Becker55177552018-10-24 12:29:53 +0100152int mbedtls_asn1_write_algorithm_identifier( unsigned char **p,
Mateusz Starzyk4e300d02021-01-27 15:37:12 +0100153 const unsigned char *start,
Hanno Becker55177552018-10-24 12:29:53 +0100154 const char *oid, size_t oid_len,
155 size_t par_len );
Paul Bakker7accbce2013-08-26 17:34:53 +0200156
157/**
Hanno Becker55177552018-10-24 12:29:53 +0100158 * \brief Write a boolean tag (#MBEDTLS_ASN1_BOOLEAN) and value
159 * in ASN.1 format.
Paul Bakker329def32013-09-06 16:34:38 +0200160 *
Hanno Becker55177552018-10-24 12:29:53 +0100161 * \note This function works backwards in data buffer.
Paul Bakker329def32013-09-06 16:34:38 +0200162 *
Hanno Becker55177552018-10-24 12:29:53 +0100163 * \param p The reference to the current position pointer.
164 * \param start The start of the buffer, for bounds-checking.
165 * \param boolean The boolean value to write, either \c 0 or \c 1.
166 *
167 * \return The number of bytes written to \p p on success.
168 * \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure.
Paul Bakker329def32013-09-06 16:34:38 +0200169 */
Mateusz Starzyk4e300d02021-01-27 15:37:12 +0100170int mbedtls_asn1_write_bool( unsigned char **p, const unsigned char *start,
Hanno Becker55177552018-10-24 12:29:53 +0100171 int boolean );
Paul Bakker329def32013-09-06 16:34:38 +0200172
173/**
Hanno Becker55177552018-10-24 12:29:53 +0100174 * \brief Write an int tag (#MBEDTLS_ASN1_INTEGER) and value
175 * in ASN.1 format.
Paul Bakker7accbce2013-08-26 17:34:53 +0200176 *
Hanno Becker55177552018-10-24 12:29:53 +0100177 * \note This function works backwards in data buffer.
Paul Bakker7accbce2013-08-26 17:34:53 +0200178 *
Hanno Becker55177552018-10-24 12:29:53 +0100179 * \param p The reference to the current position pointer.
180 * \param start The start of the buffer, for bounds-checking.
181 * \param val The integer value to write.
Gilles Peskine105031b2019-03-01 19:28:41 +0100182 * It must be non-negative.
Hanno Becker55177552018-10-24 12:29:53 +0100183 *
184 * \return The number of bytes written to \p p on success.
185 * \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure.
Paul Bakker7accbce2013-08-26 17:34:53 +0200186 */
Mateusz Starzyk4e300d02021-01-27 15:37:12 +0100187int mbedtls_asn1_write_int( unsigned char **p, const unsigned char *start, int val );
Paul Bakker7accbce2013-08-26 17:34:53 +0200188
189/**
Mykhailo Sopiha20180ca2019-10-29 15:58:10 +0200190 * \brief Write an enum tag (#MBEDTLS_ASN1_ENUMERATED) and value
191 * in ASN.1 format.
192 *
193 * \note This function works backwards in data buffer.
194 *
195 * \param p The reference to the current position pointer.
196 * \param start The start of the buffer, for bounds-checking.
197 * \param val The integer value to write.
198 *
199 * \return The number of bytes written to \p p on success.
200 * \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure.
201 */
Mateusz Starzyk4e300d02021-01-27 15:37:12 +0100202int mbedtls_asn1_write_enum( unsigned char **p, const unsigned char *start, int val );
Mykhailo Sopiha20180ca2019-10-29 15:58:10 +0200203
204/**
Hanno Beckerd0e21fb2018-10-08 14:41:31 +0100205 * \brief Write a string in ASN.1 format using a specific
206 * string encoding tag.
Hanno Becker55177552018-10-24 12:29:53 +0100207
208 * \note This function works backwards in data buffer.
Jaeden Amero23f954d2018-05-17 11:46:13 +0100209 *
Hanno Beckerd0e21fb2018-10-08 14:41:31 +0100210 * \param p The reference to the current position pointer.
Hanno Becker55177552018-10-24 12:29:53 +0100211 * \param start The start of the buffer, for bounds-checking.
Hanno Beckerd0e21fb2018-10-08 14:41:31 +0100212 * \param tag The string encoding tag to write, e.g.
213 * #MBEDTLS_ASN1_UTF8_STRING.
214 * \param text The string to write.
215 * \param text_len The length of \p text in bytes (which might
216 * be strictly larger than the number of characters).
Jaeden Amero23f954d2018-05-17 11:46:13 +0100217 *
Hanno Beckerd0e21fb2018-10-08 14:41:31 +0100218 * \return The number of bytes written to \p p on success.
219 * \return A negative error code on failure.
Jaeden Amero23f954d2018-05-17 11:46:13 +0100220 */
Mateusz Starzyk4e300d02021-01-27 15:37:12 +0100221int mbedtls_asn1_write_tagged_string( unsigned char **p, const unsigned char *start,
Hanno Becker55177552018-10-24 12:29:53 +0100222 int tag, const char *text,
223 size_t text_len );
Paul Bakker7accbce2013-08-26 17:34:53 +0200224
225/**
Hanno Beckerd0e21fb2018-10-08 14:41:31 +0100226 * \brief Write a string in ASN.1 format using the PrintableString
227 * string encoding tag (#MBEDTLS_ASN1_PRINTABLE_STRING).
Hanno Becker55177552018-10-24 12:29:53 +0100228 *
229 * \note This function works backwards in data buffer.
Jaeden Amero23f954d2018-05-17 11:46:13 +0100230 *
Hanno Beckerd0e21fb2018-10-08 14:41:31 +0100231 * \param p The reference to the current position pointer.
Hanno Becker55177552018-10-24 12:29:53 +0100232 * \param start The start of the buffer, for bounds-checking.
Hanno Beckerd0e21fb2018-10-08 14:41:31 +0100233 * \param text The string to write.
234 * \param text_len The length of \p text in bytes (which might
235 * be strictly larger than the number of characters).
Jaeden Amero23f954d2018-05-17 11:46:13 +0100236 *
Hanno Beckerd0e21fb2018-10-08 14:41:31 +0100237 * \return The number of bytes written to \p p on success.
238 * \return A negative error code on failure.
239 */
240int mbedtls_asn1_write_printable_string( unsigned char **p,
Mateusz Starzyk4e300d02021-01-27 15:37:12 +0100241 const unsigned char *start,
Hanno Beckerd0e21fb2018-10-08 14:41:31 +0100242 const char *text, size_t text_len );
243
244/**
245 * \brief Write a UTF8 string in ASN.1 format using the UTF8String
Gilles Peskine105031b2019-03-01 19:28:41 +0100246 * string encoding tag (#MBEDTLS_ASN1_UTF8_STRING).
Hanno Becker55177552018-10-24 12:29:53 +0100247 *
248 * \note This function works backwards in data buffer.
Hanno Beckerd0e21fb2018-10-08 14:41:31 +0100249 *
250 * \param p The reference to the current position pointer.
Hanno Becker55177552018-10-24 12:29:53 +0100251 * \param start The start of the buffer, for bounds-checking.
Hanno Beckerd0e21fb2018-10-08 14:41:31 +0100252 * \param text The string to write.
253 * \param text_len The length of \p text in bytes (which might
254 * be strictly larger than the number of characters).
255 *
256 * \return The number of bytes written to \p p on success.
257 * \return A negative error code on failure.
Jaeden Amero23f954d2018-05-17 11:46:13 +0100258 */
Mateusz Starzyk4e300d02021-01-27 15:37:12 +0100259int mbedtls_asn1_write_utf8_string( unsigned char **p, const unsigned char *start,
Hanno Beckerd0e21fb2018-10-08 14:41:31 +0100260 const char *text, size_t text_len );
Jaeden Amero23f954d2018-05-17 11:46:13 +0100261
262/**
Hanno Becker55177552018-10-24 12:29:53 +0100263 * \brief Write a string in ASN.1 format using the IA5String
Hanno Beckerd0e21fb2018-10-08 14:41:31 +0100264 * string encoding tag (#MBEDTLS_ASN1_IA5_STRING).
Hanno Becker55177552018-10-24 12:29:53 +0100265 *
266 * \note This function works backwards in data buffer.
Paul Bakker7accbce2013-08-26 17:34:53 +0200267 *
Hanno Beckerd0e21fb2018-10-08 14:41:31 +0100268 * \param p The reference to the current position pointer.
Hanno Becker55177552018-10-24 12:29:53 +0100269 * \param start The start of the buffer, for bounds-checking.
Hanno Beckerd0e21fb2018-10-08 14:41:31 +0100270 * \param text The string to write.
271 * \param text_len The length of \p text in bytes (which might
272 * be strictly larger than the number of characters).
Paul Bakker7accbce2013-08-26 17:34:53 +0200273 *
Hanno Beckerd0e21fb2018-10-08 14:41:31 +0100274 * \return The number of bytes written to \p p on success.
275 * \return A negative error code on failure.
Paul Bakker7accbce2013-08-26 17:34:53 +0200276 */
Mateusz Starzyk4e300d02021-01-27 15:37:12 +0100277int mbedtls_asn1_write_ia5_string( unsigned char **p, const unsigned char *start,
Hanno Beckerd0e21fb2018-10-08 14:41:31 +0100278 const char *text, size_t text_len );
Paul Bakker7accbce2013-08-26 17:34:53 +0200279
280/**
Hanno Becker55177552018-10-24 12:29:53 +0100281 * \brief Write a bitstring tag (#MBEDTLS_ASN1_BIT_STRING) and
282 * value in ASN.1 format.
Paul Bakker7accbce2013-08-26 17:34:53 +0200283 *
Hanno Becker55177552018-10-24 12:29:53 +0100284 * \note This function works backwards in data buffer.
Paul Bakker7accbce2013-08-26 17:34:53 +0200285 *
Hanno Becker55177552018-10-24 12:29:53 +0100286 * \param p The reference to the current position pointer.
287 * \param start The start of the buffer, for bounds-checking.
288 * \param buf The bitstring to write.
289 * \param bits The total number of bits in the bitstring.
290 *
291 * \return The number of bytes written to \p p on success.
292 * \return A negative error code on failure.
Paul Bakker7accbce2013-08-26 17:34:53 +0200293 */
Mateusz Starzyk4e300d02021-01-27 15:37:12 +0100294int mbedtls_asn1_write_bitstring( unsigned char **p, const unsigned char *start,
Hanno Becker55177552018-10-24 12:29:53 +0100295 const unsigned char *buf, size_t bits );
Paul Bakker7accbce2013-08-26 17:34:53 +0200296
297/**
Andres Amaya Garciad8233f72018-10-08 19:44:55 +0100298 * \brief This function writes a named bitstring tag
299 * (#MBEDTLS_ASN1_BIT_STRING) and value in ASN.1 format.
Andres Amaya Garcia6e959142018-09-26 10:48:24 +0100300 *
Andres Amaya Garciad8233f72018-10-08 19:44:55 +0100301 * As stated in RFC 5280 Appendix B, trailing zeroes are
Andres Amaya Garcia6e959142018-09-26 10:48:24 +0100302 * omitted when encoding named bitstrings in DER.
303 *
Andres Amaya Garciad8233f72018-10-08 19:44:55 +0100304 * \note This function works backwards within the data buffer.
305 *
306 * \param p The reference to the current position pointer.
307 * \param start The start of the buffer which is used for bounds-checking.
308 * \param buf The bitstring to write.
Andres Amaya Garcia6e959142018-09-26 10:48:24 +0100309 * \param bits The total number of bits in the bitstring.
310 *
Andres Amaya Garciad8233f72018-10-08 19:44:55 +0100311 * \return The number of bytes written to \p p on success.
312 * \return A negative error code on failure.
Andres Amaya Garcia6e959142018-09-26 10:48:24 +0100313 */
314int mbedtls_asn1_write_named_bitstring( unsigned char **p,
Mateusz Starzyk4e300d02021-01-27 15:37:12 +0100315 const unsigned char *start,
Andres Amaya Garcia6e959142018-09-26 10:48:24 +0100316 const unsigned char *buf,
317 size_t bits );
318
319/**
Hanno Becker55177552018-10-24 12:29:53 +0100320 * \brief Write an octet string tag (#MBEDTLS_ASN1_OCTET_STRING)
321 * and value in ASN.1 format.
Paul Bakker7accbce2013-08-26 17:34:53 +0200322 *
Hanno Becker55177552018-10-24 12:29:53 +0100323 * \note This function works backwards in data buffer.
Paul Bakker7accbce2013-08-26 17:34:53 +0200324 *
Hanno Becker55177552018-10-24 12:29:53 +0100325 * \param p The reference to the current position pointer.
326 * \param start The start of the buffer, for bounds-checking.
327 * \param buf The buffer holding the data to write.
328 * \param size The length of the data buffer \p buf.
329 *
330 * \return The number of bytes written to \p p on success.
331 * \return A negative error code on failure.
Paul Bakker7accbce2013-08-26 17:34:53 +0200332 */
Mateusz Starzyk4e300d02021-01-27 15:37:12 +0100333int mbedtls_asn1_write_octet_string( unsigned char **p, const unsigned char *start,
Hanno Becker55177552018-10-24 12:29:53 +0100334 const unsigned char *buf, size_t size );
Paul Bakker59ba59f2013-09-09 11:26:00 +0200335
336/**
337 * \brief Create or find a specific named_data entry for writing in a
338 * sequence or list based on the OID. If not already in there,
339 * a new entry is added to the head of the list.
340 * Warning: Destructive behaviour for the val data!
341 *
Hanno Becker55177552018-10-24 12:29:53 +0100342 * \param list The pointer to the location of the head of the list to seek
343 * through (will be updated in case of a new entry).
344 * \param oid The OID to look for.
345 * \param oid_len The size of the OID.
Gilles Peskine09c0a232019-03-04 15:00:06 +0100346 * \param val The associated data to store. If this is \c NULL,
347 * no data is copied to the new or existing buffer.
Hanno Becker55177552018-10-24 12:29:53 +0100348 * \param val_len The minimum length of the data buffer needed.
Gilles Peskine09c0a232019-03-04 15:00:06 +0100349 * If this is 0, do not allocate a buffer for the associated
350 * data.
351 * If the OID was already present, enlarge, shrink or free
352 * the existing buffer to fit \p val_len.
Paul Bakker59ba59f2013-09-09 11:26:00 +0200353 *
Hanno Becker55177552018-10-24 12:29:53 +0100354 * \return A pointer to the new / existing entry on success.
355 * \return \c NULL if if there was a memory allocation error.
Paul Bakker59ba59f2013-09-09 11:26:00 +0200356 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200357mbedtls_asn1_named_data *mbedtls_asn1_store_named_data( mbedtls_asn1_named_data **list,
Paul Bakker59ba59f2013-09-09 11:26:00 +0200358 const char *oid, size_t oid_len,
359 const unsigned char *val,
360 size_t val_len );
361
Paul Bakker407a0da2013-06-27 14:29:21 +0200362#ifdef __cplusplus
363}
364#endif
365
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200366#endif /* MBEDTLS_ASN1_WRITE_H */