mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2025-01-25 18:10:59 +00:00
Simplify some option parsing code
This commit is contained in:
parent
a6781c99ee
commit
fdee74b8d6
|
@ -314,6 +314,16 @@ int main( int argc, char *argv[] )
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Used by sni_parse and psk_parse to handle coma-separated lists
|
||||||
|
*/
|
||||||
|
#define GET_ITEM( dst ) \
|
||||||
|
dst = p; \
|
||||||
|
while( *p != ',' ) \
|
||||||
|
if( ++p > end ) \
|
||||||
|
return( NULL ); \
|
||||||
|
*p++ = '\0';
|
||||||
|
|
||||||
#if defined(POLARSSL_SNI)
|
#if defined(POLARSSL_SNI)
|
||||||
typedef struct _sni_entry sni_entry;
|
typedef struct _sni_entry sni_entry;
|
||||||
|
|
||||||
|
@ -328,8 +338,8 @@ struct _sni_entry {
|
||||||
* Parse a string of triplets name1,crt1,key1[,name2,crt2,key2[,...]]
|
* Parse a string of triplets name1,crt1,key1[,name2,crt2,key2[,...]]
|
||||||
* into a usable sni_entry list.
|
* into a usable sni_entry list.
|
||||||
*
|
*
|
||||||
* Note: this is not production quality: leaks memory if parsing fails,
|
* Modifies the input string! This is not production quality!
|
||||||
* and error reporting is poor.
|
* (leaks memory if parsing fails, no error reporting, ...)
|
||||||
*/
|
*/
|
||||||
sni_entry *sni_parse( char *sni_string )
|
sni_entry *sni_parse( char *sni_string )
|
||||||
{
|
{
|
||||||
|
@ -351,44 +361,21 @@ sni_entry *sni_parse( char *sni_string )
|
||||||
|
|
||||||
if( ( new->cert = polarssl_malloc( sizeof( x509_crt ) ) ) == NULL ||
|
if( ( new->cert = polarssl_malloc( sizeof( x509_crt ) ) ) == NULL ||
|
||||||
( new->key = polarssl_malloc( sizeof( pk_context ) ) ) == NULL )
|
( new->key = polarssl_malloc( sizeof( pk_context ) ) ) == NULL )
|
||||||
{
|
return( NULL );
|
||||||
cur = NULL;
|
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
x509_crt_init( new->cert );
|
x509_crt_init( new->cert );
|
||||||
pk_init( new->key );
|
pk_init( new->key );
|
||||||
|
|
||||||
new->name = p;
|
GET_ITEM( new->name );
|
||||||
while( *p != ',' ) if( ++p > end ) { cur = NULL; goto exit; }
|
GET_ITEM( crt_file );
|
||||||
*p++ = '\0';
|
GET_ITEM( key_file );
|
||||||
|
|
||||||
crt_file = p;
|
|
||||||
while( *p != ',' ) if( ++p > end ) { cur = NULL; goto exit; }
|
|
||||||
*p++ = '\0';
|
|
||||||
|
|
||||||
key_file = p;
|
|
||||||
while( *p != ',' ) if( ++p > end ) { cur = NULL; goto exit; }
|
|
||||||
*p++ = '\0';
|
|
||||||
|
|
||||||
if( x509_crt_parse_file( new->cert, crt_file ) != 0 ||
|
if( x509_crt_parse_file( new->cert, crt_file ) != 0 ||
|
||||||
pk_parse_keyfile( new->key, key_file, "" ) != 0 )
|
pk_parse_keyfile( new->key, key_file, "" ) != 0 )
|
||||||
{
|
return( NULL );
|
||||||
cur = NULL;
|
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
new->next = cur;
|
new->next = cur;
|
||||||
cur = new;
|
cur = new;
|
||||||
new = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
exit:
|
|
||||||
if( new != NULL )
|
|
||||||
{
|
|
||||||
x509_crt_free( new->cert);
|
|
||||||
pk_free( new->key );
|
|
||||||
polarssl_free( new );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return( cur );
|
return( cur );
|
||||||
|
@ -512,13 +499,8 @@ psk_entry *psk_parse( char *psk_string )
|
||||||
|
|
||||||
memset( new, 0, sizeof( psk_entry ) );
|
memset( new, 0, sizeof( psk_entry ) );
|
||||||
|
|
||||||
new->name = p;
|
GET_ITEM( new->name );
|
||||||
while( *p != ',' ) if( ++p > end ) return( NULL );
|
GET_ITEM( key_hex );
|
||||||
*p++ = '\0';
|
|
||||||
|
|
||||||
key_hex = p;
|
|
||||||
while( *p != ',' ) if( ++p > end ) return( NULL );
|
|
||||||
*p++ = '\0';
|
|
||||||
|
|
||||||
if( unhexify( new->key, key_hex, &new->key_len ) != 0 )
|
if( unhexify( new->key, key_hex, &new->key_len ) != 0 )
|
||||||
return( NULL );
|
return( NULL );
|
||||||
|
|
Loading…
Reference in a new issue