Fix some more ifdef's RSA/EC, in pk and debug
diff --git a/library/debug.c b/library/debug.c
index b6babe6..8e3dd03 100644
--- a/library/debug.c
+++ b/library/debug.c
@@ -250,27 +250,25 @@
str[maxlen] = '\0';
ssl->f_dbg( ssl->p_dbg, level, str );
- switch( crt->pk.type )
+#if defined(POLARSSL_RSA_C)
+ if( crt->pk.type == POLARSSL_PK_RSA )
{
- case POLARSSL_PK_NONE:
- case POLARSSL_PK_ECDSA:
- debug_print_msg( ssl, level, file, line,
- "crt->pk.type is not valid" );
- break;
-
- case POLARSSL_PK_RSA:
- debug_print_mpi( ssl, level, file, line,
- "crt->rsa.N", &pk_rsa( crt->pk )->N );
- debug_print_mpi( ssl, level, file, line,
- "crt->rsa.E", &pk_rsa( crt->pk )->E );
- break;
-
- case POLARSSL_PK_ECKEY:
- case POLARSSL_PK_ECKEY_DH:
- debug_print_ecp( ssl, level, file, line,
- "crt->eckey.Q", &pk_ec( crt->pk )->Q );
- break;
- }
+ debug_print_mpi( ssl, level, file, line,
+ "crt->rsa.N", &pk_rsa( crt->pk )->N );
+ debug_print_mpi( ssl, level, file, line,
+ "crt->rsa.E", &pk_rsa( crt->pk )->E );
+ } else
+#endif /* POLARSSL_RSA_C */
+#if defined(POLARSSL_ECP_C)
+ if( crt->pk.type == POLARSSL_PK_ECKEY ||
+ crt->pk.type == POLARSSL_PK_ECKEY_DH )
+ {
+ debug_print_ecp( ssl, level, file, line,
+ "crt->eckey.Q", &pk_ec( crt->pk )->Q );
+ } else
+#endif /* POLARSSL_ECP_C */
+ debug_print_msg( ssl, level, file, line,
+ "crt->pk.type is not valid" );
crt = crt->next;
}
diff --git a/library/pk.c b/library/pk.c
index 3ea600a..18db95a 100644
--- a/library/pk.c
+++ b/library/pk.c
@@ -60,29 +60,23 @@
if( ctx == NULL )
return;
- switch( ctx->type )
- {
- case POLARSSL_PK_NONE:
- break;
-
#if defined(POLARSSL_RSA_C)
- case POLARSSL_PK_RSA:
- rsa_free( ctx->data );
- break;
+ if( ctx->type == POLARSSL_PK_RSA )
+ rsa_free( ctx->data );
+ else
#endif
-
#if defined(POLARSSL_ECP_C)
- case POLARSSL_PK_ECKEY:
- case POLARSSL_PK_ECKEY_DH:
- ecp_keypair_free( ctx->data );
- break;
+ if( ctx->type == POLARSSL_PK_ECKEY || ctx->type == POLARSSL_PK_ECKEY_DH )
+ ecp_keypair_free( ctx->data );
+ else
#endif
-
#if defined(POLARSSL_ECDSA_C)
- case POLARSSL_PK_ECDSA:
- ecdsa_free( ctx->data );
- break;
+ if( ctx->type == POLARSSL_PK_ECDSA )
+ ecdsa_free( ctx->data );
+ else
#endif
+ {
+ ; /* guard for the else's above */
}
if( ! ctx->dont_free )
@@ -97,7 +91,7 @@
*/
int pk_set_type( pk_context *ctx, pk_type_t type )
{
- size_t size = 0;
+ size_t size;
if( ctx->type == type )
return( 0 );
@@ -105,30 +99,22 @@
if( ctx->type != POLARSSL_PK_NONE )
return( POLARSSL_ERR_PK_TYPE_MISMATCH );
- switch( type )
- {
#if defined(POLARSSL_RSA_C)
- case POLARSSL_PK_RSA:
- size = sizeof( rsa_context );
- break;
+ if( type == POLARSSL_PK_RSA )
+ size = sizeof( rsa_context );
+ else
#endif
-
#if defined(POLARSSL_ECP_C)
- case POLARSSL_PK_ECKEY:
- case POLARSSL_PK_ECKEY_DH:
- size = sizeof( ecp_keypair );
- break;
+ if( type == POLARSSL_PK_ECKEY || type == POLARSSL_PK_ECKEY_DH )
+ size = sizeof( ecp_keypair );
+ else
#endif
-
#if defined(POLARSSL_ECDSA_C)
- case POLARSSL_PK_ECDSA:
- size = sizeof( ecdsa_context );
- break;
+ if( type == POLARSSL_PK_ECDSA )
+ size = sizeof( ecdsa_context );
+ else
#endif
-
- case POLARSSL_PK_NONE:
- ; /* Cannot happen, but the compiler doesn't know */
- }
+ size = 0; /* should never be executed */
if( ( ctx->data = malloc( size ) ) == NULL )
return( POLARSSL_ERR_PK_MALLOC_FAILED );