Add accessor for timing final delay
Signed-off-by: Paul Elliott <paul.elliott@arm.com>
diff --git a/include/mbedtls/timing.h b/include/mbedtls/timing.h
index 25db1c6..652548d 100644
--- a/include/mbedtls/timing.h
+++ b/include/mbedtls/timing.h
@@ -90,6 +90,17 @@
*/
int mbedtls_timing_get_delay( void *data );
+/**
+ * \brief Get the final timing delay
+ *
+ * \param data Pointer to timing data
+ * Must point to a valid \c mbedtls_timing_delay_context struct.
+ *
+ * \return Final timing delay in milliseconds.
+ */
+uint32_t mbedtls_timing_get_final_delay(
+ const mbedtls_timing_delay_context *data );
+
#ifdef __cplusplus
}
#endif
diff --git a/library/timing.c b/library/timing.c
index d66e11e..a65bc99 100644
--- a/library/timing.c
+++ b/library/timing.c
@@ -158,13 +158,28 @@
return( 0 );
}
-#else
-int mbedtls_timing_get_delay( void *data )
+
+/*
+ * Get the final delay.
+ */
+uint32_t mbedtls_timing_get_final_delay(
+ const mbedtls_timing_delay_context *data )
+{
+ return( data->fin_ms );
+}
+#else /* MBEDTLS_HAVE_TIME */
+uint32_t mbedtls_timing_get_final_delay(
+ const mbedtls_timing_delay_context *data )
{
(void) data;
return( 0 );
}
+int mbedtls_timing_get_delay( void *data )
+{
+ (void) data;
+ return( 0 );
+}
void mbedtls_timing_set_delay( void *data, uint32_t int_ms, uint32_t fin_ms )
{
(void) data;
@@ -178,6 +193,7 @@
(void) reset;
return( 0 );
}
+
#endif /* MBEDTLS_HAVE_TIME */
#endif /* !MBEDTLS_TIMING_ALT */
#endif /* MBEDTLS_TIMING_C */
diff --git a/tests/suites/test_suite_ssl.function b/tests/suites/test_suite_ssl.function
index 67f4d6e..bda2a96 100644
--- a/tests/suites/test_suite_ssl.function
+++ b/tests/suites/test_suite_ssl.function
@@ -5277,3 +5277,14 @@
mbedtls_ssl_config_free( &conf );
}
/* END_CASE */
+
+/* BEGIN_CASE depends_on:MBEDTLS_TIMING_C:MBEDTLS_HAVE_TIME */
+void timing_accessor( )
+{
+ mbedtls_timing_delay_context delay_context;
+
+ mbedtls_timing_set_delay( &delay_context, 50, 100 );
+
+ TEST_ASSERT( mbedtls_timing_get_final_delay( &delay_context ) == 100 );
+}
+/* END_CASE */