mbed TLS v2.16.7
asn1write.h
Go to the documentation of this file.
1 
6 /*
7  * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
8  * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
9  *
10  * This file is provided under the Apache License 2.0, or the
11  * GNU General Public License v2.0 or later.
12  *
13  * **********
14  * Apache License 2.0:
15  *
16  * Licensed under the Apache License, Version 2.0 (the "License"); you may
17  * not use this file except in compliance with the License.
18  * You may obtain a copy of the License at
19  *
20  * http://www.apache.org/licenses/LICENSE-2.0
21  *
22  * Unless required by applicable law or agreed to in writing, software
23  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
24  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25  * See the License for the specific language governing permissions and
26  * limitations under the License.
27  *
28  * **********
29  *
30  * **********
31  * GNU General Public License v2.0 or later:
32  *
33  * This program is free software; you can redistribute it and/or modify
34  * it under the terms of the GNU General Public License as published by
35  * the Free Software Foundation; either version 2 of the License, or
36  * (at your option) any later version.
37  *
38  * This program is distributed in the hope that it will be useful,
39  * but WITHOUT ANY WARRANTY; without even the implied warranty of
40  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
41  * GNU General Public License for more details.
42  *
43  * You should have received a copy of the GNU General Public License along
44  * with this program; if not, write to the Free Software Foundation, Inc.,
45  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
46  *
47  * **********
48  *
49  * This file is part of mbed TLS (https://tls.mbed.org)
50  */
51 #ifndef MBEDTLS_ASN1_WRITE_H
52 #define MBEDTLS_ASN1_WRITE_H
53 
54 #if !defined(MBEDTLS_CONFIG_FILE)
55 #include "config.h"
56 #else
57 #include MBEDTLS_CONFIG_FILE
58 #endif
59 
60 #include "asn1.h"
61 
62 #define MBEDTLS_ASN1_CHK_ADD(g, f) \
63  do \
64  { \
65  if( ( ret = (f) ) < 0 ) \
66  return( ret ); \
67  else \
68  (g) += ret; \
69  } while( 0 )
70 
71 #ifdef __cplusplus
72 extern "C" {
73 #endif
74 
87 int mbedtls_asn1_write_len( unsigned char **p, unsigned char *start,
88  size_t len );
101 int mbedtls_asn1_write_tag( unsigned char **p, unsigned char *start,
102  unsigned char tag );
103 
117 int mbedtls_asn1_write_raw_buffer( unsigned char **p, unsigned char *start,
118  const unsigned char *buf, size_t size );
119 
120 #if defined(MBEDTLS_BIGNUM_C)
121 
134 int mbedtls_asn1_write_mpi( unsigned char **p, unsigned char *start,
135  const mbedtls_mpi *X );
136 #endif /* MBEDTLS_BIGNUM_C */
137 
150 int mbedtls_asn1_write_null( unsigned char **p, unsigned char *start );
151 
166 int mbedtls_asn1_write_oid( unsigned char **p, unsigned char *start,
167  const char *oid, size_t oid_len );
168 
184 int mbedtls_asn1_write_algorithm_identifier( unsigned char **p,
185  unsigned char *start,
186  const char *oid, size_t oid_len,
187  size_t par_len );
188 
202 int mbedtls_asn1_write_bool( unsigned char **p, unsigned char *start,
203  int boolean );
204 
218 int mbedtls_asn1_write_int( unsigned char **p, unsigned char *start, int val );
219 
237 int mbedtls_asn1_write_tagged_string( unsigned char **p, unsigned char *start,
238  int tag, const char *text,
239  size_t text_len );
240 
256 int mbedtls_asn1_write_printable_string( unsigned char **p,
257  unsigned char *start,
258  const char *text, size_t text_len );
259 
275 int mbedtls_asn1_write_utf8_string( unsigned char **p, unsigned char *start,
276  const char *text, size_t text_len );
277 
293 int mbedtls_asn1_write_ia5_string( unsigned char **p, unsigned char *start,
294  const char *text, size_t text_len );
295 
310 int mbedtls_asn1_write_bitstring( unsigned char **p, unsigned char *start,
311  const unsigned char *buf, size_t bits );
312 
327 int mbedtls_asn1_write_octet_string( unsigned char **p, unsigned char *start,
328  const unsigned char *buf, size_t size );
329 
348  const char *oid, size_t oid_len,
349  const unsigned char *val,
350  size_t val_len );
351 
352 #ifdef __cplusplus
353 }
354 #endif
355 
356 #endif /* MBEDTLS_ASN1_WRITE_H */
int mbedtls_asn1_write_bitstring(unsigned char **p, unsigned char *start, const unsigned char *buf, size_t bits)
Write a bitstring tag (MBEDTLS_ASN1_BIT_STRING) and value in ASN.1 format.
mbedtls_asn1_buf oid
Definition: asn1.h:195
int mbedtls_asn1_write_null(unsigned char **p, unsigned char *start)
Write a NULL tag (MBEDTLS_ASN1_NULL) with zero data in ASN.1 format.
Configuration options (set of defines)
Generic ASN.1 parsing.
int mbedtls_asn1_write_int(unsigned char **p, unsigned char *start, int val)
Write an int tag (MBEDTLS_ASN1_INTEGER) and value in ASN.1 format.
int mbedtls_asn1_write_bool(unsigned char **p, unsigned char *start, int boolean)
Write a boolean tag (MBEDTLS_ASN1_BOOLEAN) and value in ASN.1 format.
int mbedtls_asn1_write_len(unsigned char **p, unsigned char *start, size_t len)
Write a length field in ASN.1 format.
mbedtls_asn1_buf val
Definition: asn1.h:196
int mbedtls_asn1_write_octet_string(unsigned char **p, unsigned char *start, const unsigned char *buf, size_t size)
Write an octet string tag (MBEDTLS_ASN1_OCTET_STRING) and value in ASN.1 format.
int mbedtls_asn1_write_utf8_string(unsigned char **p, unsigned char *start, const char *text, size_t text_len)
Write a UTF8 string in ASN.1 format using the UTF8String string encoding tag (MBEDTLS_ASN1_PRINTABLE_...
int mbedtls_asn1_write_mpi(unsigned char **p, unsigned char *start, const mbedtls_mpi *X)
Write a arbitrary-precision number (MBEDTLS_ASN1_INTEGER) in ASN.1 format.
int mbedtls_asn1_write_printable_string(unsigned char **p, unsigned char *start, const char *text, size_t text_len)
Write a string in ASN.1 format using the PrintableString string encoding tag (MBEDTLS_ASN1_PRINTABLE_...
int mbedtls_asn1_write_algorithm_identifier(unsigned char **p, unsigned char *start, const char *oid, size_t oid_len, size_t par_len)
Write an AlgorithmIdentifier sequence in ASN.1 format.
MPI structure.
Definition: bignum.h:212
mbedtls_asn1_named_data * mbedtls_asn1_store_named_data(mbedtls_asn1_named_data **list, const char *oid, size_t oid_len, const unsigned char *val, size_t val_len)
Create or find a specific named_data entry for writing in a sequence or list based on the OID...
int mbedtls_asn1_write_ia5_string(unsigned char **p, unsigned char *start, const char *text, size_t text_len)
Write a string in ASN.1 format using the IA5String string encoding tag (MBEDTLS_ASN1_IA5_STRING).
int mbedtls_asn1_write_raw_buffer(unsigned char **p, unsigned char *start, const unsigned char *buf, size_t size)
Write raw buffer data.
int mbedtls_asn1_write_tag(unsigned char **p, unsigned char *start, unsigned char tag)
Write an ASN.1 tag in ASN.1 format.
int mbedtls_asn1_write_oid(unsigned char **p, unsigned char *start, const char *oid, size_t oid_len)
Write an OID tag (MBEDTLS_ASN1_OID) and data in ASN.1 format.
int mbedtls_asn1_write_tagged_string(unsigned char **p, unsigned char *start, int tag, const char *text, size_t text_len)
Write a string in ASN.1 format using a specific string encoding tag.