| Paul Bakker | bdb912d | 2012-02-13 23:11:30 +0000 | [diff] [blame] | 1 | /* |
| 2 | * ASN.1 buffer writing functionality |
| 3 | * |
| Manuel Pégourié-Gonnard | a658a40 | 2015-01-23 09:45:19 +0000 | [diff] [blame] | 4 | * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved |
| Paul Bakker | bdb912d | 2012-02-13 23:11:30 +0000 | [diff] [blame] | 5 | * |
| Manuel Pégourié-Gonnard | 967a2a5 | 2015-01-22 14:28:16 +0000 | [diff] [blame] | 6 | * This file is part of mbed TLS (http://www.polarssl.org) |
| Paul Bakker | bdb912d | 2012-02-13 23:11:30 +0000 | [diff] [blame] | 7 | * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org> |
| 8 | * |
| Paul Bakker | bdb912d | 2012-02-13 23:11:30 +0000 | [diff] [blame] | 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License as published by |
| 11 | * the Free Software Foundation; either version 2 of the License, or |
| 12 | * (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License along |
| 20 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 21 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 22 | */ |
| 23 | |
| Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 24 | #if !defined(POLARSSL_CONFIG_FILE) |
| Paul Bakker | bdb912d | 2012-02-13 23:11:30 +0000 | [diff] [blame] | 25 | #include "polarssl/config.h" |
| Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 26 | #else |
| 27 | #include POLARSSL_CONFIG_FILE |
| 28 | #endif |
| Paul Bakker | bdb912d | 2012-02-13 23:11:30 +0000 | [diff] [blame] | 29 | |
| 30 | #if defined(POLARSSL_ASN1_WRITE_C) |
| 31 | |
| 32 | #include "polarssl/asn1write.h" |
| 33 | |
| Paul Bakker | 7dc4c44 | 2014-02-01 22:50:26 +0100 | [diff] [blame] | 34 | #if defined(POLARSSL_PLATFORM_C) |
| 35 | #include "polarssl/platform.h" |
| Paul Bakker | 59ba59f | 2013-09-09 11:26:00 +0200 | [diff] [blame] | 36 | #else |
| 37 | #include <stdlib.h> |
| 38 | #define polarssl_malloc malloc |
| 39 | #define polarssl_free free |
| 40 | #endif |
| 41 | |
| Paul Bakker | bdb912d | 2012-02-13 23:11:30 +0000 | [diff] [blame] | 42 | int asn1_write_len( unsigned char **p, unsigned char *start, size_t len ) |
| 43 | { |
| 44 | if( len < 0x80 ) |
| 45 | { |
| 46 | if( *p - start < 1 ) |
| 47 | return( POLARSSL_ERR_ASN1_BUF_TOO_SMALL ); |
| 48 | |
| Paul Bakker | b9cfaa0 | 2013-10-11 18:58:55 +0200 | [diff] [blame] | 49 | *--(*p) = (unsigned char) len; |
| Paul Bakker | bdb912d | 2012-02-13 23:11:30 +0000 | [diff] [blame] | 50 | return( 1 ); |
| 51 | } |
| 52 | |
| 53 | if( len <= 0xFF ) |
| 54 | { |
| 55 | if( *p - start < 2 ) |
| 56 | return( POLARSSL_ERR_ASN1_BUF_TOO_SMALL ); |
| 57 | |
| Paul Bakker | b9cfaa0 | 2013-10-11 18:58:55 +0200 | [diff] [blame] | 58 | *--(*p) = (unsigned char) len; |
| Paul Bakker | bdb912d | 2012-02-13 23:11:30 +0000 | [diff] [blame] | 59 | *--(*p) = 0x81; |
| 60 | return( 2 ); |
| 61 | } |
| 62 | |
| 63 | if( *p - start < 3 ) |
| 64 | return( POLARSSL_ERR_ASN1_BUF_TOO_SMALL ); |
| 65 | |
| 66 | // We assume we never have lengths larger than 65535 bytes |
| 67 | // |
| 68 | *--(*p) = len % 256; |
| 69 | *--(*p) = ( len / 256 ) % 256; |
| 70 | *--(*p) = 0x82; |
| 71 | |
| 72 | return( 3 ); |
| 73 | } |
| 74 | |
| 75 | int asn1_write_tag( unsigned char **p, unsigned char *start, unsigned char tag ) |
| 76 | { |
| 77 | if( *p - start < 1 ) |
| 78 | return( POLARSSL_ERR_ASN1_BUF_TOO_SMALL ); |
| 79 | |
| 80 | *--(*p) = tag; |
| 81 | |
| 82 | return( 1 ); |
| 83 | } |
| 84 | |
| Paul Bakker | 9852d00 | 2013-08-26 17:56:37 +0200 | [diff] [blame] | 85 | int asn1_write_raw_buffer( unsigned char **p, unsigned char *start, |
| 86 | const unsigned char *buf, size_t size ) |
| 87 | { |
| 88 | size_t len = 0; |
| 89 | |
| 90 | if( *p - start < (int) size ) |
| 91 | return( POLARSSL_ERR_ASN1_BUF_TOO_SMALL ); |
| 92 | |
| 93 | len = size; |
| 94 | (*p) -= len; |
| 95 | memcpy( *p, buf, len ); |
| 96 | |
| Paul Bakker | b9cfaa0 | 2013-10-11 18:58:55 +0200 | [diff] [blame] | 97 | return( (int) len ); |
| Paul Bakker | 9852d00 | 2013-08-26 17:56:37 +0200 | [diff] [blame] | 98 | } |
| 99 | |
| Paul Bakker | ed27a04 | 2013-04-18 22:46:23 +0200 | [diff] [blame] | 100 | #if defined(POLARSSL_BIGNUM_C) |
| Paul Bakker | bdb912d | 2012-02-13 23:11:30 +0000 | [diff] [blame] | 101 | int asn1_write_mpi( unsigned char **p, unsigned char *start, mpi *X ) |
| 102 | { |
| 103 | int ret; |
| 104 | size_t len = 0; |
| 105 | |
| 106 | // Write the MPI |
| 107 | // |
| 108 | len = mpi_size( X ); |
| 109 | |
| 110 | if( *p - start < (int) len ) |
| 111 | return( POLARSSL_ERR_ASN1_BUF_TOO_SMALL ); |
| 112 | |
| 113 | (*p) -= len; |
| Paul Bakker | 3d8fb63 | 2014-04-17 12:42:41 +0200 | [diff] [blame] | 114 | MPI_CHK( mpi_write_binary( X, *p, len ) ); |
| Paul Bakker | bdb912d | 2012-02-13 23:11:30 +0000 | [diff] [blame] | 115 | |
| 116 | // DER format assumes 2s complement for numbers, so the leftmost bit |
| 117 | // should be 0 for positive numbers and 1 for negative numbers. |
| 118 | // |
| Paul Bakker | 66d5d07 | 2014-06-17 16:39:18 +0200 | [diff] [blame] | 119 | if( X->s ==1 && **p & 0x80 ) |
| Paul Bakker | bdb912d | 2012-02-13 23:11:30 +0000 | [diff] [blame] | 120 | { |
| 121 | if( *p - start < 1 ) |
| 122 | return( POLARSSL_ERR_ASN1_BUF_TOO_SMALL ); |
| 123 | |
| 124 | *--(*p) = 0x00; |
| 125 | len += 1; |
| 126 | } |
| 127 | |
| 128 | ASN1_CHK_ADD( len, asn1_write_len( p, start, len ) ); |
| 129 | ASN1_CHK_ADD( len, asn1_write_tag( p, start, ASN1_INTEGER ) ); |
| 130 | |
| Paul Bakker | 3d8fb63 | 2014-04-17 12:42:41 +0200 | [diff] [blame] | 131 | ret = (int) len; |
| 132 | |
| 133 | cleanup: |
| 134 | return( ret ); |
| Paul Bakker | bdb912d | 2012-02-13 23:11:30 +0000 | [diff] [blame] | 135 | } |
| Paul Bakker | ed27a04 | 2013-04-18 22:46:23 +0200 | [diff] [blame] | 136 | #endif /* POLARSSL_BIGNUM_C */ |
| 137 | |
| Paul Bakker | bdb912d | 2012-02-13 23:11:30 +0000 | [diff] [blame] | 138 | int asn1_write_null( unsigned char **p, unsigned char *start ) |
| 139 | { |
| 140 | int ret; |
| 141 | size_t len = 0; |
| 142 | |
| 143 | // Write NULL |
| 144 | // |
| 145 | ASN1_CHK_ADD( len, asn1_write_len( p, start, 0) ); |
| 146 | ASN1_CHK_ADD( len, asn1_write_tag( p, start, ASN1_NULL ) ); |
| 147 | |
| Paul Bakker | b9cfaa0 | 2013-10-11 18:58:55 +0200 | [diff] [blame] | 148 | return( (int) len ); |
| Paul Bakker | bdb912d | 2012-02-13 23:11:30 +0000 | [diff] [blame] | 149 | } |
| 150 | |
| Paul Bakker | 5f45e62 | 2013-09-09 12:02:36 +0200 | [diff] [blame] | 151 | int asn1_write_oid( unsigned char **p, unsigned char *start, |
| 152 | const char *oid, size_t oid_len ) |
| Paul Bakker | bdb912d | 2012-02-13 23:11:30 +0000 | [diff] [blame] | 153 | { |
| 154 | int ret; |
| 155 | size_t len = 0; |
| 156 | |
| Paul Bakker | 9852d00 | 2013-08-26 17:56:37 +0200 | [diff] [blame] | 157 | ASN1_CHK_ADD( len, asn1_write_raw_buffer( p, start, |
| Paul Bakker | 5f45e62 | 2013-09-09 12:02:36 +0200 | [diff] [blame] | 158 | (const unsigned char *) oid, oid_len ) ); |
| Paul Bakker | bdb912d | 2012-02-13 23:11:30 +0000 | [diff] [blame] | 159 | ASN1_CHK_ADD( len , asn1_write_len( p, start, len ) ); |
| 160 | ASN1_CHK_ADD( len , asn1_write_tag( p, start, ASN1_OID ) ); |
| 161 | |
| Paul Bakker | b9cfaa0 | 2013-10-11 18:58:55 +0200 | [diff] [blame] | 162 | return( (int) len ); |
| Paul Bakker | bdb912d | 2012-02-13 23:11:30 +0000 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | int asn1_write_algorithm_identifier( unsigned char **p, unsigned char *start, |
| Manuel Pégourié-Gonnard | edda904 | 2013-09-12 02:17:54 +0200 | [diff] [blame] | 166 | const char *oid, size_t oid_len, |
| 167 | size_t par_len ) |
| Paul Bakker | bdb912d | 2012-02-13 23:11:30 +0000 | [diff] [blame] | 168 | { |
| 169 | int ret; |
| Paul Bakker | bdb912d | 2012-02-13 23:11:30 +0000 | [diff] [blame] | 170 | size_t len = 0; |
| 171 | |
| Manuel Pégourié-Gonnard | edda904 | 2013-09-12 02:17:54 +0200 | [diff] [blame] | 172 | if( par_len == 0 ) |
| 173 | ASN1_CHK_ADD( len, asn1_write_null( p, start ) ); |
| 174 | else |
| 175 | len += par_len; |
| Paul Bakker | bdb912d | 2012-02-13 23:11:30 +0000 | [diff] [blame] | 176 | |
| Paul Bakker | 5f45e62 | 2013-09-09 12:02:36 +0200 | [diff] [blame] | 177 | ASN1_CHK_ADD( len, asn1_write_oid( p, start, oid, oid_len ) ); |
| Paul Bakker | bdb912d | 2012-02-13 23:11:30 +0000 | [diff] [blame] | 178 | |
| Paul Bakker | 5f45e62 | 2013-09-09 12:02:36 +0200 | [diff] [blame] | 179 | ASN1_CHK_ADD( len, asn1_write_len( p, start, len ) ); |
| Paul Bakker | bdb912d | 2012-02-13 23:11:30 +0000 | [diff] [blame] | 180 | ASN1_CHK_ADD( len, asn1_write_tag( p, start, |
| 181 | ASN1_CONSTRUCTED | ASN1_SEQUENCE ) ); |
| 182 | |
| Paul Bakker | b9cfaa0 | 2013-10-11 18:58:55 +0200 | [diff] [blame] | 183 | return( (int) len ); |
| Paul Bakker | bdb912d | 2012-02-13 23:11:30 +0000 | [diff] [blame] | 184 | } |
| 185 | |
| Paul Bakker | 329def3 | 2013-09-06 16:34:38 +0200 | [diff] [blame] | 186 | int asn1_write_bool( unsigned char **p, unsigned char *start, int boolean ) |
| 187 | { |
| 188 | int ret; |
| 189 | size_t len = 0; |
| 190 | |
| 191 | if( *p - start < 1 ) |
| 192 | return( POLARSSL_ERR_ASN1_BUF_TOO_SMALL ); |
| 193 | |
| 194 | *--(*p) = (boolean) ? 1 : 0; |
| 195 | len++; |
| 196 | |
| 197 | ASN1_CHK_ADD( len, asn1_write_len( p, start, len ) ); |
| 198 | ASN1_CHK_ADD( len, asn1_write_tag( p, start, ASN1_BOOLEAN ) ); |
| 199 | |
| Paul Bakker | b9cfaa0 | 2013-10-11 18:58:55 +0200 | [diff] [blame] | 200 | return( (int) len ); |
| Paul Bakker | 329def3 | 2013-09-06 16:34:38 +0200 | [diff] [blame] | 201 | } |
| 202 | |
| Paul Bakker | bdb912d | 2012-02-13 23:11:30 +0000 | [diff] [blame] | 203 | int asn1_write_int( unsigned char **p, unsigned char *start, int val ) |
| 204 | { |
| 205 | int ret; |
| 206 | size_t len = 0; |
| 207 | |
| 208 | // TODO negative values and values larger than 128 |
| 209 | // DER format assumes 2s complement for numbers, so the leftmost bit |
| 210 | // should be 0 for positive numbers and 1 for negative numbers. |
| 211 | // |
| 212 | if( *p - start < 1 ) |
| 213 | return( POLARSSL_ERR_ASN1_BUF_TOO_SMALL ); |
| 214 | |
| 215 | len += 1; |
| 216 | *--(*p) = val; |
| 217 | |
| Paul Bakker | 66d5d07 | 2014-06-17 16:39:18 +0200 | [diff] [blame] | 218 | if( val > 0 && **p & 0x80 ) |
| Paul Bakker | bdb912d | 2012-02-13 23:11:30 +0000 | [diff] [blame] | 219 | { |
| 220 | if( *p - start < 1 ) |
| 221 | return( POLARSSL_ERR_ASN1_BUF_TOO_SMALL ); |
| 222 | |
| 223 | *--(*p) = 0x00; |
| 224 | len += 1; |
| 225 | } |
| 226 | |
| 227 | ASN1_CHK_ADD( len, asn1_write_len( p, start, len ) ); |
| 228 | ASN1_CHK_ADD( len, asn1_write_tag( p, start, ASN1_INTEGER ) ); |
| 229 | |
| Paul Bakker | b9cfaa0 | 2013-10-11 18:58:55 +0200 | [diff] [blame] | 230 | return( (int) len ); |
| Paul Bakker | bdb912d | 2012-02-13 23:11:30 +0000 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | int asn1_write_printable_string( unsigned char **p, unsigned char *start, |
| Paul Bakker | 5f45e62 | 2013-09-09 12:02:36 +0200 | [diff] [blame] | 234 | const char *text, size_t text_len ) |
| Paul Bakker | bdb912d | 2012-02-13 23:11:30 +0000 | [diff] [blame] | 235 | { |
| 236 | int ret; |
| 237 | size_t len = 0; |
| 238 | |
| Paul Bakker | 9852d00 | 2013-08-26 17:56:37 +0200 | [diff] [blame] | 239 | ASN1_CHK_ADD( len, asn1_write_raw_buffer( p, start, |
| Paul Bakker | 5f45e62 | 2013-09-09 12:02:36 +0200 | [diff] [blame] | 240 | (const unsigned char *) text, text_len ) ); |
| Paul Bakker | bdb912d | 2012-02-13 23:11:30 +0000 | [diff] [blame] | 241 | |
| 242 | ASN1_CHK_ADD( len, asn1_write_len( p, start, len ) ); |
| 243 | ASN1_CHK_ADD( len, asn1_write_tag( p, start, ASN1_PRINTABLE_STRING ) ); |
| 244 | |
| Paul Bakker | b9cfaa0 | 2013-10-11 18:58:55 +0200 | [diff] [blame] | 245 | return( (int) len ); |
| Paul Bakker | bdb912d | 2012-02-13 23:11:30 +0000 | [diff] [blame] | 246 | } |
| Paul Bakker | 598e450 | 2013-08-25 14:46:39 +0200 | [diff] [blame] | 247 | |
| Paul Bakker | 0588815 | 2012-02-16 10:26:57 +0000 | [diff] [blame] | 248 | int asn1_write_ia5_string( unsigned char **p, unsigned char *start, |
| Paul Bakker | 5f45e62 | 2013-09-09 12:02:36 +0200 | [diff] [blame] | 249 | const char *text, size_t text_len ) |
| Paul Bakker | 0588815 | 2012-02-16 10:26:57 +0000 | [diff] [blame] | 250 | { |
| 251 | int ret; |
| 252 | size_t len = 0; |
| 253 | |
| Paul Bakker | 9852d00 | 2013-08-26 17:56:37 +0200 | [diff] [blame] | 254 | ASN1_CHK_ADD( len, asn1_write_raw_buffer( p, start, |
| Paul Bakker | 5f45e62 | 2013-09-09 12:02:36 +0200 | [diff] [blame] | 255 | (const unsigned char *) text, text_len ) ); |
| Paul Bakker | 0588815 | 2012-02-16 10:26:57 +0000 | [diff] [blame] | 256 | |
| 257 | ASN1_CHK_ADD( len, asn1_write_len( p, start, len ) ); |
| 258 | ASN1_CHK_ADD( len, asn1_write_tag( p, start, ASN1_IA5_STRING ) ); |
| 259 | |
| Paul Bakker | b9cfaa0 | 2013-10-11 18:58:55 +0200 | [diff] [blame] | 260 | return( (int) len ); |
| Paul Bakker | 0588815 | 2012-02-16 10:26:57 +0000 | [diff] [blame] | 261 | } |
| Paul Bakker | 598e450 | 2013-08-25 14:46:39 +0200 | [diff] [blame] | 262 | |
| 263 | int asn1_write_bitstring( unsigned char **p, unsigned char *start, |
| 264 | const unsigned char *buf, size_t bits ) |
| 265 | { |
| 266 | int ret; |
| 267 | size_t len = 0, size; |
| 268 | |
| 269 | size = ( bits / 8 ) + ( ( bits % 8 ) ? 1 : 0 ); |
| 270 | |
| 271 | // Calculate byte length |
| 272 | // |
| 273 | if( *p - start < (int) size + 1 ) |
| 274 | return( POLARSSL_ERR_ASN1_BUF_TOO_SMALL ); |
| 275 | |
| 276 | len = size + 1; |
| 277 | (*p) -= size; |
| 278 | memcpy( *p, buf, size ); |
| 279 | |
| 280 | // Write unused bits |
| 281 | // |
| Paul Bakker | b9cfaa0 | 2013-10-11 18:58:55 +0200 | [diff] [blame] | 282 | *--(*p) = (unsigned char) (size * 8 - bits); |
| Paul Bakker | 598e450 | 2013-08-25 14:46:39 +0200 | [diff] [blame] | 283 | |
| 284 | ASN1_CHK_ADD( len, asn1_write_len( p, start, len ) ); |
| 285 | ASN1_CHK_ADD( len, asn1_write_tag( p, start, ASN1_BIT_STRING ) ); |
| 286 | |
| Paul Bakker | b9cfaa0 | 2013-10-11 18:58:55 +0200 | [diff] [blame] | 287 | return( (int) len ); |
| Paul Bakker | 598e450 | 2013-08-25 14:46:39 +0200 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | int asn1_write_octet_string( unsigned char **p, unsigned char *start, |
| 291 | const unsigned char *buf, size_t size ) |
| 292 | { |
| 293 | int ret; |
| 294 | size_t len = 0; |
| 295 | |
| Paul Bakker | 9852d00 | 2013-08-26 17:56:37 +0200 | [diff] [blame] | 296 | ASN1_CHK_ADD( len, asn1_write_raw_buffer( p, start, buf, size ) ); |
| Paul Bakker | 598e450 | 2013-08-25 14:46:39 +0200 | [diff] [blame] | 297 | |
| 298 | ASN1_CHK_ADD( len, asn1_write_len( p, start, len ) ); |
| 299 | ASN1_CHK_ADD( len, asn1_write_tag( p, start, ASN1_OCTET_STRING ) ); |
| 300 | |
| Paul Bakker | b9cfaa0 | 2013-10-11 18:58:55 +0200 | [diff] [blame] | 301 | return( (int) len ); |
| Paul Bakker | 598e450 | 2013-08-25 14:46:39 +0200 | [diff] [blame] | 302 | } |
| Paul Bakker | 59ba59f | 2013-09-09 11:26:00 +0200 | [diff] [blame] | 303 | |
| 304 | asn1_named_data *asn1_store_named_data( asn1_named_data **head, |
| 305 | const char *oid, size_t oid_len, |
| 306 | const unsigned char *val, |
| 307 | size_t val_len ) |
| 308 | { |
| 309 | asn1_named_data *cur; |
| 310 | |
| 311 | if( ( cur = asn1_find_named_data( *head, oid, oid_len ) ) == NULL ) |
| 312 | { |
| 313 | // Add new entry if not present yet based on OID |
| 314 | // |
| 315 | if( ( cur = polarssl_malloc( sizeof(asn1_named_data) ) ) == NULL ) |
| 316 | return( NULL ); |
| 317 | |
| 318 | memset( cur, 0, sizeof(asn1_named_data) ); |
| 319 | |
| 320 | cur->oid.len = oid_len; |
| 321 | cur->oid.p = polarssl_malloc( oid_len ); |
| 322 | if( cur->oid.p == NULL ) |
| 323 | { |
| 324 | polarssl_free( cur ); |
| 325 | return( NULL ); |
| 326 | } |
| 327 | |
| Manuel Pégourié-Gonnard | e5b0fc1 | 2014-11-12 22:27:42 +0100 | [diff] [blame] | 328 | memcpy( cur->oid.p, oid, oid_len ); |
| 329 | |
| Paul Bakker | 59ba59f | 2013-09-09 11:26:00 +0200 | [diff] [blame] | 330 | cur->val.len = val_len; |
| 331 | cur->val.p = polarssl_malloc( val_len ); |
| 332 | if( cur->val.p == NULL ) |
| 333 | { |
| 334 | polarssl_free( cur->oid.p ); |
| 335 | polarssl_free( cur ); |
| 336 | return( NULL ); |
| 337 | } |
| 338 | |
| Paul Bakker | 59ba59f | 2013-09-09 11:26:00 +0200 | [diff] [blame] | 339 | cur->next = *head; |
| 340 | *head = cur; |
| 341 | } |
| 342 | else if( cur->val.len < val_len ) |
| 343 | { |
| 344 | // Enlarge existing value buffer if needed |
| 345 | // |
| 346 | polarssl_free( cur->val.p ); |
| 347 | cur->val.p = NULL; |
| 348 | |
| 349 | cur->val.len = val_len; |
| 350 | cur->val.p = polarssl_malloc( val_len ); |
| 351 | if( cur->val.p == NULL ) |
| 352 | { |
| 353 | polarssl_free( cur->oid.p ); |
| 354 | polarssl_free( cur ); |
| 355 | return( NULL ); |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | if( val != NULL ) |
| 360 | memcpy( cur->val.p, val, val_len ); |
| 361 | |
| 362 | return( cur ); |
| 363 | } |
| Paul Bakker | 9af723c | 2014-05-01 13:03:14 +0200 | [diff] [blame] | 364 | #endif /* POLARSSL_ASN1_WRITE_C */ |