blob: a12bf039befc9060f5027b21add16c38e1ef5ce5 [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
Dave Rodgman7ff79652023-11-03 12:04:52 +00008 * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
Paul Bakkerbdb912d2012-02-13 23:11:30 +00009 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020010#ifndef MBEDTLS_ASN1_WRITE_H
11#define MBEDTLS_ASN1_WRITE_H
Paul Bakkerbdb912d2012-02-13 23:11:30 +000012
Ron Eldor8b0cf2e2018-02-14 16:02:41 +020013#if !defined(MBEDTLS_CONFIG_FILE)
Jaeden Ameroc49fbbf2019-07-04 20:01:14 +010014#include "mbedtls/config.h"
Ron Eldor8b0cf2e2018-02-14 16:02:41 +020015#else
16#include MBEDTLS_CONFIG_FILE
17#endif
18
Jaeden Ameroc49fbbf2019-07-04 20:01:14 +010019#include "mbedtls/asn1.h"
Paul Bakkerbdb912d2012-02-13 23:11:30 +000020
Hanno Becker55177552018-10-24 12:29:53 +010021#define MBEDTLS_ASN1_CHK_ADD(g, f) \
Hanno Becker1eeca412018-10-15 12:01:35 +010022 do \
23 { \
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010024 if ((ret = (f)) < 0) \
25 return ret; \
Hanno Becker55177552018-10-24 12:29:53 +010026 else \
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010027 (g) += ret; \
28 } while (0)
Paul Bakkerbdb912d2012-02-13 23:11:30 +000029
Paul Bakker407a0da2013-06-27 14:29:21 +020030#ifdef __cplusplus
31extern "C" {
32#endif
33
Paul Bakker7accbce2013-08-26 17:34:53 +020034/**
Hanno Becker55177552018-10-24 12:29:53 +010035 * \brief Write a length field in ASN.1 format.
Paul Bakker7accbce2013-08-26 17:34:53 +020036 *
Hanno Becker55177552018-10-24 12:29:53 +010037 * \note This function works backwards in data buffer.
Paul Bakker7accbce2013-08-26 17:34:53 +020038 *
Hanno Becker55177552018-10-24 12:29:53 +010039 * \param p The reference to the current position pointer.
40 * \param start The start of the buffer, for bounds-checking.
41 * \param len The length value to write.
42 *
43 * \return The number of bytes written to \p p on success.
44 * \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure.
Paul Bakker7accbce2013-08-26 17:34:53 +020045 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010046int mbedtls_asn1_write_len(unsigned char **p, unsigned char *start,
47 size_t len);
Paul Bakker7accbce2013-08-26 17:34:53 +020048/**
Hanno Becker55177552018-10-24 12:29:53 +010049 * \brief Write an ASN.1 tag 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 tag The tag 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 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010060int mbedtls_asn1_write_tag(unsigned char **p, unsigned char *start,
61 unsigned char tag);
Paul Bakker7accbce2013-08-26 17:34:53 +020062
Paul Bakker9852d002013-08-26 17:56:37 +020063/**
Hanno Becker55177552018-10-24 12:29:53 +010064 * \brief Write raw buffer data.
Paul Bakker9852d002013-08-26 17:56:37 +020065 *
Hanno Becker55177552018-10-24 12:29:53 +010066 * \note This function works backwards in data buffer.
Paul Bakker9852d002013-08-26 17:56:37 +020067 *
Hanno Becker55177552018-10-24 12:29:53 +010068 * \param p The reference to the current position pointer.
69 * \param start The start of the buffer, for bounds-checking.
70 * \param buf The data buffer to write.
71 * \param size The length of the data buffer.
72 *
73 * \return The number of bytes written to \p p on success.
74 * \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure.
Paul Bakker9852d002013-08-26 17:56:37 +020075 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010076int mbedtls_asn1_write_raw_buffer(unsigned char **p, unsigned char *start,
77 const unsigned char *buf, size_t size);
Paul Bakker9852d002013-08-26 17:56:37 +020078
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020079#if defined(MBEDTLS_BIGNUM_C)
Paul Bakker7accbce2013-08-26 17:34:53 +020080/**
Tom Cosgrove5205c972022-07-28 06:12:08 +010081 * \brief Write an arbitrary-precision number (#MBEDTLS_ASN1_INTEGER)
Hanno Becker55177552018-10-24 12:29:53 +010082 * in ASN.1 format.
Paul Bakker7accbce2013-08-26 17:34:53 +020083 *
Hanno Becker55177552018-10-24 12:29:53 +010084 * \note This function works backwards in data buffer.
Paul Bakker7accbce2013-08-26 17:34:53 +020085 *
Hanno Becker55177552018-10-24 12:29:53 +010086 * \param p The reference to the current position pointer.
87 * \param start The start of the buffer, for bounds-checking.
88 * \param X The MPI to write.
Gilles Peskine105031b2019-03-01 19:28:41 +010089 * It must be non-negative.
Hanno Becker55177552018-10-24 12:29:53 +010090 *
91 * \return The number of bytes written to \p p on success.
92 * \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure.
Paul Bakker7accbce2013-08-26 17:34:53 +020093 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010094int mbedtls_asn1_write_mpi(unsigned char **p, unsigned char *start,
95 const mbedtls_mpi *X);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020096#endif /* MBEDTLS_BIGNUM_C */
Paul Bakker7accbce2013-08-26 17:34:53 +020097
98/**
Hanno Becker55177552018-10-24 12:29:53 +010099 * \brief Write a NULL tag (#MBEDTLS_ASN1_NULL) with zero data
100 * in ASN.1 format.
Paul Bakker7accbce2013-08-26 17:34:53 +0200101 *
Hanno Becker55177552018-10-24 12:29:53 +0100102 * \note This function works backwards in data buffer.
Paul Bakker7accbce2013-08-26 17:34:53 +0200103 *
Hanno Becker55177552018-10-24 12:29:53 +0100104 * \param p The reference to the current position pointer.
105 * \param start The start of the buffer, for bounds-checking.
106 *
107 * \return The number of bytes written to \p p on success.
108 * \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure.
Paul Bakker7accbce2013-08-26 17:34:53 +0200109 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100110int mbedtls_asn1_write_null(unsigned char **p, unsigned char *start);
Paul Bakker7accbce2013-08-26 17:34:53 +0200111
112/**
Hanno Becker55177552018-10-24 12:29:53 +0100113 * \brief Write an OID tag (#MBEDTLS_ASN1_OID) and 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 * \param oid The OID to write.
121 * \param oid_len The length of the OID.
122 *
123 * \return The number of bytes written to \p p on success.
124 * \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure.
Paul Bakker7accbce2013-08-26 17:34:53 +0200125 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100126int mbedtls_asn1_write_oid(unsigned char **p, unsigned char *start,
127 const char *oid, size_t oid_len);
Paul Bakker7accbce2013-08-26 17:34:53 +0200128
129/**
Hanno Becker55177552018-10-24 12:29:53 +0100130 * \brief Write an AlgorithmIdentifier sequence in ASN.1 format.
Paul Bakker7accbce2013-08-26 17:34:53 +0200131 *
Hanno Becker55177552018-10-24 12:29:53 +0100132 * \note This function works backwards in data buffer.
133 *
134 * \param p The reference to the current position pointer.
135 * \param start The start of the buffer, for bounds-checking.
136 * \param oid The OID of the algorithm to write.
137 * \param oid_len The length of the algorithm's OID.
138 * \param par_len The length of the parameters, which must be already written.
Manuel Pégourié-Gonnardedda9042013-09-12 02:17:54 +0200139 * If 0, NULL parameters are added
Paul Bakker7accbce2013-08-26 17:34:53 +0200140 *
Hanno Becker55177552018-10-24 12:29:53 +0100141 * \return The number of bytes written to \p p on success.
142 * \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure.
Paul Bakker7accbce2013-08-26 17:34:53 +0200143 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100144int mbedtls_asn1_write_algorithm_identifier(unsigned char **p,
145 unsigned char *start,
146 const char *oid, size_t oid_len,
147 size_t par_len);
Paul Bakker7accbce2013-08-26 17:34:53 +0200148
149/**
Marek Janstaf5257c02023-07-31 14:49:38 +0200150 * \brief Write an AlgorithmIdentifier sequence in ASN.1 format.
151 *
152 * \note This function works backwards in data buffer.
153 *
154 * \param p The reference to the current position pointer.
155 * \param start The start of the buffer, for bounds-checking.
156 * \param oid The OID of the algorithm to write.
157 * \param oid_len The length of the algorithm's OID.
158 * \param par_len The length of the parameters, which must be already written.
159 * \param has_par If there are any parameters. If 0, par_len must be 0. If 1
160 * and \p par_len is 0, NULL parameters are added.
161 *
162 * \return The number of bytes written to \p p on success.
163 * \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure.
164 */
165int mbedtls_asn1_write_algorithm_identifier_ext(unsigned char **p,
166 unsigned char *start,
167 const char *oid, size_t oid_len,
168 size_t par_len, int has_par);
169
170/**
Hanno Becker55177552018-10-24 12:29:53 +0100171 * \brief Write a boolean tag (#MBEDTLS_ASN1_BOOLEAN) and value
172 * in ASN.1 format.
Paul Bakker329def32013-09-06 16:34:38 +0200173 *
Hanno Becker55177552018-10-24 12:29:53 +0100174 * \note This function works backwards in data buffer.
Paul Bakker329def32013-09-06 16:34:38 +0200175 *
Hanno Becker55177552018-10-24 12:29:53 +0100176 * \param p The reference to the current position pointer.
177 * \param start The start of the buffer, for bounds-checking.
178 * \param boolean The boolean value to write, either \c 0 or \c 1.
179 *
180 * \return The number of bytes written to \p p on success.
181 * \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure.
Paul Bakker329def32013-09-06 16:34:38 +0200182 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100183int mbedtls_asn1_write_bool(unsigned char **p, unsigned char *start,
184 int boolean);
Paul Bakker329def32013-09-06 16:34:38 +0200185
186/**
Hanno Becker55177552018-10-24 12:29:53 +0100187 * \brief Write an int tag (#MBEDTLS_ASN1_INTEGER) and value
188 * in ASN.1 format.
Paul Bakker7accbce2013-08-26 17:34:53 +0200189 *
Hanno Becker55177552018-10-24 12:29:53 +0100190 * \note This function works backwards in data buffer.
Paul Bakker7accbce2013-08-26 17:34:53 +0200191 *
Hanno Becker55177552018-10-24 12:29:53 +0100192 * \param p The reference to the current position pointer.
193 * \param start The start of the buffer, for bounds-checking.
194 * \param val The integer value to write.
Gilles Peskine105031b2019-03-01 19:28:41 +0100195 * It must be non-negative.
Hanno Becker55177552018-10-24 12:29:53 +0100196 *
197 * \return The number of bytes written to \p p on success.
198 * \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure.
Paul Bakker7accbce2013-08-26 17:34:53 +0200199 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100200int mbedtls_asn1_write_int(unsigned char **p, unsigned char *start, int val);
Paul Bakker7accbce2013-08-26 17:34:53 +0200201
202/**
Mykhailo Sopiha20180ca2019-10-29 15:58:10 +0200203 * \brief Write an enum tag (#MBEDTLS_ASN1_ENUMERATED) and value
204 * in ASN.1 format.
205 *
206 * \note This function works backwards in data buffer.
207 *
208 * \param p The reference to the current position pointer.
209 * \param start The start of the buffer, for bounds-checking.
210 * \param val The integer value to write.
211 *
212 * \return The number of bytes written to \p p on success.
213 * \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure.
214 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100215int mbedtls_asn1_write_enum(unsigned char **p, unsigned char *start, int val);
Mykhailo Sopiha20180ca2019-10-29 15:58:10 +0200216
217/**
Hanno Beckerd0e21fb2018-10-08 14:41:31 +0100218 * \brief Write a string in ASN.1 format using a specific
219 * string encoding tag.
Hanno Becker55177552018-10-24 12:29:53 +0100220
221 * \note This function works backwards in data buffer.
Jaeden Amero23f954d2018-05-17 11:46:13 +0100222 *
Hanno Beckerd0e21fb2018-10-08 14:41:31 +0100223 * \param p The reference to the current position pointer.
Hanno Becker55177552018-10-24 12:29:53 +0100224 * \param start The start of the buffer, for bounds-checking.
Hanno Beckerd0e21fb2018-10-08 14:41:31 +0100225 * \param tag The string encoding tag to write, e.g.
226 * #MBEDTLS_ASN1_UTF8_STRING.
227 * \param text The string to write.
228 * \param text_len The length of \p text in bytes (which might
229 * be strictly larger than the number of characters).
Jaeden Amero23f954d2018-05-17 11:46:13 +0100230 *
Hanno Beckerd0e21fb2018-10-08 14:41:31 +0100231 * \return The number of bytes written to \p p on success.
232 * \return A negative error code on failure.
Jaeden Amero23f954d2018-05-17 11:46:13 +0100233 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100234int mbedtls_asn1_write_tagged_string(unsigned char **p, unsigned char *start,
235 int tag, const char *text,
236 size_t text_len);
Paul Bakker7accbce2013-08-26 17:34:53 +0200237
238/**
Hanno Beckerd0e21fb2018-10-08 14:41:31 +0100239 * \brief Write a string in ASN.1 format using the PrintableString
240 * string encoding tag (#MBEDTLS_ASN1_PRINTABLE_STRING).
Hanno Becker55177552018-10-24 12:29:53 +0100241 *
242 * \note This function works backwards in data buffer.
Jaeden Amero23f954d2018-05-17 11:46:13 +0100243 *
Hanno Beckerd0e21fb2018-10-08 14:41:31 +0100244 * \param p The reference to the current position pointer.
Hanno Becker55177552018-10-24 12:29:53 +0100245 * \param start The start of the buffer, for bounds-checking.
Hanno Beckerd0e21fb2018-10-08 14:41:31 +0100246 * \param text The string to write.
247 * \param text_len The length of \p text in bytes (which might
248 * be strictly larger than the number of characters).
Jaeden Amero23f954d2018-05-17 11:46:13 +0100249 *
Hanno Beckerd0e21fb2018-10-08 14:41:31 +0100250 * \return The number of bytes written to \p p on success.
251 * \return A negative error code on failure.
252 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100253int mbedtls_asn1_write_printable_string(unsigned char **p,
254 unsigned char *start,
255 const char *text, size_t text_len);
Hanno Beckerd0e21fb2018-10-08 14:41:31 +0100256
257/**
258 * \brief Write a UTF8 string in ASN.1 format using the UTF8String
Gilles Peskine105031b2019-03-01 19:28:41 +0100259 * string encoding tag (#MBEDTLS_ASN1_UTF8_STRING).
Hanno Becker55177552018-10-24 12:29:53 +0100260 *
261 * \note This function works backwards in data buffer.
Hanno Beckerd0e21fb2018-10-08 14:41:31 +0100262 *
263 * \param p The reference to the current position pointer.
Hanno Becker55177552018-10-24 12:29:53 +0100264 * \param start The start of the buffer, for bounds-checking.
Hanno Beckerd0e21fb2018-10-08 14:41:31 +0100265 * \param text The string to write.
266 * \param text_len The length of \p text in bytes (which might
267 * be strictly larger than the number of characters).
268 *
269 * \return The number of bytes written to \p p on success.
270 * \return A negative error code on failure.
Jaeden Amero23f954d2018-05-17 11:46:13 +0100271 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100272int mbedtls_asn1_write_utf8_string(unsigned char **p, unsigned char *start,
273 const char *text, size_t text_len);
Jaeden Amero23f954d2018-05-17 11:46:13 +0100274
275/**
Hanno Becker55177552018-10-24 12:29:53 +0100276 * \brief Write a string in ASN.1 format using the IA5String
Hanno Beckerd0e21fb2018-10-08 14:41:31 +0100277 * string encoding tag (#MBEDTLS_ASN1_IA5_STRING).
Hanno Becker55177552018-10-24 12:29:53 +0100278 *
279 * \note This function works backwards in data buffer.
Paul Bakker7accbce2013-08-26 17:34:53 +0200280 *
Hanno Beckerd0e21fb2018-10-08 14:41:31 +0100281 * \param p The reference to the current position pointer.
Hanno Becker55177552018-10-24 12:29:53 +0100282 * \param start The start of the buffer, for bounds-checking.
Hanno Beckerd0e21fb2018-10-08 14:41:31 +0100283 * \param text The string to write.
284 * \param text_len The length of \p text in bytes (which might
285 * be strictly larger than the number of characters).
Paul Bakker7accbce2013-08-26 17:34:53 +0200286 *
Hanno Beckerd0e21fb2018-10-08 14:41:31 +0100287 * \return The number of bytes written to \p p on success.
288 * \return A negative error code on failure.
Paul Bakker7accbce2013-08-26 17:34:53 +0200289 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100290int mbedtls_asn1_write_ia5_string(unsigned char **p, unsigned char *start,
291 const char *text, size_t text_len);
Paul Bakker7accbce2013-08-26 17:34:53 +0200292
293/**
Hanno Becker55177552018-10-24 12:29:53 +0100294 * \brief Write a bitstring tag (#MBEDTLS_ASN1_BIT_STRING) and
295 * value in ASN.1 format.
Paul Bakker7accbce2013-08-26 17:34:53 +0200296 *
Hanno Becker55177552018-10-24 12:29:53 +0100297 * \note This function works backwards in data buffer.
Paul Bakker7accbce2013-08-26 17:34:53 +0200298 *
Hanno Becker55177552018-10-24 12:29:53 +0100299 * \param p The reference to the current position pointer.
300 * \param start The start of the buffer, for bounds-checking.
301 * \param buf The bitstring to write.
302 * \param bits The total number of bits in the bitstring.
303 *
304 * \return The number of bytes written to \p p on success.
305 * \return A negative error code on failure.
Paul Bakker7accbce2013-08-26 17:34:53 +0200306 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100307int mbedtls_asn1_write_bitstring(unsigned char **p, unsigned char *start,
308 const unsigned char *buf, size_t bits);
Paul Bakker7accbce2013-08-26 17:34:53 +0200309
310/**
Andres Amaya Garciad8233f72018-10-08 19:44:55 +0100311 * \brief This function writes a named bitstring tag
312 * (#MBEDTLS_ASN1_BIT_STRING) and value in ASN.1 format.
Andres Amaya Garcia6e959142018-09-26 10:48:24 +0100313 *
Andres Amaya Garciad8233f72018-10-08 19:44:55 +0100314 * As stated in RFC 5280 Appendix B, trailing zeroes are
Andres Amaya Garcia6e959142018-09-26 10:48:24 +0100315 * omitted when encoding named bitstrings in DER.
316 *
Andres Amaya Garciad8233f72018-10-08 19:44:55 +0100317 * \note This function works backwards within the data buffer.
318 *
319 * \param p The reference to the current position pointer.
320 * \param start The start of the buffer which is used for bounds-checking.
321 * \param buf The bitstring to write.
Andres Amaya Garcia6e959142018-09-26 10:48:24 +0100322 * \param bits The total number of bits in the bitstring.
323 *
Andres Amaya Garciad8233f72018-10-08 19:44:55 +0100324 * \return The number of bytes written to \p p on success.
325 * \return A negative error code on failure.
Andres Amaya Garcia6e959142018-09-26 10:48:24 +0100326 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100327int mbedtls_asn1_write_named_bitstring(unsigned char **p,
328 unsigned char *start,
329 const unsigned char *buf,
330 size_t bits);
Andres Amaya Garcia6e959142018-09-26 10:48:24 +0100331
332/**
Hanno Becker55177552018-10-24 12:29:53 +0100333 * \brief Write an octet string tag (#MBEDTLS_ASN1_OCTET_STRING)
334 * and value in ASN.1 format.
Paul Bakker7accbce2013-08-26 17:34:53 +0200335 *
Hanno Becker55177552018-10-24 12:29:53 +0100336 * \note This function works backwards in data buffer.
Paul Bakker7accbce2013-08-26 17:34:53 +0200337 *
Hanno Becker55177552018-10-24 12:29:53 +0100338 * \param p The reference to the current position pointer.
339 * \param start The start of the buffer, for bounds-checking.
340 * \param buf The buffer holding the data to write.
341 * \param size The length of the data buffer \p buf.
342 *
343 * \return The number of bytes written to \p p on success.
344 * \return A negative error code on failure.
Paul Bakker7accbce2013-08-26 17:34:53 +0200345 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100346int mbedtls_asn1_write_octet_string(unsigned char **p, unsigned char *start,
347 const unsigned char *buf, size_t size);
Paul Bakker59ba59f2013-09-09 11:26:00 +0200348
349/**
350 * \brief Create or find a specific named_data entry for writing in a
351 * sequence or list based on the OID. If not already in there,
352 * a new entry is added to the head of the list.
353 * Warning: Destructive behaviour for the val data!
354 *
Hanno Becker55177552018-10-24 12:29:53 +0100355 * \param list The pointer to the location of the head of the list to seek
356 * through (will be updated in case of a new entry).
357 * \param oid The OID to look for.
358 * \param oid_len The size of the OID.
Gilles Peskine09c0a232019-03-04 15:00:06 +0100359 * \param val The associated data to store. If this is \c NULL,
360 * no data is copied to the new or existing buffer.
Hanno Becker55177552018-10-24 12:29:53 +0100361 * \param val_len The minimum length of the data buffer needed.
Gilles Peskine09c0a232019-03-04 15:00:06 +0100362 * If this is 0, do not allocate a buffer for the associated
363 * data.
364 * If the OID was already present, enlarge, shrink or free
365 * the existing buffer to fit \p val_len.
Paul Bakker59ba59f2013-09-09 11:26:00 +0200366 *
Hanno Becker55177552018-10-24 12:29:53 +0100367 * \return A pointer to the new / existing entry on success.
368 * \return \c NULL if if there was a memory allocation error.
Paul Bakker59ba59f2013-09-09 11:26:00 +0200369 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100370mbedtls_asn1_named_data *mbedtls_asn1_store_named_data(mbedtls_asn1_named_data **list,
371 const char *oid, size_t oid_len,
372 const unsigned char *val,
373 size_t val_len);
Paul Bakker59ba59f2013-09-09 11:26:00 +0200374
Paul Bakker407a0da2013-06-27 14:29:21 +0200375#ifdef __cplusplus
376}
377#endif
378
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200379#endif /* MBEDTLS_ASN1_WRITE_H */