blob: 0bce28ed132aaee466d46bf25aacc7de40fdc060 [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/*
Manuel Pégourié-Gonnard6fb81872015-07-27 11:11:48 +02007 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
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é-Gonnardfe446432015-03-06 13:17:10 +000022 * This file is part of mbed TLS (https://tls.mbed.org)
Paul Bakkerbdb912d2012-02-13 23:11:30 +000023 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020024#ifndef MBEDTLS_ASN1_WRITE_H
25#define MBEDTLS_ASN1_WRITE_H
Paul Bakkerbdb912d2012-02-13 23:11:30 +000026
Ron Eldor8b0cf2e2018-02-14 16:02:41 +020027#if !defined(MBEDTLS_CONFIG_FILE)
Jaeden Ameroc49fbbf2019-07-04 20:01:14 +010028#include "mbedtls/config.h"
Ron Eldor8b0cf2e2018-02-14 16:02:41 +020029#else
30#include MBEDTLS_CONFIG_FILE
31#endif
32
Jaeden Ameroc49fbbf2019-07-04 20:01:14 +010033#include "mbedtls/asn1.h"
Paul Bakkerbdb912d2012-02-13 23:11:30 +000034
Hanno Becker55177552018-10-24 12:29:53 +010035#define MBEDTLS_ASN1_CHK_ADD(g, f) \
Hanno Becker1eeca412018-10-15 12:01:35 +010036 do \
37 { \
38 if( ( ret = (f) ) < 0 ) \
Hanno Becker55177552018-10-24 12:29:53 +010039 return( ret ); \
40 else \
Hanno Becker1eeca412018-10-15 12:01:35 +010041 (g) += ret; \
Hanno Becker55177552018-10-24 12:29:53 +010042 } while( 0 )
Paul Bakkerbdb912d2012-02-13 23:11:30 +000043
Paul Bakker407a0da2013-06-27 14:29:21 +020044#ifdef __cplusplus
45extern "C" {
46#endif
47
Paul Bakker7accbce2013-08-26 17:34:53 +020048/**
Hanno Becker55177552018-10-24 12:29:53 +010049 * \brief Write a length field in ASN.1 format.
Paul Bakker7accbce2013-08-26 17:34:53 +020050 *
Hanno Becker55177552018-10-24 12:29:53 +010051 * \note This function works backwards in data buffer.
Paul Bakker7accbce2013-08-26 17:34:53 +020052 *
Hanno Becker55177552018-10-24 12:29:53 +010053 * \param p The reference to the current position pointer.
54 * \param start The start of the buffer, for bounds-checking.
55 * \param len The length value to write.
56 *
57 * \return The number of bytes written to \p p on success.
58 * \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure.
Paul Bakker7accbce2013-08-26 17:34:53 +020059 */
Hanno Becker55177552018-10-24 12:29:53 +010060int mbedtls_asn1_write_len( unsigned char **p, unsigned char *start,
61 size_t len );
Paul Bakker7accbce2013-08-26 17:34:53 +020062/**
Hanno Becker55177552018-10-24 12:29:53 +010063 * \brief Write an ASN.1 tag in ASN.1 format.
Paul Bakker7accbce2013-08-26 17:34:53 +020064 *
Hanno Becker55177552018-10-24 12:29:53 +010065 * \note This function works backwards in data buffer.
Paul Bakker7accbce2013-08-26 17:34:53 +020066 *
Hanno Becker55177552018-10-24 12:29:53 +010067 * \param p The reference to the current position pointer.
68 * \param start The start of the buffer, for bounds-checking.
69 * \param tag The tag to write.
70 *
71 * \return The number of bytes written to \p p on success.
72 * \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure.
Paul Bakker7accbce2013-08-26 17:34:53 +020073 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020074int mbedtls_asn1_write_tag( unsigned char **p, unsigned char *start,
Hanno Becker55177552018-10-24 12:29:53 +010075 unsigned char tag );
Paul Bakker7accbce2013-08-26 17:34:53 +020076
Paul Bakker9852d002013-08-26 17:56:37 +020077/**
Hanno Becker55177552018-10-24 12:29:53 +010078 * \brief Write raw buffer data.
Paul Bakker9852d002013-08-26 17:56:37 +020079 *
Hanno Becker55177552018-10-24 12:29:53 +010080 * \note This function works backwards in data buffer.
Paul Bakker9852d002013-08-26 17:56:37 +020081 *
Hanno Becker55177552018-10-24 12:29:53 +010082 * \param p The reference to the current position pointer.
83 * \param start The start of the buffer, for bounds-checking.
84 * \param buf The data buffer to write.
85 * \param size The length of the data buffer.
86 *
87 * \return The number of bytes written to \p p on success.
88 * \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure.
Paul Bakker9852d002013-08-26 17:56:37 +020089 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020090int mbedtls_asn1_write_raw_buffer( unsigned char **p, unsigned char *start,
Hanno Becker55177552018-10-24 12:29:53 +010091 const unsigned char *buf, size_t size );
Paul Bakker9852d002013-08-26 17:56:37 +020092
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020093#if defined(MBEDTLS_BIGNUM_C)
Paul Bakker7accbce2013-08-26 17:34:53 +020094/**
Hanno Becker55177552018-10-24 12:29:53 +010095 * \brief Write a arbitrary-precision number (#MBEDTLS_ASN1_INTEGER)
96 * in ASN.1 format.
Paul Bakker7accbce2013-08-26 17:34:53 +020097 *
Hanno Becker55177552018-10-24 12:29:53 +010098 * \note This function works backwards in data buffer.
Paul Bakker7accbce2013-08-26 17:34:53 +020099 *
Hanno Becker55177552018-10-24 12:29:53 +0100100 * \param p The reference to the current position pointer.
101 * \param start The start of the buffer, for bounds-checking.
102 * \param X The MPI to write.
Gilles Peskine105031b2019-03-01 19:28:41 +0100103 * It must be non-negative.
Hanno Becker55177552018-10-24 12:29:53 +0100104 *
105 * \return The number of bytes written to \p p on success.
106 * \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure.
Paul Bakker7accbce2013-08-26 17:34:53 +0200107 */
Hanno Becker55177552018-10-24 12:29:53 +0100108int mbedtls_asn1_write_mpi( unsigned char **p, unsigned char *start,
109 const mbedtls_mpi *X );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200110#endif /* MBEDTLS_BIGNUM_C */
Paul Bakker7accbce2013-08-26 17:34:53 +0200111
112/**
Hanno Becker55177552018-10-24 12:29:53 +0100113 * \brief Write a NULL tag (#MBEDTLS_ASN1_NULL) with zero data
114 * in ASN.1 format.
Paul Bakker7accbce2013-08-26 17:34:53 +0200115 *
Hanno Becker55177552018-10-24 12:29:53 +0100116 * \note This function works backwards in data buffer.
Paul Bakker7accbce2013-08-26 17:34:53 +0200117 *
Hanno Becker55177552018-10-24 12:29:53 +0100118 * \param p The reference to the current position pointer.
119 * \param start The start of the buffer, for bounds-checking.
120 *
121 * \return The number of bytes written to \p p on success.
122 * \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure.
Paul Bakker7accbce2013-08-26 17:34:53 +0200123 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200124int mbedtls_asn1_write_null( unsigned char **p, unsigned char *start );
Paul Bakker7accbce2013-08-26 17:34:53 +0200125
126/**
Hanno Becker55177552018-10-24 12:29:53 +0100127 * \brief Write an OID tag (#MBEDTLS_ASN1_OID) and data
128 * in ASN.1 format.
Paul Bakker7accbce2013-08-26 17:34:53 +0200129 *
Hanno Becker55177552018-10-24 12:29:53 +0100130 * \note This function works backwards in data buffer.
Paul Bakker7accbce2013-08-26 17:34:53 +0200131 *
Hanno Becker55177552018-10-24 12:29:53 +0100132 * \param p The reference to the current position pointer.
133 * \param start The start of the buffer, for bounds-checking.
134 * \param oid The OID to write.
135 * \param oid_len The length of the OID.
136 *
137 * \return The number of bytes written to \p p on success.
138 * \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure.
Paul Bakker7accbce2013-08-26 17:34:53 +0200139 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200140int mbedtls_asn1_write_oid( unsigned char **p, unsigned char *start,
Hanno Becker55177552018-10-24 12:29:53 +0100141 const char *oid, size_t oid_len );
Paul Bakker7accbce2013-08-26 17:34:53 +0200142
143/**
Hanno Becker55177552018-10-24 12:29:53 +0100144 * \brief Write an AlgorithmIdentifier sequence in ASN.1 format.
Paul Bakker7accbce2013-08-26 17:34:53 +0200145 *
Hanno Becker55177552018-10-24 12:29:53 +0100146 * \note This function works backwards in data buffer.
147 *
148 * \param p The reference to the current position pointer.
149 * \param start The start of the buffer, for bounds-checking.
150 * \param oid The OID of the algorithm to write.
151 * \param oid_len The length of the algorithm's OID.
152 * \param par_len The length of the parameters, which must be already written.
Manuel Pégourié-Gonnardedda9042013-09-12 02:17:54 +0200153 * If 0, NULL parameters are added
Paul Bakker7accbce2013-08-26 17:34:53 +0200154 *
Hanno Becker55177552018-10-24 12:29:53 +0100155 * \return The number of bytes written to \p p on success.
156 * \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure.
Paul Bakker7accbce2013-08-26 17:34:53 +0200157 */
Hanno Becker55177552018-10-24 12:29:53 +0100158int mbedtls_asn1_write_algorithm_identifier( unsigned char **p,
159 unsigned char *start,
160 const char *oid, size_t oid_len,
161 size_t par_len );
Paul Bakker7accbce2013-08-26 17:34:53 +0200162
163/**
Hanno Becker55177552018-10-24 12:29:53 +0100164 * \brief Write a boolean tag (#MBEDTLS_ASN1_BOOLEAN) and value
165 * in ASN.1 format.
Paul Bakker329def32013-09-06 16:34:38 +0200166 *
Hanno Becker55177552018-10-24 12:29:53 +0100167 * \note This function works backwards in data buffer.
Paul Bakker329def32013-09-06 16:34:38 +0200168 *
Hanno Becker55177552018-10-24 12:29:53 +0100169 * \param p The reference to the current position pointer.
170 * \param start The start of the buffer, for bounds-checking.
171 * \param boolean The boolean value to write, either \c 0 or \c 1.
172 *
173 * \return The number of bytes written to \p p on success.
174 * \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure.
Paul Bakker329def32013-09-06 16:34:38 +0200175 */
Hanno Becker55177552018-10-24 12:29:53 +0100176int mbedtls_asn1_write_bool( unsigned char **p, unsigned char *start,
177 int boolean );
Paul Bakker329def32013-09-06 16:34:38 +0200178
179/**
Hanno Becker55177552018-10-24 12:29:53 +0100180 * \brief Write an int tag (#MBEDTLS_ASN1_INTEGER) and value
181 * in ASN.1 format.
Paul Bakker7accbce2013-08-26 17:34:53 +0200182 *
Hanno Becker55177552018-10-24 12:29:53 +0100183 * \note This function works backwards in data buffer.
Paul Bakker7accbce2013-08-26 17:34:53 +0200184 *
Hanno Becker55177552018-10-24 12:29:53 +0100185 * \param p The reference to the current position pointer.
186 * \param start The start of the buffer, for bounds-checking.
187 * \param val The integer value to write.
Gilles Peskine105031b2019-03-01 19:28:41 +0100188 * It must be non-negative.
Hanno Becker55177552018-10-24 12:29:53 +0100189 *
190 * \return The number of bytes written to \p p on success.
191 * \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure.
Paul Bakker7accbce2013-08-26 17:34:53 +0200192 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200193int mbedtls_asn1_write_int( unsigned char **p, unsigned char *start, int val );
Paul Bakker7accbce2013-08-26 17:34:53 +0200194
195/**
Mykhailo Sopiha20180ca2019-10-29 15:58:10 +0200196 * \brief Write an enum tag (#MBEDTLS_ASN1_ENUMERATED) and value
197 * in ASN.1 format.
198 *
199 * \note This function works backwards in data buffer.
200 *
201 * \param p The reference to the current position pointer.
202 * \param start The start of the buffer, for bounds-checking.
203 * \param val The integer value to write.
204 *
205 * \return The number of bytes written to \p p on success.
206 * \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure.
207 */
208int mbedtls_asn1_write_enum( unsigned char **p, unsigned char *start, int val );
209
210/**
Hanno Beckerd0e21fb2018-10-08 14:41:31 +0100211 * \brief Write a string in ASN.1 format using a specific
212 * string encoding tag.
Hanno Becker55177552018-10-24 12:29:53 +0100213
214 * \note This function works backwards in data buffer.
Jaeden Amero23f954d2018-05-17 11:46:13 +0100215 *
Hanno Beckerd0e21fb2018-10-08 14:41:31 +0100216 * \param p The reference to the current position pointer.
Hanno Becker55177552018-10-24 12:29:53 +0100217 * \param start The start of the buffer, for bounds-checking.
Hanno Beckerd0e21fb2018-10-08 14:41:31 +0100218 * \param tag The string encoding tag to write, e.g.
219 * #MBEDTLS_ASN1_UTF8_STRING.
220 * \param text The string to write.
221 * \param text_len The length of \p text in bytes (which might
222 * be strictly larger than the number of characters).
Jaeden Amero23f954d2018-05-17 11:46:13 +0100223 *
Hanno Beckerd0e21fb2018-10-08 14:41:31 +0100224 * \return The number of bytes written to \p p on success.
225 * \return A negative error code on failure.
Jaeden Amero23f954d2018-05-17 11:46:13 +0100226 */
thomas-deeeba6c9b2018-09-19 09:10:37 +0200227int mbedtls_asn1_write_tagged_string( unsigned char **p, unsigned char *start,
Hanno Becker55177552018-10-24 12:29:53 +0100228 int tag, const char *text,
229 size_t text_len );
Paul Bakker7accbce2013-08-26 17:34:53 +0200230
231/**
Hanno Beckerd0e21fb2018-10-08 14:41:31 +0100232 * \brief Write a string in ASN.1 format using the PrintableString
233 * string encoding tag (#MBEDTLS_ASN1_PRINTABLE_STRING).
Hanno Becker55177552018-10-24 12:29:53 +0100234 *
235 * \note This function works backwards in data buffer.
Jaeden Amero23f954d2018-05-17 11:46:13 +0100236 *
Hanno Beckerd0e21fb2018-10-08 14:41:31 +0100237 * \param p The reference to the current position pointer.
Hanno Becker55177552018-10-24 12:29:53 +0100238 * \param start The start of the buffer, for bounds-checking.
Hanno Beckerd0e21fb2018-10-08 14:41:31 +0100239 * \param text The string to write.
240 * \param text_len The length of \p text in bytes (which might
241 * be strictly larger than the number of characters).
Jaeden Amero23f954d2018-05-17 11:46:13 +0100242 *
Hanno Beckerd0e21fb2018-10-08 14:41:31 +0100243 * \return The number of bytes written to \p p on success.
244 * \return A negative error code on failure.
245 */
246int mbedtls_asn1_write_printable_string( unsigned char **p,
247 unsigned char *start,
248 const char *text, size_t text_len );
249
250/**
251 * \brief Write a UTF8 string in ASN.1 format using the UTF8String
Gilles Peskine105031b2019-03-01 19:28:41 +0100252 * string encoding tag (#MBEDTLS_ASN1_UTF8_STRING).
Hanno Becker55177552018-10-24 12:29:53 +0100253 *
254 * \note This function works backwards in data buffer.
Hanno Beckerd0e21fb2018-10-08 14:41:31 +0100255 *
256 * \param p The reference to the current position pointer.
Hanno Becker55177552018-10-24 12:29:53 +0100257 * \param start The start of the buffer, for bounds-checking.
Hanno Beckerd0e21fb2018-10-08 14:41:31 +0100258 * \param text The string to write.
259 * \param text_len The length of \p text in bytes (which might
260 * be strictly larger than the number of characters).
261 *
262 * \return The number of bytes written to \p p on success.
263 * \return A negative error code on failure.
Jaeden Amero23f954d2018-05-17 11:46:13 +0100264 */
265int mbedtls_asn1_write_utf8_string( unsigned char **p, unsigned char *start,
Hanno Beckerd0e21fb2018-10-08 14:41:31 +0100266 const char *text, size_t text_len );
Jaeden Amero23f954d2018-05-17 11:46:13 +0100267
268/**
Hanno Becker55177552018-10-24 12:29:53 +0100269 * \brief Write a string in ASN.1 format using the IA5String
Hanno Beckerd0e21fb2018-10-08 14:41:31 +0100270 * string encoding tag (#MBEDTLS_ASN1_IA5_STRING).
Hanno Becker55177552018-10-24 12:29:53 +0100271 *
272 * \note This function works backwards in data buffer.
Paul Bakker7accbce2013-08-26 17:34:53 +0200273 *
Hanno Beckerd0e21fb2018-10-08 14:41:31 +0100274 * \param p The reference to the current position pointer.
Hanno Becker55177552018-10-24 12:29:53 +0100275 * \param start The start of the buffer, for bounds-checking.
Hanno Beckerd0e21fb2018-10-08 14:41:31 +0100276 * \param text The string to write.
277 * \param text_len The length of \p text in bytes (which might
278 * be strictly larger than the number of characters).
Paul Bakker7accbce2013-08-26 17:34:53 +0200279 *
Hanno Beckerd0e21fb2018-10-08 14:41:31 +0100280 * \return The number of bytes written to \p p on success.
281 * \return A negative error code on failure.
Paul Bakker7accbce2013-08-26 17:34:53 +0200282 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200283int mbedtls_asn1_write_ia5_string( unsigned char **p, unsigned char *start,
Hanno Beckerd0e21fb2018-10-08 14:41:31 +0100284 const char *text, size_t text_len );
Paul Bakker7accbce2013-08-26 17:34:53 +0200285
286/**
Hanno Becker55177552018-10-24 12:29:53 +0100287 * \brief Write a bitstring tag (#MBEDTLS_ASN1_BIT_STRING) and
288 * value in ASN.1 format.
Paul Bakker7accbce2013-08-26 17:34:53 +0200289 *
Hanno Becker55177552018-10-24 12:29:53 +0100290 * \note This function works backwards in data buffer.
Paul Bakker7accbce2013-08-26 17:34:53 +0200291 *
Hanno Becker55177552018-10-24 12:29:53 +0100292 * \param p The reference to the current position pointer.
293 * \param start The start of the buffer, for bounds-checking.
294 * \param buf The bitstring to write.
295 * \param bits The total number of bits in the bitstring.
296 *
297 * \return The number of bytes written to \p p on success.
298 * \return A negative error code on failure.
Paul Bakker7accbce2013-08-26 17:34:53 +0200299 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200300int mbedtls_asn1_write_bitstring( unsigned char **p, unsigned char *start,
Hanno Becker55177552018-10-24 12:29:53 +0100301 const unsigned char *buf, size_t bits );
Paul Bakker7accbce2013-08-26 17:34:53 +0200302
303/**
Andres Amaya Garciad8233f72018-10-08 19:44:55 +0100304 * \brief This function writes a named bitstring tag
305 * (#MBEDTLS_ASN1_BIT_STRING) and value in ASN.1 format.
Andres Amaya Garcia6e959142018-09-26 10:48:24 +0100306 *
Andres Amaya Garciad8233f72018-10-08 19:44:55 +0100307 * As stated in RFC 5280 Appendix B, trailing zeroes are
Andres Amaya Garcia6e959142018-09-26 10:48:24 +0100308 * omitted when encoding named bitstrings in DER.
309 *
Andres Amaya Garciad8233f72018-10-08 19:44:55 +0100310 * \note This function works backwards within the data buffer.
311 *
312 * \param p The reference to the current position pointer.
313 * \param start The start of the buffer which is used for bounds-checking.
314 * \param buf The bitstring to write.
Andres Amaya Garcia6e959142018-09-26 10:48:24 +0100315 * \param bits The total number of bits in the bitstring.
316 *
Andres Amaya Garciad8233f72018-10-08 19:44:55 +0100317 * \return The number of bytes written to \p p on success.
318 * \return A negative error code on failure.
Andres Amaya Garcia6e959142018-09-26 10:48:24 +0100319 */
320int mbedtls_asn1_write_named_bitstring( unsigned char **p,
321 unsigned char *start,
322 const unsigned char *buf,
323 size_t bits );
324
325/**
Hanno Becker55177552018-10-24 12:29:53 +0100326 * \brief Write an octet string tag (#MBEDTLS_ASN1_OCTET_STRING)
327 * and value in ASN.1 format.
Paul Bakker7accbce2013-08-26 17:34:53 +0200328 *
Hanno Becker55177552018-10-24 12:29:53 +0100329 * \note This function works backwards in data buffer.
Paul Bakker7accbce2013-08-26 17:34:53 +0200330 *
Hanno Becker55177552018-10-24 12:29:53 +0100331 * \param p The reference to the current position pointer.
332 * \param start The start of the buffer, for bounds-checking.
333 * \param buf The buffer holding the data to write.
334 * \param size The length of the data buffer \p buf.
335 *
336 * \return The number of bytes written to \p p on success.
337 * \return A negative error code on failure.
Paul Bakker7accbce2013-08-26 17:34:53 +0200338 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200339int mbedtls_asn1_write_octet_string( unsigned char **p, unsigned char *start,
Hanno Becker55177552018-10-24 12:29:53 +0100340 const unsigned char *buf, size_t size );
Paul Bakker59ba59f2013-09-09 11:26:00 +0200341
342/**
343 * \brief Create or find a specific named_data entry for writing in a
344 * sequence or list based on the OID. If not already in there,
345 * a new entry is added to the head of the list.
346 * Warning: Destructive behaviour for the val data!
347 *
Hanno Becker55177552018-10-24 12:29:53 +0100348 * \param list The pointer to the location of the head of the list to seek
349 * through (will be updated in case of a new entry).
350 * \param oid The OID to look for.
351 * \param oid_len The size of the OID.
Gilles Peskine09c0a232019-03-04 15:00:06 +0100352 * \param val The associated data to store. If this is \c NULL,
353 * no data is copied to the new or existing buffer.
Hanno Becker55177552018-10-24 12:29:53 +0100354 * \param val_len The minimum length of the data buffer needed.
Gilles Peskine09c0a232019-03-04 15:00:06 +0100355 * If this is 0, do not allocate a buffer for the associated
356 * data.
357 * If the OID was already present, enlarge, shrink or free
358 * the existing buffer to fit \p val_len.
Paul Bakker59ba59f2013-09-09 11:26:00 +0200359 *
Hanno Becker55177552018-10-24 12:29:53 +0100360 * \return A pointer to the new / existing entry on success.
361 * \return \c NULL if if there was a memory allocation error.
Paul Bakker59ba59f2013-09-09 11:26:00 +0200362 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200363mbedtls_asn1_named_data *mbedtls_asn1_store_named_data( mbedtls_asn1_named_data **list,
Paul Bakker59ba59f2013-09-09 11:26:00 +0200364 const char *oid, size_t oid_len,
365 const unsigned char *val,
366 size_t val_len );
367
Paul Bakker407a0da2013-06-27 14:29:21 +0200368#ifdef __cplusplus
369}
370#endif
371
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200372#endif /* MBEDTLS_ASN1_WRITE_H */