blob: 7e70c67dc2309b157127cb74f0e885fb8cd1ff61 [file] [log] [blame]
Simon Butcher86311432016-07-12 13:11:00 +01001/**
2 * \file platform_time.h
3 *
4 * \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
Simon Butcher86311432016-07-12 13:11:00 +01008 * SPDX-License-Identifier: Apache-2.0
9 *
10 * Licensed under the Apache License, Version 2.0 (the "License"); you may
11 * not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
13 *
14 * http://www.apache.org/licenses/LICENSE-2.0
15 *
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
18 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
Simon Butcher86311432016-07-12 13:11:00 +010021 */
22#ifndef MBEDTLS_PLATFORM_TIME_H
23#define MBEDTLS_PLATFORM_TIME_H
24
Bence Szépkútic662b362021-05-27 11:25:03 +020025#include "mbedtls/build_info.h"
Simon Butcher86311432016-07-12 13:11:00 +010026
27#ifdef __cplusplus
28extern "C" {
29#endif
30
31/**
32 * \name SECTION: Module settings
33 *
34 * The configuration options you can set for this module are in this section.
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +020035 * Either change them in mbedtls_config.h or define them on the compiler command
36 * line.
Simon Butcher86311432016-07-12 13:11:00 +010037 * \{
38 */
39
40/*
41 * The time_t datatype
42 */
43#if defined(MBEDTLS_PLATFORM_TIME_TYPE_MACRO)
44typedef MBEDTLS_PLATFORM_TIME_TYPE_MACRO mbedtls_time_t;
45#else
46/* For time_t */
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +020047# include <time.h>
Simon Butcher86311432016-07-12 13:11:00 +010048typedef time_t mbedtls_time_t;
49#endif /* MBEDTLS_PLATFORM_TIME_TYPE_MACRO */
50
51/*
52 * The function pointers for time
53 */
54#if defined(MBEDTLS_PLATFORM_TIME_ALT)
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +020055extern mbedtls_time_t (*mbedtls_time)(mbedtls_time_t *time);
Simon Butcher86311432016-07-12 13:11:00 +010056
57/**
58 * \brief Set your own time function pointer
59 *
60 * \param time_func the time function implementation
61 *
62 * \return 0
63 */
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +020064int mbedtls_platform_set_time(mbedtls_time_t (*time_func)(mbedtls_time_t *time));
Simon Butcher86311432016-07-12 13:11:00 +010065#else
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +020066# if defined(MBEDTLS_PLATFORM_TIME_MACRO)
67# define mbedtls_time MBEDTLS_PLATFORM_TIME_MACRO
68# else
69# define mbedtls_time time
70# endif /* MBEDTLS_PLATFORM_TIME_MACRO */
Simon Butcher86311432016-07-12 13:11:00 +010071#endif /* MBEDTLS_PLATFORM_TIME_ALT */
72
73#ifdef __cplusplus
74}
75#endif
76
77#endif /* platform_time.h */