mirror of
https://git.suyu.dev/suyu/mbedtls.git
synced 2025-12-22 05:46:41 +01:00
Nicer interface between PK and debug.
Finally get rid of pk_context.type member, too.
This commit is contained in:
parent
b3d9187cea
commit
c6ac8870d5
5 changed files with 113 additions and 28 deletions
23
library/pk.c
23
library/pk.c
|
|
@ -56,7 +56,6 @@ void pk_init( pk_context *ctx )
|
|||
return;
|
||||
|
||||
ctx->info = NULL;
|
||||
ctx->type = POLARSSL_PK_NONE;
|
||||
ctx->data = NULL;
|
||||
}
|
||||
|
||||
|
|
@ -72,7 +71,6 @@ void pk_free( pk_context *ctx )
|
|||
ctx->data = NULL;
|
||||
|
||||
ctx->info = NULL;
|
||||
ctx->type = POLARSSL_PK_NONE;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -107,11 +105,13 @@ int pk_set_type( pk_context *ctx, pk_type_t type )
|
|||
{
|
||||
const pk_info_t *info;
|
||||
|
||||
if( ctx->type == type )
|
||||
return( 0 );
|
||||
if( ctx->info != NULL )
|
||||
{
|
||||
if( ctx->info->type == type )
|
||||
return 0;
|
||||
|
||||
if( ctx->type != POLARSSL_PK_NONE )
|
||||
return( POLARSSL_ERR_PK_TYPE_MISMATCH );
|
||||
}
|
||||
|
||||
if( ( info = pk_info_from_type( type ) ) == NULL )
|
||||
return( POLARSSL_ERR_PK_TYPE_MISMATCH );
|
||||
|
|
@ -119,7 +119,6 @@ int pk_set_type( pk_context *ctx, pk_type_t type )
|
|||
if( ( ctx->data = info->ctx_alloc_func() ) == NULL )
|
||||
return( POLARSSL_ERR_PK_MALLOC_FAILED );
|
||||
|
||||
ctx->type = type;
|
||||
ctx->info = info;
|
||||
|
||||
return( 0 );
|
||||
|
|
@ -160,3 +159,15 @@ size_t pk_get_size( const pk_context *ctx )
|
|||
|
||||
return( ctx->info->get_size( ctx->data ) );
|
||||
}
|
||||
|
||||
/*
|
||||
* Export debug information
|
||||
*/
|
||||
int pk_debug( const pk_context *ctx, pk_debug_item *items )
|
||||
{
|
||||
if( ctx == NULL || ctx->info == NULL )
|
||||
return( POLARSSL_ERR_PK_TYPE_MISMATCH ); // TODO
|
||||
|
||||
ctx->info->debug_func( ctx->data, items );
|
||||
return( 0 );
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue