@@ -301,3 +301,152 @@ exit:
301
301
mbedtls_free( data.output );
302
302
}
303
303
/* END_CASE */
304
+
305
+ /* BEGIN_CASE */
306
+ void store_named_data_find( data_t *oid0, data_t *oid1,
307
+ data_t *oid2, data_t *oid3,
308
+ data_t *needle, int from, int position )
309
+ {
310
+ data_t *oid[4] = {oid0, oid1, oid2, oid3};
311
+ mbedtls_asn1_named_data nd[] ={
312
+ { {0x06, 0, NULL}, {0, 0, NULL}, NULL, 0 },
313
+ { {0x06, 0, NULL}, {0, 0, NULL}, NULL, 0 },
314
+ { {0x06, 0, NULL}, {0, 0, NULL}, NULL, 0 },
315
+ { {0x06, 0, NULL}, {0, 0, NULL}, NULL, 0 },
316
+ };
317
+ mbedtls_asn1_named_data *pointers[ARRAY_LENGTH( nd ) + 1];
318
+ size_t i;
319
+ mbedtls_asn1_named_data *head = NULL;
320
+ mbedtls_asn1_named_data *found = NULL;
321
+
322
+ for( i = 0; i < ARRAY_LENGTH( nd ); i++ )
323
+ pointers[i] = &nd[i];
324
+ pointers[ARRAY_LENGTH( nd )] = NULL;
325
+ for( i = 0; i < ARRAY_LENGTH( nd ); i++ )
326
+ {
327
+ ASSERT_ALLOC( nd[i].oid.p, oid[i]->len );
328
+ memcpy( nd[i].oid.p, oid[i]->x, oid[i]->len );
329
+ nd[i].oid.len = oid[i]->len;
330
+ nd[i].next = pointers[i+1];
331
+ }
332
+
333
+ head = pointers[from];
334
+ found = mbedtls_asn1_store_named_data( &head,
335
+ (const char *) needle->x,
336
+ needle->len,
337
+ NULL, 0 );
338
+
339
+ /* In any case, the existing list structure must be unchanged. */
340
+ for( i = 0; i < ARRAY_LENGTH( nd ); i++ )
341
+ TEST_ASSERT( nd[i].next == pointers[i+1] );
342
+
343
+ if( position >= 0 )
344
+ {
345
+ /* position should have been found and modified. */
346
+ TEST_ASSERT( head == pointers[from] );
347
+ TEST_ASSERT( found == pointers[position] );
348
+ }
349
+ else
350
+ {
351
+ /* A new entry should have been created. */
352
+ TEST_ASSERT( found == head );
353
+ TEST_ASSERT( head->next == pointers[from] );
354
+ for( i = 0; i < ARRAY_LENGTH( nd ); i++ )
355
+ TEST_ASSERT( found != &nd[i] );
356
+ }
357
+
358
+ exit:
359
+ if( found != NULL && found == head && found != pointers[from] )
360
+ {
361
+ mbedtls_free( found->oid.p );
362
+ mbedtls_free( found );
363
+ }
364
+ for( i = 0; i < ARRAY_LENGTH( nd ); i++ )
365
+ mbedtls_free( nd[i].oid.p );
366
+ }
367
+ /* END_CASE */
368
+
369
+ /* BEGIN_CASE */
370
+ void store_named_data_val_found( int old_len, int new_len )
371
+ {
372
+ mbedtls_asn1_named_data nd =
373
+ { {0x06, 3, (unsigned char *) "OID"}, {0, 0, NULL}, NULL, 0 };
374
+ mbedtls_asn1_named_data *head = &nd;
375
+ mbedtls_asn1_named_data *found = NULL;
376
+ unsigned char *old_val = NULL;
377
+ unsigned char *new_val = (unsigned char *) "new value";
378
+
379
+ if( old_len != 0 )
380
+ {
381
+ ASSERT_ALLOC( nd.val.p, (size_t) old_len );
382
+ old_val = nd.val.p;
383
+ nd.val.len = old_len;
384
+ memset( old_val, 'x', old_len );
385
+ }
386
+ if( new_len <= 0 )
387
+ {
388
+ new_len = - new_len;
389
+ new_val = NULL;
390
+ }
391
+
392
+ found = mbedtls_asn1_store_named_data( &head, "OID", 3,
393
+ new_val, new_len );
394
+ TEST_ASSERT( head == &nd );
395
+ TEST_ASSERT( found == head );
396
+
397
+ if( new_val != NULL)
398
+ ASSERT_COMPARE( found->val.p, found->val.len,
399
+ new_val, (size_t) new_len );
400
+ if( new_len == 0)
401
+ TEST_ASSERT( found->val.p == NULL );
402
+ else if( new_len == old_len )
403
+ TEST_ASSERT( found->val.p == old_val );
404
+ else
405
+ TEST_ASSERT( found->val.p != old_val );
406
+
407
+ exit:
408
+ mbedtls_free( nd.val.p );
409
+ }
410
+ /* END_CASE */
411
+
412
+ /* BEGIN_CASE */
413
+ void store_named_data_val_new( int new_len )
414
+ {
415
+ mbedtls_asn1_named_data *head = NULL;
416
+ mbedtls_asn1_named_data *found = NULL;
417
+ const unsigned char *oid = (unsigned char *) "OID";
418
+ size_t oid_len = strlen( (const char *) oid );
419
+ const unsigned char *new_val = (unsigned char *) "new value";
420
+
421
+ if( new_len <= 0 )
422
+ new_val = NULL;
423
+ if( new_len < 0 )
424
+ new_len = - new_len;
425
+
426
+ found = mbedtls_asn1_store_named_data( &head,
427
+ (const char *) oid, oid_len,
428
+ new_val, (size_t) new_len );
429
+ TEST_ASSERT( found != NULL );
430
+ TEST_ASSERT( found == head );
431
+ TEST_ASSERT( found->oid.p != oid );
432
+ ASSERT_COMPARE( found->oid.p, found->oid.len, oid, oid_len );
433
+ if( new_len == 0 )
434
+ TEST_ASSERT( found->val.p == NULL );
435
+ else if( new_val == NULL )
436
+ TEST_ASSERT( found->val.p != NULL );
437
+ else
438
+ {
439
+ TEST_ASSERT( found->val.p != new_val );
440
+ ASSERT_COMPARE( found->val.p, found->val.len,
441
+ new_val, (size_t) new_len );
442
+ }
443
+
444
+ exit:
445
+ if( found != NULL )
446
+ {
447
+ mbedtls_free( found->oid.p );
448
+ mbedtls_free( found->val.p );
449
+ }
450
+ mbedtls_free( found );
451
+ }
452
+ /* END_CASE */
0 commit comments