Move existence check for pk/frame to mbedtls_x509_crt_provide_xxx()
diff --git a/include/mbedtls/x509_crt.h b/include/mbedtls/x509_crt.h
index c7f816b..b3570be 100644
--- a/include/mbedtls/x509_crt.h
+++ b/include/mbedtls/x509_crt.h
@@ -817,53 +817,26 @@
int mbedtls_x509_crt_cache_provide_frame( mbedtls_x509_crt const *crt );
int mbedtls_x509_crt_cache_provide_pk( mbedtls_x509_crt const *crt );
-static inline int mbedtls_x509_crt_cache_frame_set(
- mbedtls_x509_crt_cache *cache )
-{
- return( cache->frame != NULL );
-}
-
-static inline mbedtls_x509_crt_frame* mbedtls_x509_crt_cache_get_frame(
- mbedtls_x509_crt_cache *cache )
-{
- return( cache->frame );
-}
-
-static inline int mbedtls_x509_crt_cache_pk_set(
- mbedtls_x509_crt_cache *cache )
-{
- return( cache->pk != NULL );
-}
-
-static inline mbedtls_pk_context* mbedtls_x509_crt_cache_get_pk(
- mbedtls_x509_crt_cache *cache )
-{
- return( cache->pk );
-}
-
static inline int mbedtls_x509_crt_frame_acquire( mbedtls_x509_crt const *crt,
mbedtls_x509_crt_frame **frame_ptr )
{
+ int ret;
#if defined(MBEDTLS_THREADING_C)
if( mbedtls_mutex_lock( &crt->cache->frame_mutex ) != 0 )
return( MBEDTLS_ERR_THREADING_MUTEX_ERROR );
#endif
- if( !mbedtls_x509_crt_cache_frame_set( crt->cache ) )
+ ret = mbedtls_x509_crt_cache_provide_frame( crt );
+ if( ret != 0 )
{
- int ret;
- ret = mbedtls_x509_crt_cache_provide_frame( crt );
- if( ret != 0 )
- {
#if defined(MBEDTLS_THREADING_C)
- if( mbedtls_mutex_unlock( &crt->cache->frame_mutex ) != 0 )
- return( MBEDTLS_ERR_THREADING_MUTEX_ERROR );
+ if( mbedtls_mutex_unlock( &crt->cache->frame_mutex ) != 0 )
+ return( MBEDTLS_ERR_THREADING_MUTEX_ERROR );
#endif
- return( ret );
- }
+ return( ret );
}
- *frame_ptr = mbedtls_x509_crt_cache_get_frame( crt->cache );
+ *frame_ptr = crt->cache->frame;
return( 0 );
}
@@ -883,26 +856,23 @@
static inline int mbedtls_x509_crt_pk_acquire( mbedtls_x509_crt const *crt,
mbedtls_pk_context **pk_ptr )
{
+ int ret;
#if defined(MBEDTLS_THREADING_C)
if( mbedtls_mutex_lock( &crt->cache->pk_mutex ) != 0 )
return( MBEDTLS_ERR_THREADING_MUTEX_ERROR );
#endif
- if( !mbedtls_x509_crt_cache_pk_set( crt->cache ) )
+ ret = mbedtls_x509_crt_cache_provide_pk( crt );
+ if( ret != 0 )
{
- int ret;
- ret = mbedtls_x509_crt_cache_provide_pk( crt );
- if( ret != 0 )
- {
#if defined(MBEDTLS_THREADING_C)
- if( mbedtls_mutex_unlock( &crt->cache->pk_mutex ) != 0 )
- return( MBEDTLS_ERR_THREADING_MUTEX_ERROR );
+ if( mbedtls_mutex_unlock( &crt->cache->pk_mutex ) != 0 )
+ return( MBEDTLS_ERR_THREADING_MUTEX_ERROR );
#endif
- return( ret );
- }
+ return( ret );
}
- *pk_ptr = mbedtls_x509_crt_cache_get_pk( crt->cache );
+ *pk_ptr = crt->cache->pk;
return( 0 );
}