blob: a439268b0ea6d00235fe1a827b493c27c89c83a8 [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
Ron Eldor8b0cf2e2018-02-14 16:02:41 +020025#if !defined(MBEDTLS_CONFIG_FILE)
Jaeden Ameroc49fbbf2019-07-04 20:01:14 +010026#include "mbedtls/config.h"
Ron Eldor8b0cf2e2018-02-14 16:02:41 +020027#else
28#include MBEDTLS_CONFIG_FILE
29#endif
30
Jaeden Ameroc49fbbf2019-07-04 20:01:14 +010031#include "mbedtls/asn1.h"
Paul Bakkerbdb912d2012-02-13 23:11:30 +000032
Hanno Becker55177552018-10-24 12:29:53 +010033#define MBEDTLS_ASN1_CHK_ADD(g, f) \
Hanno Becker1eeca412018-10-15 12:01:35 +010034 do \
35 { \
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010036 if ((ret = (f)) < 0) \
37 return ret; \
Hanno Becker55177552018-10-24 12:29:53 +010038 else \
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010039 (g) += ret; \
40 } while (0)
Paul Bakkerbdb912d2012-02-13 23:11:30 +000041
Paul Bakker407a0da2013-06-27 14:29:21 +020042#ifdef __cplusplus
43extern "C" {
44#endif
45
Paul Bakker7accbce2013-08-26 17:34:53 +020046/**
Hanno Becker55177552018-10-24 12:29:53 +010047 * \brief Write a length field in ASN.1 format.
Paul Bakker7accbce2013-08-26 17:34:53 +020048 *
Hanno Becker55177552018-10-24 12:29:53 +010049 * \note This function works backwards in data buffer.
Paul Bakker7accbce2013-08-26 17:34:53 +020050 *
Hanno Becker55177552018-10-24 12:29:53 +010051 * \param p The reference to the current position pointer.
52 * \param start The start of the buffer, for bounds-checking.
53 * \param len The length value to write.
54 *
55 * \return The number of bytes written to \p p on success.
56 * \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure.
Paul Bakker7accbce2013-08-26 17:34:53 +020057 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010058int mbedtls_asn1_write_len(unsigned char **p, unsigned char *start,
59 size_t len);
Paul Bakker7accbce2013-08-26 17:34:53 +020060/**
Hanno Becker55177552018-10-24 12:29:53 +010061 * \brief Write an ASN.1 tag in ASN.1 format.
Paul Bakker7accbce2013-08-26 17:34:53 +020062 *
Hanno Becker55177552018-10-24 12:29:53 +010063 * \note This function works backwards in data buffer.
Paul Bakker7accbce2013-08-26 17:34:53 +020064 *
Hanno Becker55177552018-10-24 12:29:53 +010065 * \param p The reference to the current position pointer.
66 * \param start The start of the buffer, for bounds-checking.
67 * \param tag The tag to write.
68 *
69 * \return The number of bytes written to \p p on success.
70 * \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure.
Paul Bakker7accbce2013-08-26 17:34:53 +020071 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010072int mbedtls_asn1_write_tag(unsigned char **p, unsigned char *start,
73 unsigned char tag);
Paul Bakker7accbce2013-08-26 17:34:53 +020074
Paul Bakker9852d002013-08-26 17:56:37 +020075/**
Hanno Becker55177552018-10-24 12:29:53 +010076 * \brief Write raw buffer data.
Paul Bakker9852d002013-08-26 17:56:37 +020077 *
Hanno Becker55177552018-10-24 12:29:53 +010078 * \note This function works backwards in data buffer.
Paul Bakker9852d002013-08-26 17:56:37 +020079 *
Hanno Becker55177552018-10-24 12:29:53 +010080 * \param p The reference to the current position pointer.
81 * \param start The start of the buffer, for bounds-checking.
82 * \param buf The data buffer to write.
83 * \param size The length of the data buffer.
84 *
85 * \return The number of bytes written to \p p on success.
86 * \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure.
Paul Bakker9852d002013-08-26 17:56:37 +020087 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010088int mbedtls_asn1_write_raw_buffer(unsigned char **p, unsigned char *start,
89 const unsigned char *buf, size_t size);
Paul Bakker9852d002013-08-26 17:56:37 +020090
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020091#if defined(MBEDTLS_BIGNUM_C)
Paul Bakker7accbce2013-08-26 17:34:53 +020092/**
Tom Cosgrove5205c972022-07-28 06:12:08 +010093 * \brief Write an arbitrary-precision number (#MBEDTLS_ASN1_INTEGER)
Hanno Becker55177552018-10-24 12:29:53 +010094 * in ASN.1 format.
Paul Bakker7accbce2013-08-26 17:34:53 +020095 *
Hanno Becker55177552018-10-24 12:29:53 +010096 * \note This function works backwards in data buffer.
Paul Bakker7accbce2013-08-26 17:34:53 +020097 *
Hanno Becker55177552018-10-24 12:29:53 +010098 * \param p The reference to the current position pointer.
99 * \param start The start of the buffer, for bounds-checking.
100 * \param X The MPI to write.
Gilles Peskine105031b2019-03-01 19:28:41 +0100101 * It must be non-negative.
Hanno Becker55177552018-10-24 12:29:53 +0100102 *
103 * \return The number of bytes written to \p p on success.
104 * \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure.
Paul Bakker7accbce2013-08-26 17:34:53 +0200105 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100106int mbedtls_asn1_write_mpi(unsigned char **p, unsigned char *start,
107 const mbedtls_mpi *X);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200108#endif /* MBEDTLS_BIGNUM_C */
Paul Bakker7accbce2013-08-26 17:34:53 +0200109
110/**
Hanno Becker55177552018-10-24 12:29:53 +0100111 * \brief Write a NULL tag (#MBEDTLS_ASN1_NULL) with zero data
112 * in ASN.1 format.
Paul Bakker7accbce2013-08-26 17:34:53 +0200113 *
Hanno Becker55177552018-10-24 12:29:53 +0100114 * \note This function works backwards in data buffer.
Paul Bakker7accbce2013-08-26 17:34:53 +0200115 *
Hanno Becker55177552018-10-24 12:29:53 +0100116 * \param p The reference to the current position pointer.
117 * \param start The start of the buffer, for bounds-checking.
118 *
119 * \return The number of bytes written to \p p on success.
120 * \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure.
Paul Bakker7accbce2013-08-26 17:34:53 +0200121 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100122int mbedtls_asn1_write_null(unsigned char **p, unsigned char *start);
Paul Bakker7accbce2013-08-26 17:34:53 +0200123
124/**
Hanno Becker55177552018-10-24 12:29:53 +0100125 * \brief Write an OID tag (#MBEDTLS_ASN1_OID) and data
126 * in ASN.1 format.
Paul Bakker7accbce2013-08-26 17:34:53 +0200127 *
Hanno Becker55177552018-10-24 12:29:53 +0100128 * \note This function works backwards in data buffer.
Paul Bakker7accbce2013-08-26 17:34:53 +0200129 *
Hanno Becker55177552018-10-24 12:29:53 +0100130 * \param p The reference to the current position pointer.
131 * \param start The start of the buffer, for bounds-checking.
132 * \param oid The OID to write.
133 * \param oid_len The length of the OID.
134 *
135 * \return The number of bytes written to \p p on success.
136 * \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure.
Paul Bakker7accbce2013-08-26 17:34:53 +0200137 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100138int mbedtls_asn1_write_oid(unsigned char **p, unsigned char *start,
139 const char *oid, size_t oid_len);
Paul Bakker7accbce2013-08-26 17:34:53 +0200140
141/**
Hanno Becker55177552018-10-24 12:29:53 +0100142 * \brief Write an AlgorithmIdentifier sequence in ASN.1 format.
Paul Bakker7accbce2013-08-26 17:34:53 +0200143 *
Hanno Becker55177552018-10-24 12:29:53 +0100144 * \note This function works backwards in data buffer.
145 *
146 * \param p The reference to the current position pointer.
147 * \param start The start of the buffer, for bounds-checking.
148 * \param oid The OID of the algorithm to write.
149 * \param oid_len The length of the algorithm's OID.
150 * \param par_len The length of the parameters, which must be already written.
Manuel Pégourié-Gonnardedda9042013-09-12 02:17:54 +0200151 * If 0, NULL parameters are added
Paul Bakker7accbce2013-08-26 17:34:53 +0200152 *
Hanno Becker55177552018-10-24 12:29:53 +0100153 * \return The number of bytes written to \p p on success.
154 * \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure.
Paul Bakker7accbce2013-08-26 17:34:53 +0200155 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100156int mbedtls_asn1_write_algorithm_identifier(unsigned char **p,
157 unsigned char *start,
158 const char *oid, size_t oid_len,
159 size_t par_len);
Paul Bakker7accbce2013-08-26 17:34:53 +0200160
161/**
Hanno Becker55177552018-10-24 12:29:53 +0100162 * \brief Write a boolean tag (#MBEDTLS_ASN1_BOOLEAN) and value
163 * in ASN.1 format.
Paul Bakker329def32013-09-06 16:34:38 +0200164 *
Hanno Becker55177552018-10-24 12:29:53 +0100165 * \note This function works backwards in data buffer.
Paul Bakker329def32013-09-06 16:34:38 +0200166 *
Hanno Becker55177552018-10-24 12:29:53 +0100167 * \param p The reference to the current position pointer.
168 * \param start The start of the buffer, for bounds-checking.
169 * \param boolean The boolean value to write, either \c 0 or \c 1.
170 *
171 * \return The number of bytes written to \p p on success.
172 * \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure.
Paul Bakker329def32013-09-06 16:34:38 +0200173 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100174int mbedtls_asn1_write_bool(unsigned char **p, unsigned char *start,
175 int boolean);
Paul Bakker329def32013-09-06 16:34:38 +0200176
177/**
Hanno Becker55177552018-10-24 12:29:53 +0100178 * \brief Write an int tag (#MBEDTLS_ASN1_INTEGER) and value
179 * in ASN.1 format.
Paul Bakker7accbce2013-08-26 17:34:53 +0200180 *
Hanno Becker55177552018-10-24 12:29:53 +0100181 * \note This function works backwards in data buffer.
Paul Bakker7accbce2013-08-26 17:34:53 +0200182 *
Hanno Becker55177552018-10-24 12:29:53 +0100183 * \param p The reference to the current position pointer.
184 * \param start The start of the buffer, for bounds-checking.
185 * \param val The integer value to write.
Gilles Peskine105031b2019-03-01 19:28:41 +0100186 * It must be non-negative.
Hanno Becker55177552018-10-24 12:29:53 +0100187 *
188 * \return The number of bytes written to \p p on success.
189 * \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure.
Paul Bakker7accbce2013-08-26 17:34:53 +0200190 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100191int mbedtls_asn1_write_int(unsigned char **p, unsigned char *start, int val);
Paul Bakker7accbce2013-08-26 17:34:53 +0200192
193/**
Mykhailo Sopiha20180ca2019-10-29 15:58:10 +0200194 * \brief Write an enum tag (#MBEDTLS_ASN1_ENUMERATED) and value
195 * in ASN.1 format.
196 *
197 * \note This function works backwards in data buffer.
198 *
199 * \param p The reference to the current position pointer.
200 * \param start The start of the buffer, for bounds-checking.
201 * \param val The integer value to write.
202 *
203 * \return The number of bytes written to \p p on success.
204 * \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure.
205 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100206int mbedtls_asn1_write_enum(unsigned char **p, unsigned char *start, int val);
Mykhailo Sopiha20180ca2019-10-29 15:58:10 +0200207
208/**
Hanno Beckerd0e21fb2018-10-08 14:41:31 +0100209 * \brief Write a string in ASN.1 format using a specific
210 * string encoding tag.
Hanno Becker55177552018-10-24 12:29:53 +0100211
212 * \note This function works backwards in data buffer.
Jaeden Amero23f954d2018-05-17 11:46:13 +0100213 *
Hanno Beckerd0e21fb2018-10-08 14:41:31 +0100214 * \param p The reference to the current position pointer.
Hanno Becker55177552018-10-24 12:29:53 +0100215 * \param start The start of the buffer, for bounds-checking.
Hanno Beckerd0e21fb2018-10-08 14:41:31 +0100216 * \param tag The string encoding tag to write, e.g.
217 * #MBEDTLS_ASN1_UTF8_STRING.
218 * \param text The string to write.
219 * \param text_len The length of \p text in bytes (which might
220 * be strictly larger than the number of characters).
Jaeden Amero23f954d2018-05-17 11:46:13 +0100221 *
Hanno Beckerd0e21fb2018-10-08 14:41:31 +0100222 * \return The number of bytes written to \p p on success.
223 * \return A negative error code on failure.
Jaeden Amero23f954d2018-05-17 11:46:13 +0100224 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100225int mbedtls_asn1_write_tagged_string(unsigned char **p, unsigned char *start,
226 int tag, const char *text,
227 size_t text_len);
Paul Bakker7accbce2013-08-26 17:34:53 +0200228
229/**
Hanno Beckerd0e21fb2018-10-08 14:41:31 +0100230 * \brief Write a string in ASN.1 format using the PrintableString
231 * string encoding tag (#MBEDTLS_ASN1_PRINTABLE_STRING).
Hanno Becker55177552018-10-24 12:29:53 +0100232 *
233 * \note This function works backwards in data buffer.
Jaeden Amero23f954d2018-05-17 11:46:13 +0100234 *
Hanno Beckerd0e21fb2018-10-08 14:41:31 +0100235 * \param p The reference to the current position pointer.
Hanno Becker55177552018-10-24 12:29:53 +0100236 * \param start The start of the buffer, for bounds-checking.
Hanno Beckerd0e21fb2018-10-08 14:41:31 +0100237 * \param text The string to write.
238 * \param text_len The length of \p text in bytes (which might
239 * be strictly larger than the number of characters).
Jaeden Amero23f954d2018-05-17 11:46:13 +0100240 *
Hanno Beckerd0e21fb2018-10-08 14:41:31 +0100241 * \return The number of bytes written to \p p on success.
242 * \return A negative error code on failure.
243 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100244int mbedtls_asn1_write_printable_string(unsigned char **p,
245 unsigned char *start,
246 const char *text, size_t text_len);
Hanno Beckerd0e21fb2018-10-08 14:41:31 +0100247
248/**
249 * \brief Write a UTF8 string in ASN.1 format using the UTF8String
Gilles Peskine105031b2019-03-01 19:28:41 +0100250 * string encoding tag (#MBEDTLS_ASN1_UTF8_STRING).
Hanno Becker55177552018-10-24 12:29:53 +0100251 *
252 * \note This function works backwards in data buffer.
Hanno Beckerd0e21fb2018-10-08 14:41:31 +0100253 *
254 * \param p The reference to the current position pointer.
Hanno Becker55177552018-10-24 12:29:53 +0100255 * \param start The start of the buffer, for bounds-checking.
Hanno Beckerd0e21fb2018-10-08 14:41:31 +0100256 * \param text The string to write.
257 * \param text_len The length of \p text in bytes (which might
258 * be strictly larger than the number of characters).
259 *
260 * \return The number of bytes written to \p p on success.
261 * \return A negative error code on failure.
Jaeden Amero23f954d2018-05-17 11:46:13 +0100262 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100263int mbedtls_asn1_write_utf8_string(unsigned char **p, unsigned char *start,
264 const char *text, size_t text_len);
Jaeden Amero23f954d2018-05-17 11:46:13 +0100265
266/**
Hanno Becker55177552018-10-24 12:29:53 +0100267 * \brief Write a string in ASN.1 format using the IA5String
Hanno Beckerd0e21fb2018-10-08 14:41:31 +0100268 * string encoding tag (#MBEDTLS_ASN1_IA5_STRING).
Hanno Becker55177552018-10-24 12:29:53 +0100269 *
270 * \note This function works backwards in data buffer.
Paul Bakker7accbce2013-08-26 17:34:53 +0200271 *
Hanno Beckerd0e21fb2018-10-08 14:41:31 +0100272 * \param p The reference to the current position pointer.
Hanno Becker55177552018-10-24 12:29:53 +0100273 * \param start The start of the buffer, for bounds-checking.
Hanno Beckerd0e21fb2018-10-08 14:41:31 +0100274 * \param text The string to write.
275 * \param text_len The length of \p text in bytes (which might
276 * be strictly larger than the number of characters).
Paul Bakker7accbce2013-08-26 17:34:53 +0200277 *
Hanno Beckerd0e21fb2018-10-08 14:41:31 +0100278 * \return The number of bytes written to \p p on success.
279 * \return A negative error code on failure.
Paul Bakker7accbce2013-08-26 17:34:53 +0200280 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100281int mbedtls_asn1_write_ia5_string(unsigned char **p, unsigned char *start,
282 const char *text, size_t text_len);
Paul Bakker7accbce2013-08-26 17:34:53 +0200283
284/**
Hanno Becker55177552018-10-24 12:29:53 +0100285 * \brief Write a bitstring tag (#MBEDTLS_ASN1_BIT_STRING) and
286 * value in ASN.1 format.
Paul Bakker7accbce2013-08-26 17:34:53 +0200287 *
Hanno Becker55177552018-10-24 12:29:53 +0100288 * \note This function works backwards in data buffer.
Paul Bakker7accbce2013-08-26 17:34:53 +0200289 *
Hanno Becker55177552018-10-24 12:29:53 +0100290 * \param p The reference to the current position pointer.
291 * \param start The start of the buffer, for bounds-checking.
292 * \param buf The bitstring to write.
293 * \param bits The total number of bits in the bitstring.
294 *
295 * \return The number of bytes written to \p p on success.
296 * \return A negative error code on failure.
Paul Bakker7accbce2013-08-26 17:34:53 +0200297 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100298int mbedtls_asn1_write_bitstring(unsigned char **p, unsigned char *start,
299 const unsigned char *buf, size_t bits);
Paul Bakker7accbce2013-08-26 17:34:53 +0200300
301/**
Andres Amaya Garciad8233f72018-10-08 19:44:55 +0100302 * \brief This function writes a named bitstring tag
303 * (#MBEDTLS_ASN1_BIT_STRING) and value in ASN.1 format.
Andres Amaya Garcia6e959142018-09-26 10:48:24 +0100304 *
Andres Amaya Garciad8233f72018-10-08 19:44:55 +0100305 * As stated in RFC 5280 Appendix B, trailing zeroes are
Andres Amaya Garcia6e959142018-09-26 10:48:24 +0100306 * omitted when encoding named bitstrings in DER.
307 *
Andres Amaya Garciad8233f72018-10-08 19:44:55 +0100308 * \note This function works backwards within the data buffer.
309 *
310 * \param p The reference to the current position pointer.
311 * \param start The start of the buffer which is used for bounds-checking.
312 * \param buf The bitstring to write.
Andres Amaya Garcia6e959142018-09-26 10:48:24 +0100313 * \param bits The total number of bits in the bitstring.
314 *
Andres Amaya Garciad8233f72018-10-08 19:44:55 +0100315 * \return The number of bytes written to \p p on success.
316 * \return A negative error code on failure.
Andres Amaya Garcia6e959142018-09-26 10:48:24 +0100317 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100318int mbedtls_asn1_write_named_bitstring(unsigned char **p,
319 unsigned char *start,
320 const unsigned char *buf,
321 size_t bits);
Andres Amaya Garcia6e959142018-09-26 10:48:24 +0100322
323/**
Hanno Becker55177552018-10-24 12:29:53 +0100324 * \brief Write an octet string tag (#MBEDTLS_ASN1_OCTET_STRING)
325 * and value in ASN.1 format.
Paul Bakker7accbce2013-08-26 17:34:53 +0200326 *
Hanno Becker55177552018-10-24 12:29:53 +0100327 * \note This function works backwards in data buffer.
Paul Bakker7accbce2013-08-26 17:34:53 +0200328 *
Hanno Becker55177552018-10-24 12:29:53 +0100329 * \param p The reference to the current position pointer.
330 * \param start The start of the buffer, for bounds-checking.
331 * \param buf The buffer holding the data to write.
332 * \param size The length of the data buffer \p buf.
333 *
334 * \return The number of bytes written to \p p on success.
335 * \return A negative error code on failure.
Paul Bakker7accbce2013-08-26 17:34:53 +0200336 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100337int mbedtls_asn1_write_octet_string(unsigned char **p, unsigned char *start,
338 const unsigned char *buf, size_t size);
Paul Bakker59ba59f2013-09-09 11:26:00 +0200339
340/**
341 * \brief Create or find a specific named_data entry for writing in a
342 * sequence or list based on the OID. If not already in there,
343 * a new entry is added to the head of the list.
344 * Warning: Destructive behaviour for the val data!
345 *
Hanno Becker55177552018-10-24 12:29:53 +0100346 * \param list The pointer to the location of the head of the list to seek
347 * through (will be updated in case of a new entry).
348 * \param oid The OID to look for.
349 * \param oid_len The size of the OID.
Gilles Peskine09c0a232019-03-04 15:00:06 +0100350 * \param val The associated data to store. If this is \c NULL,
351 * no data is copied to the new or existing buffer.
Hanno Becker55177552018-10-24 12:29:53 +0100352 * \param val_len The minimum length of the data buffer needed.
Gilles Peskine09c0a232019-03-04 15:00:06 +0100353 * If this is 0, do not allocate a buffer for the associated
354 * data.
355 * If the OID was already present, enlarge, shrink or free
356 * the existing buffer to fit \p val_len.
Paul Bakker59ba59f2013-09-09 11:26:00 +0200357 *
Hanno Becker55177552018-10-24 12:29:53 +0100358 * \return A pointer to the new / existing entry on success.
359 * \return \c NULL if if there was a memory allocation error.
Paul Bakker59ba59f2013-09-09 11:26:00 +0200360 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100361mbedtls_asn1_named_data *mbedtls_asn1_store_named_data(mbedtls_asn1_named_data **list,
362 const char *oid, size_t oid_len,
363 const unsigned char *val,
364 size_t val_len);
Paul Bakker59ba59f2013-09-09 11:26:00 +0200365
Paul Bakker407a0da2013-06-27 14:29:21 +0200366#ifdef __cplusplus
367}
368#endif
369
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200370#endif /* MBEDTLS_ASN1_WRITE_H */