Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
asn1write.h
00001 /** 00002 * \file asn1write.h 00003 * 00004 * \brief ASN.1 buffer writing functionality 00005 * 00006 * Copyright (C) 2006-2014, Brainspark B.V. 00007 * 00008 * This file is part of PolarSSL (http://www.polarssl.org) 00009 * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org> 00010 * 00011 * All rights reserved. 00012 * 00013 * This program is free software; you can redistribute it and/or modify 00014 * it under the terms of the GNU General Public License as published by 00015 * the Free Software Foundation; either version 2 of the License, or 00016 * (at your option) any later version. 00017 * 00018 * This program is distributed in the hope that it will be useful, 00019 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00020 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00021 * GNU General Public License for more details. 00022 * 00023 * You should have received a copy of the GNU General Public License along 00024 * with this program; if not, write to the Free Software Foundation, Inc., 00025 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 00026 */ 00027 #ifndef POLARSSL_ASN1_WRITE_H 00028 #define POLARSSL_ASN1_WRITE_H 00029 00030 #include "asn1.h" 00031 00032 #define ASN1_CHK_ADD(g, f) do { if( ( ret = f ) < 0 ) return( ret ); else \ 00033 g += ret; } while( 0 ) 00034 00035 #ifdef __cplusplus 00036 extern "C" { 00037 #endif 00038 00039 /** 00040 * \brief Write a length field in ASN.1 format 00041 * Note: function works backwards in data buffer 00042 * 00043 * \param p reference to current position pointer 00044 * \param start start of the buffer (for bounds-checking) 00045 * \param len the length to write 00046 * 00047 * \return the length written or a negative error code 00048 */ 00049 int asn1_write_len( unsigned char **p, unsigned char *start, size_t len ); 00050 00051 /** 00052 * \brief Write a ASN.1 tag in ASN.1 format 00053 * Note: function works backwards in data buffer 00054 * 00055 * \param p reference to current position pointer 00056 * \param start start of the buffer (for bounds-checking) 00057 * \param tag the tag to write 00058 * 00059 * \return the length written or a negative error code 00060 */ 00061 int asn1_write_tag( unsigned char **p, unsigned char *start, 00062 unsigned char tag ); 00063 00064 /** 00065 * \brief Write raw buffer data 00066 * Note: function works backwards in data buffer 00067 * 00068 * \param p reference to current position pointer 00069 * \param start start of the buffer (for bounds-checking) 00070 * \param buf data buffer to write 00071 * \param size length of the data buffer 00072 * 00073 * \return the length written or a negative error code 00074 */ 00075 int asn1_write_raw_buffer( unsigned char **p, unsigned char *start, 00076 const unsigned char *buf, size_t size ); 00077 00078 #if defined(POLARSSL_BIGNUM_C) 00079 /** 00080 * \brief Write a big number (ASN1_INTEGER) in ASN.1 format 00081 * Note: function works backwards in data buffer 00082 * 00083 * \param p reference to current position pointer 00084 * \param start start of the buffer (for bounds-checking) 00085 * \param X the MPI to write 00086 * 00087 * \return the length written or a negative error code 00088 */ 00089 int asn1_write_mpi( unsigned char **p, unsigned char *start, mpi *X ); 00090 #endif /* POLARSSL_BIGNUM_C */ 00091 00092 /** 00093 * \brief Write a NULL tag (ASN1_NULL) with zero data in ASN.1 format 00094 * Note: function works backwards in data buffer 00095 * 00096 * \param p reference to current position pointer 00097 * \param start start of the buffer (for bounds-checking) 00098 * 00099 * \return the length written or a negative error code 00100 */ 00101 int asn1_write_null( unsigned char **p, unsigned char *start ); 00102 00103 /** 00104 * \brief Write an OID tag (ASN1_OID) and data in ASN.1 format 00105 * Note: function works backwards in data buffer 00106 * 00107 * \param p reference to current position pointer 00108 * \param start start of the buffer (for bounds-checking) 00109 * \param oid the OID to write 00110 * \param oid_len length of the OID 00111 * 00112 * \return the length written or a negative error code 00113 */ 00114 int asn1_write_oid( unsigned char **p, unsigned char *start, 00115 const char *oid, size_t oid_len ); 00116 00117 /** 00118 * \brief Write an AlgorithmIdentifier sequence in ASN.1 format 00119 * Note: function works backwards in data buffer 00120 * 00121 * \param p reference to current position pointer 00122 * \param start start of the buffer (for bounds-checking) 00123 * \param oid the OID of the algorithm 00124 * \param oid_len length of the OID 00125 * \param par_len length of parameters, which must be already written. 00126 * If 0, NULL parameters are added 00127 * 00128 * \return the length written or a negative error code 00129 */ 00130 int asn1_write_algorithm_identifier( unsigned char **p, unsigned char *start, 00131 const char *oid, size_t oid_len, 00132 size_t par_len ); 00133 00134 /** 00135 * \brief Write a boolean tag (ASN1_BOOLEAN) and value in ASN.1 format 00136 * Note: function works backwards in data buffer 00137 * 00138 * \param p reference to current position pointer 00139 * \param start start of the buffer (for bounds-checking) 00140 * \param boolean 0 or 1 00141 * 00142 * \return the length written or a negative error code 00143 */ 00144 int asn1_write_bool( unsigned char **p, unsigned char *start, int boolean ); 00145 00146 /** 00147 * \brief Write an int tag (ASN1_INTEGER) and value in ASN.1 format 00148 * Note: function works backwards in data buffer 00149 * 00150 * \param p reference to current position pointer 00151 * \param start start of the buffer (for bounds-checking) 00152 * \param val the integer value 00153 * 00154 * \return the length written or a negative error code 00155 */ 00156 int asn1_write_int( unsigned char **p, unsigned char *start, int val ); 00157 00158 /** 00159 * \brief Write a printable string tag (ASN1_PRINTABLE_STRING) and 00160 * value in ASN.1 format 00161 * Note: function works backwards in data buffer 00162 * 00163 * \param p reference to current position pointer 00164 * \param start start of the buffer (for bounds-checking) 00165 * \param text the text to write 00166 * \param text_len length of the text 00167 * 00168 * \return the length written or a negative error code 00169 */ 00170 int asn1_write_printable_string( unsigned char **p, unsigned char *start, 00171 const char *text, size_t text_len ); 00172 00173 /** 00174 * \brief Write an IA5 string tag (ASN1_IA5_STRING) and 00175 * value in ASN.1 format 00176 * Note: function works backwards in data buffer 00177 * 00178 * \param p reference to current position pointer 00179 * \param start start of the buffer (for bounds-checking) 00180 * \param text the text to write 00181 * \param text_len length of the text 00182 * 00183 * \return the length written or a negative error code 00184 */ 00185 int asn1_write_ia5_string( unsigned char **p, unsigned char *start, 00186 const char *text, size_t text_len ); 00187 00188 /** 00189 * \brief Write a bitstring tag (ASN1_BIT_STRING) and 00190 * value in ASN.1 format 00191 * Note: function works backwards in data buffer 00192 * 00193 * \param p reference to current position pointer 00194 * \param start start of the buffer (for bounds-checking) 00195 * \param buf the bitstring 00196 * \param bits the total number of bits in the bitstring 00197 * 00198 * \return the length written or a negative error code 00199 */ 00200 int asn1_write_bitstring( unsigned char **p, unsigned char *start, 00201 const unsigned char *buf, size_t bits ); 00202 00203 /** 00204 * \brief Write an octet string tag (ASN1_OCTET_STRING) and 00205 * value in ASN.1 format 00206 * Note: function works backwards in data buffer 00207 * 00208 * \param p reference to current position pointer 00209 * \param start start of the buffer (for bounds-checking) 00210 * \param buf data buffer to write 00211 * \param size length of the data buffer 00212 * 00213 * \return the length written or a negative error code 00214 */ 00215 int asn1_write_octet_string( unsigned char **p, unsigned char *start, 00216 const unsigned char *buf, size_t size ); 00217 00218 /** 00219 * \brief Create or find a specific named_data entry for writing in a 00220 * sequence or list based on the OID. If not already in there, 00221 * a new entry is added to the head of the list. 00222 * Warning: Destructive behaviour for the val data! 00223 * 00224 * \param list Pointer to the location of the head of the list to seek 00225 * through (will be updated in case of a new entry) 00226 * \param oid The OID to look for 00227 * \param oid_len Size of the OID 00228 * \param val Data to store (can be NULL if you want to fill it by hand) 00229 * \param val_len Minimum length of the data buffer needed 00230 * 00231 * \return NULL if if there was a memory allocation error, or a pointer 00232 * to the new / existing entry. 00233 */ 00234 asn1_named_data *asn1_store_named_data( asn1_named_data **list, 00235 const char *oid, size_t oid_len, 00236 const unsigned char *val, 00237 size_t val_len ); 00238 00239 #ifdef __cplusplus 00240 } 00241 #endif 00242 00243 #endif /* POLARSSL_ASN1_WRITE_H */ 00244 00245
Generated on Tue Jul 12 2022 19:40:15 by
1.7.2