blob: 9671c88d09ecbf991488dd2b5452971e9231a1c4 [file] [log] [blame]
Simon Butcher86311432016-07-12 13:11:00 +01001/**
2 * \file platform_time.h
3 *
Gilles Peskinef08ca832023-09-12 19:21:54 +02004 * \brief Mbed TLS Platform time abstraction
Darryl Greena40a1012018-01-05 15:33:17 +00005 */
6/*
Bence Szépkúti1e148272020-08-07 13:07:28 +02007 * Copyright The Mbed TLS Contributors
Dave Rodgman7ff79652023-11-03 12:04:52 +00008 * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
Simon Butcher86311432016-07-12 13:11:00 +01009 */
10#ifndef MBEDTLS_PLATFORM_TIME_H
11#define MBEDTLS_PLATFORM_TIME_H
12
13#if !defined(MBEDTLS_CONFIG_FILE)
Jaeden Ameroc49fbbf2019-07-04 20:01:14 +010014#include "mbedtls/config.h"
Simon Butcher86311432016-07-12 13:11:00 +010015#else
16#include MBEDTLS_CONFIG_FILE
17#endif
18
19#ifdef __cplusplus
20extern "C" {
21#endif
22
Simon Butcher86311432016-07-12 13:11:00 +010023/*
24 * The time_t datatype
25 */
26#if defined(MBEDTLS_PLATFORM_TIME_TYPE_MACRO)
27typedef MBEDTLS_PLATFORM_TIME_TYPE_MACRO mbedtls_time_t;
28#else
29/* For time_t */
30#include <time.h>
31typedef time_t mbedtls_time_t;
32#endif /* MBEDTLS_PLATFORM_TIME_TYPE_MACRO */
33
34/*
35 * The function pointers for time
36 */
37#if defined(MBEDTLS_PLATFORM_TIME_ALT)
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010038extern mbedtls_time_t (*mbedtls_time)(mbedtls_time_t *time);
Simon Butcher86311432016-07-12 13:11:00 +010039
40/**
41 * \brief Set your own time function pointer
42 *
43 * \param time_func the time function implementation
44 *
45 * \return 0
46 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010047int mbedtls_platform_set_time(mbedtls_time_t (*time_func)(mbedtls_time_t *time));
Simon Butcher86311432016-07-12 13:11:00 +010048#else
49#if defined(MBEDTLS_PLATFORM_TIME_MACRO)
50#define mbedtls_time MBEDTLS_PLATFORM_TIME_MACRO
51#else
52#define mbedtls_time time
53#endif /* MBEDTLS_PLATFORM_TIME_MACRO */
54#endif /* MBEDTLS_PLATFORM_TIME_ALT */
55
56#ifdef __cplusplus
57}
58#endif
59
Simon Butcher86311432016-07-12 13:11:00 +010060#endif /* platform_time.h */