1#ifndef	_TIME_STR_H_
2#define _TIME_STR_H_
3
4#include <time.h>
5#include <Security/x509defs.h>
6
7#define UTC_TIME_STRLEN				13
8#define CSSM_TIME_STRLEN			14		/* no trailing 'Z' */
9#define GENERALIZED_TIME_STRLEN		15
10
11#ifdef	__cplusplus
12extern "C" {
13#endif
14
15/*
16 * Given a string containing either a UTC-style or "generalized time"
17 * time string, convert to a struct tm (in GMT/UTC). Returns nonzero on
18 * error.
19 */
20int appTimeStringToTm(
21	const char			*str,
22	unsigned			len,
23	struct tm			*tmp);
24
25typedef enum {
26	TIME_UTC,
27	TIME_CSSM,
28	TIME_GEN
29} timeSpec;
30
31/* Caller must CSSM_FREE() the resulting string */
32char *appTimeAtNowPlus(int secFromNow,
33	timeSpec timeSpec);
34
35/*** for backwards compatibility ***/
36
37/*
38 * Malloc and return UTC (2-digit year) time string, for time with specified
39 * offset from present. This uses the stdlib gmtime(), which is not thread safe.
40 * Even though this function protects the call with a lock, the TP also uses
41 * gmtime. It also does the correct locking for its own calls to gmtime()�but
42 * the is no way to synchronize TP's calls to gmtime() with the calls to this
43 * one other than only using this one when no threads might be performing TP ops.
44 */
45char *utcAtNowPlus(int secFromNow);
46
47/*
48 * Same thing, generalized time (4-digit year).
49 */
50char *genTimeAtNowPlus(int secFromNow);
51
52/*
53 * Free the string obtained from the above.
54 */
55void freeTimeString(char *timeStr);
56
57char *x509TimeToCssmTimestring(
58	const CSSM_X509_TIME 	*x509Time,
59	unsigned				*rtnLen);		// for caller's convenience
60
61#ifdef	__cplusplus
62}
63#endif
64
65#endif	/* _TIME_STR_H_ */
66