mbed client lightswitch demo

Dependencies:   mbed Socket lwip-eth lwip-sys lwip

Fork of mbed-client-classic-example-lwip by Austin Blackstone

Committer:
mbedAustin
Date:
Thu Jun 09 17:08:36 2016 +0000
Revision:
11:cada08fc8a70
Commit for public Consumption

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbedAustin 11:cada08fc8a70 1 /**
mbedAustin 11:cada08fc8a70 2 * \file asn1write.h
mbedAustin 11:cada08fc8a70 3 *
mbedAustin 11:cada08fc8a70 4 * \brief ASN.1 buffer writing functionality
mbedAustin 11:cada08fc8a70 5 *
mbedAustin 11:cada08fc8a70 6 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
mbedAustin 11:cada08fc8a70 7 * SPDX-License-Identifier: Apache-2.0
mbedAustin 11:cada08fc8a70 8 *
mbedAustin 11:cada08fc8a70 9 * Licensed under the Apache License, Version 2.0 (the "License"); you may
mbedAustin 11:cada08fc8a70 10 * not use this file except in compliance with the License.
mbedAustin 11:cada08fc8a70 11 * You may obtain a copy of the License at
mbedAustin 11:cada08fc8a70 12 *
mbedAustin 11:cada08fc8a70 13 * http://www.apache.org/licenses/LICENSE-2.0
mbedAustin 11:cada08fc8a70 14 *
mbedAustin 11:cada08fc8a70 15 * Unless required by applicable law or agreed to in writing, software
mbedAustin 11:cada08fc8a70 16 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
mbedAustin 11:cada08fc8a70 17 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
mbedAustin 11:cada08fc8a70 18 * See the License for the specific language governing permissions and
mbedAustin 11:cada08fc8a70 19 * limitations under the License.
mbedAustin 11:cada08fc8a70 20 *
mbedAustin 11:cada08fc8a70 21 * This file is part of mbed TLS (https://tls.mbed.org)
mbedAustin 11:cada08fc8a70 22 */
mbedAustin 11:cada08fc8a70 23 #ifndef MBEDTLS_ASN1_WRITE_H
mbedAustin 11:cada08fc8a70 24 #define MBEDTLS_ASN1_WRITE_H
mbedAustin 11:cada08fc8a70 25
mbedAustin 11:cada08fc8a70 26 #include "asn1.h"
mbedAustin 11:cada08fc8a70 27
mbedAustin 11:cada08fc8a70 28 #define MBEDTLS_ASN1_CHK_ADD(g, f) do { if( ( ret = f ) < 0 ) return( ret ); else \
mbedAustin 11:cada08fc8a70 29 g += ret; } while( 0 )
mbedAustin 11:cada08fc8a70 30
mbedAustin 11:cada08fc8a70 31 #ifdef __cplusplus
mbedAustin 11:cada08fc8a70 32 extern "C" {
mbedAustin 11:cada08fc8a70 33 #endif
mbedAustin 11:cada08fc8a70 34
mbedAustin 11:cada08fc8a70 35 /**
mbedAustin 11:cada08fc8a70 36 * \brief Write a length field in ASN.1 format
mbedAustin 11:cada08fc8a70 37 * Note: function works backwards in data buffer
mbedAustin 11:cada08fc8a70 38 *
mbedAustin 11:cada08fc8a70 39 * \param p reference to current position pointer
mbedAustin 11:cada08fc8a70 40 * \param start start of the buffer (for bounds-checking)
mbedAustin 11:cada08fc8a70 41 * \param len the length to write
mbedAustin 11:cada08fc8a70 42 *
mbedAustin 11:cada08fc8a70 43 * \return the length written or a negative error code
mbedAustin 11:cada08fc8a70 44 */
mbedAustin 11:cada08fc8a70 45 int mbedtls_asn1_write_len( unsigned char **p, unsigned char *start, size_t len );
mbedAustin 11:cada08fc8a70 46
mbedAustin 11:cada08fc8a70 47 /**
mbedAustin 11:cada08fc8a70 48 * \brief Write a ASN.1 tag in ASN.1 format
mbedAustin 11:cada08fc8a70 49 * Note: function works backwards in data buffer
mbedAustin 11:cada08fc8a70 50 *
mbedAustin 11:cada08fc8a70 51 * \param p reference to current position pointer
mbedAustin 11:cada08fc8a70 52 * \param start start of the buffer (for bounds-checking)
mbedAustin 11:cada08fc8a70 53 * \param tag the tag to write
mbedAustin 11:cada08fc8a70 54 *
mbedAustin 11:cada08fc8a70 55 * \return the length written or a negative error code
mbedAustin 11:cada08fc8a70 56 */
mbedAustin 11:cada08fc8a70 57 int mbedtls_asn1_write_tag( unsigned char **p, unsigned char *start,
mbedAustin 11:cada08fc8a70 58 unsigned char tag );
mbedAustin 11:cada08fc8a70 59
mbedAustin 11:cada08fc8a70 60 /**
mbedAustin 11:cada08fc8a70 61 * \brief Write raw buffer data
mbedAustin 11:cada08fc8a70 62 * Note: function works backwards in data buffer
mbedAustin 11:cada08fc8a70 63 *
mbedAustin 11:cada08fc8a70 64 * \param p reference to current position pointer
mbedAustin 11:cada08fc8a70 65 * \param start start of the buffer (for bounds-checking)
mbedAustin 11:cada08fc8a70 66 * \param buf data buffer to write
mbedAustin 11:cada08fc8a70 67 * \param size length of the data buffer
mbedAustin 11:cada08fc8a70 68 *
mbedAustin 11:cada08fc8a70 69 * \return the length written or a negative error code
mbedAustin 11:cada08fc8a70 70 */
mbedAustin 11:cada08fc8a70 71 int mbedtls_asn1_write_raw_buffer( unsigned char **p, unsigned char *start,
mbedAustin 11:cada08fc8a70 72 const unsigned char *buf, size_t size );
mbedAustin 11:cada08fc8a70 73
mbedAustin 11:cada08fc8a70 74 #if defined(MBEDTLS_BIGNUM_C)
mbedAustin 11:cada08fc8a70 75 /**
mbedAustin 11:cada08fc8a70 76 * \brief Write a big number (MBEDTLS_ASN1_INTEGER) in ASN.1 format
mbedAustin 11:cada08fc8a70 77 * Note: function works backwards in data buffer
mbedAustin 11:cada08fc8a70 78 *
mbedAustin 11:cada08fc8a70 79 * \param p reference to current position pointer
mbedAustin 11:cada08fc8a70 80 * \param start start of the buffer (for bounds-checking)
mbedAustin 11:cada08fc8a70 81 * \param X the MPI to write
mbedAustin 11:cada08fc8a70 82 *
mbedAustin 11:cada08fc8a70 83 * \return the length written or a negative error code
mbedAustin 11:cada08fc8a70 84 */
mbedAustin 11:cada08fc8a70 85 int mbedtls_asn1_write_mpi( unsigned char **p, unsigned char *start, const mbedtls_mpi *X );
mbedAustin 11:cada08fc8a70 86 #endif /* MBEDTLS_BIGNUM_C */
mbedAustin 11:cada08fc8a70 87
mbedAustin 11:cada08fc8a70 88 /**
mbedAustin 11:cada08fc8a70 89 * \brief Write a NULL tag (MBEDTLS_ASN1_NULL) with zero data in ASN.1 format
mbedAustin 11:cada08fc8a70 90 * Note: function works backwards in data buffer
mbedAustin 11:cada08fc8a70 91 *
mbedAustin 11:cada08fc8a70 92 * \param p reference to current position pointer
mbedAustin 11:cada08fc8a70 93 * \param start start of the buffer (for bounds-checking)
mbedAustin 11:cada08fc8a70 94 *
mbedAustin 11:cada08fc8a70 95 * \return the length written or a negative error code
mbedAustin 11:cada08fc8a70 96 */
mbedAustin 11:cada08fc8a70 97 int mbedtls_asn1_write_null( unsigned char **p, unsigned char *start );
mbedAustin 11:cada08fc8a70 98
mbedAustin 11:cada08fc8a70 99 /**
mbedAustin 11:cada08fc8a70 100 * \brief Write an OID tag (MBEDTLS_ASN1_OID) and data in ASN.1 format
mbedAustin 11:cada08fc8a70 101 * Note: function works backwards in data buffer
mbedAustin 11:cada08fc8a70 102 *
mbedAustin 11:cada08fc8a70 103 * \param p reference to current position pointer
mbedAustin 11:cada08fc8a70 104 * \param start start of the buffer (for bounds-checking)
mbedAustin 11:cada08fc8a70 105 * \param oid the OID to write
mbedAustin 11:cada08fc8a70 106 * \param oid_len length of the OID
mbedAustin 11:cada08fc8a70 107 *
mbedAustin 11:cada08fc8a70 108 * \return the length written or a negative error code
mbedAustin 11:cada08fc8a70 109 */
mbedAustin 11:cada08fc8a70 110 int mbedtls_asn1_write_oid( unsigned char **p, unsigned char *start,
mbedAustin 11:cada08fc8a70 111 const char *oid, size_t oid_len );
mbedAustin 11:cada08fc8a70 112
mbedAustin 11:cada08fc8a70 113 /**
mbedAustin 11:cada08fc8a70 114 * \brief Write an AlgorithmIdentifier sequence in ASN.1 format
mbedAustin 11:cada08fc8a70 115 * Note: function works backwards in data buffer
mbedAustin 11:cada08fc8a70 116 *
mbedAustin 11:cada08fc8a70 117 * \param p reference to current position pointer
mbedAustin 11:cada08fc8a70 118 * \param start start of the buffer (for bounds-checking)
mbedAustin 11:cada08fc8a70 119 * \param oid the OID of the algorithm
mbedAustin 11:cada08fc8a70 120 * \param oid_len length of the OID
mbedAustin 11:cada08fc8a70 121 * \param par_len length of parameters, which must be already written.
mbedAustin 11:cada08fc8a70 122 * If 0, NULL parameters are added
mbedAustin 11:cada08fc8a70 123 *
mbedAustin 11:cada08fc8a70 124 * \return the length written or a negative error code
mbedAustin 11:cada08fc8a70 125 */
mbedAustin 11:cada08fc8a70 126 int mbedtls_asn1_write_algorithm_identifier( unsigned char **p, unsigned char *start,
mbedAustin 11:cada08fc8a70 127 const char *oid, size_t oid_len,
mbedAustin 11:cada08fc8a70 128 size_t par_len );
mbedAustin 11:cada08fc8a70 129
mbedAustin 11:cada08fc8a70 130 /**
mbedAustin 11:cada08fc8a70 131 * \brief Write a boolean tag (MBEDTLS_ASN1_BOOLEAN) and value in ASN.1 format
mbedAustin 11:cada08fc8a70 132 * Note: function works backwards in data buffer
mbedAustin 11:cada08fc8a70 133 *
mbedAustin 11:cada08fc8a70 134 * \param p reference to current position pointer
mbedAustin 11:cada08fc8a70 135 * \param start start of the buffer (for bounds-checking)
mbedAustin 11:cada08fc8a70 136 * \param boolean 0 or 1
mbedAustin 11:cada08fc8a70 137 *
mbedAustin 11:cada08fc8a70 138 * \return the length written or a negative error code
mbedAustin 11:cada08fc8a70 139 */
mbedAustin 11:cada08fc8a70 140 int mbedtls_asn1_write_bool( unsigned char **p, unsigned char *start, int boolean );
mbedAustin 11:cada08fc8a70 141
mbedAustin 11:cada08fc8a70 142 /**
mbedAustin 11:cada08fc8a70 143 * \brief Write an int tag (MBEDTLS_ASN1_INTEGER) and value in ASN.1 format
mbedAustin 11:cada08fc8a70 144 * Note: function works backwards in data buffer
mbedAustin 11:cada08fc8a70 145 *
mbedAustin 11:cada08fc8a70 146 * \param p reference to current position pointer
mbedAustin 11:cada08fc8a70 147 * \param start start of the buffer (for bounds-checking)
mbedAustin 11:cada08fc8a70 148 * \param val the integer value
mbedAustin 11:cada08fc8a70 149 *
mbedAustin 11:cada08fc8a70 150 * \return the length written or a negative error code
mbedAustin 11:cada08fc8a70 151 */
mbedAustin 11:cada08fc8a70 152 int mbedtls_asn1_write_int( unsigned char **p, unsigned char *start, int val );
mbedAustin 11:cada08fc8a70 153
mbedAustin 11:cada08fc8a70 154 /**
mbedAustin 11:cada08fc8a70 155 * \brief Write a printable string tag (MBEDTLS_ASN1_PRINTABLE_STRING) and
mbedAustin 11:cada08fc8a70 156 * value in ASN.1 format
mbedAustin 11:cada08fc8a70 157 * Note: function works backwards in data buffer
mbedAustin 11:cada08fc8a70 158 *
mbedAustin 11:cada08fc8a70 159 * \param p reference to current position pointer
mbedAustin 11:cada08fc8a70 160 * \param start start of the buffer (for bounds-checking)
mbedAustin 11:cada08fc8a70 161 * \param text the text to write
mbedAustin 11:cada08fc8a70 162 * \param text_len length of the text
mbedAustin 11:cada08fc8a70 163 *
mbedAustin 11:cada08fc8a70 164 * \return the length written or a negative error code
mbedAustin 11:cada08fc8a70 165 */
mbedAustin 11:cada08fc8a70 166 int mbedtls_asn1_write_printable_string( unsigned char **p, unsigned char *start,
mbedAustin 11:cada08fc8a70 167 const char *text, size_t text_len );
mbedAustin 11:cada08fc8a70 168
mbedAustin 11:cada08fc8a70 169 /**
mbedAustin 11:cada08fc8a70 170 * \brief Write an IA5 string tag (MBEDTLS_ASN1_IA5_STRING) and
mbedAustin 11:cada08fc8a70 171 * value in ASN.1 format
mbedAustin 11:cada08fc8a70 172 * Note: function works backwards in data buffer
mbedAustin 11:cada08fc8a70 173 *
mbedAustin 11:cada08fc8a70 174 * \param p reference to current position pointer
mbedAustin 11:cada08fc8a70 175 * \param start start of the buffer (for bounds-checking)
mbedAustin 11:cada08fc8a70 176 * \param text the text to write
mbedAustin 11:cada08fc8a70 177 * \param text_len length of the text
mbedAustin 11:cada08fc8a70 178 *
mbedAustin 11:cada08fc8a70 179 * \return the length written or a negative error code
mbedAustin 11:cada08fc8a70 180 */
mbedAustin 11:cada08fc8a70 181 int mbedtls_asn1_write_ia5_string( unsigned char **p, unsigned char *start,
mbedAustin 11:cada08fc8a70 182 const char *text, size_t text_len );
mbedAustin 11:cada08fc8a70 183
mbedAustin 11:cada08fc8a70 184 /**
mbedAustin 11:cada08fc8a70 185 * \brief Write a bitstring tag (MBEDTLS_ASN1_BIT_STRING) and
mbedAustin 11:cada08fc8a70 186 * value in ASN.1 format
mbedAustin 11:cada08fc8a70 187 * Note: function works backwards in data buffer
mbedAustin 11:cada08fc8a70 188 *
mbedAustin 11:cada08fc8a70 189 * \param p reference to current position pointer
mbedAustin 11:cada08fc8a70 190 * \param start start of the buffer (for bounds-checking)
mbedAustin 11:cada08fc8a70 191 * \param buf the bitstring
mbedAustin 11:cada08fc8a70 192 * \param bits the total number of bits in the bitstring
mbedAustin 11:cada08fc8a70 193 *
mbedAustin 11:cada08fc8a70 194 * \return the length written or a negative error code
mbedAustin 11:cada08fc8a70 195 */
mbedAustin 11:cada08fc8a70 196 int mbedtls_asn1_write_bitstring( unsigned char **p, unsigned char *start,
mbedAustin 11:cada08fc8a70 197 const unsigned char *buf, size_t bits );
mbedAustin 11:cada08fc8a70 198
mbedAustin 11:cada08fc8a70 199 /**
mbedAustin 11:cada08fc8a70 200 * \brief Write an octet string tag (MBEDTLS_ASN1_OCTET_STRING) and
mbedAustin 11:cada08fc8a70 201 * value in ASN.1 format
mbedAustin 11:cada08fc8a70 202 * Note: function works backwards in data buffer
mbedAustin 11:cada08fc8a70 203 *
mbedAustin 11:cada08fc8a70 204 * \param p reference to current position pointer
mbedAustin 11:cada08fc8a70 205 * \param start start of the buffer (for bounds-checking)
mbedAustin 11:cada08fc8a70 206 * \param buf data buffer to write
mbedAustin 11:cada08fc8a70 207 * \param size length of the data buffer
mbedAustin 11:cada08fc8a70 208 *
mbedAustin 11:cada08fc8a70 209 * \return the length written or a negative error code
mbedAustin 11:cada08fc8a70 210 */
mbedAustin 11:cada08fc8a70 211 int mbedtls_asn1_write_octet_string( unsigned char **p, unsigned char *start,
mbedAustin 11:cada08fc8a70 212 const unsigned char *buf, size_t size );
mbedAustin 11:cada08fc8a70 213
mbedAustin 11:cada08fc8a70 214 /**
mbedAustin 11:cada08fc8a70 215 * \brief Create or find a specific named_data entry for writing in a
mbedAustin 11:cada08fc8a70 216 * sequence or list based on the OID. If not already in there,
mbedAustin 11:cada08fc8a70 217 * a new entry is added to the head of the list.
mbedAustin 11:cada08fc8a70 218 * Warning: Destructive behaviour for the val data!
mbedAustin 11:cada08fc8a70 219 *
mbedAustin 11:cada08fc8a70 220 * \param list Pointer to the location of the head of the list to seek
mbedAustin 11:cada08fc8a70 221 * through (will be updated in case of a new entry)
mbedAustin 11:cada08fc8a70 222 * \param oid The OID to look for
mbedAustin 11:cada08fc8a70 223 * \param oid_len Size of the OID
mbedAustin 11:cada08fc8a70 224 * \param val Data to store (can be NULL if you want to fill it by hand)
mbedAustin 11:cada08fc8a70 225 * \param val_len Minimum length of the data buffer needed
mbedAustin 11:cada08fc8a70 226 *
mbedAustin 11:cada08fc8a70 227 * \return NULL if if there was a memory allocation error, or a pointer
mbedAustin 11:cada08fc8a70 228 * to the new / existing entry.
mbedAustin 11:cada08fc8a70 229 */
mbedAustin 11:cada08fc8a70 230 mbedtls_asn1_named_data *mbedtls_asn1_store_named_data( mbedtls_asn1_named_data **list,
mbedAustin 11:cada08fc8a70 231 const char *oid, size_t oid_len,
mbedAustin 11:cada08fc8a70 232 const unsigned char *val,
mbedAustin 11:cada08fc8a70 233 size_t val_len );
mbedAustin 11:cada08fc8a70 234
mbedAustin 11:cada08fc8a70 235 #ifdef __cplusplus
mbedAustin 11:cada08fc8a70 236 }
mbedAustin 11:cada08fc8a70 237 #endif
mbedAustin 11:cada08fc8a70 238
mbedAustin 11:cada08fc8a70 239 #endif /* MBEDTLS_ASN1_WRITE_H */