blob: 1ea06b0686b1e7df6e1a1c91d3191f5592638141 [file] [log] [blame]
Lev Walkinf15320b2004-06-03 03:38:44 +00001/*-
2 * Copyright (c) 2003, 2004 Lev Walkin <vlm@lionet.info>. All rights reserved.
3 * Redistribution and modifications are permitted subject to BSD license.
4 */
5#ifndef _GeneralizedTime_H_
6#define _GeneralizedTime_H_
7
Lev Walkinf15320b2004-06-03 03:38:44 +00008#include <OCTET_STRING.h>
9
Lev Walkin21b41ac2005-07-24 09:03:44 +000010#ifdef __cplusplus
11extern "C" {
12#endif
13
Lev Walkin11c3e172004-09-24 21:00:50 +000014typedef OCTET_STRING_t GeneralizedTime_t; /* Implemented via OCTET STRING */
Lev Walkinf15320b2004-06-03 03:38:44 +000015
Lev Walkin5e033762004-09-29 13:26:15 +000016extern asn_TYPE_descriptor_t asn_DEF_GeneralizedTime;
Lev Walkinf15320b2004-06-03 03:38:44 +000017
Lev Walkina9cc46e2004-09-22 16:06:28 +000018asn_struct_print_f GeneralizedTime_print;
Lev Walkinf15320b2004-06-03 03:38:44 +000019asn_constr_check_f GeneralizedTime_constraint;
Lev Walkin99006362004-08-07 03:52:26 +000020der_type_encoder_f GeneralizedTime_encode_der;
Lev Walkina9cc46e2004-09-22 16:06:28 +000021xer_type_encoder_f GeneralizedTime_encode_xer;
Lev Walkinf15320b2004-06-03 03:38:44 +000022
23/***********************
24 * Some handy helpers. *
25 ***********************/
26
Lev Walkinf15320b2004-06-03 03:38:44 +000027struct tm; /* <time.h> */
Lev Walkin99006362004-08-07 03:52:26 +000028
29/*
30 * Convert a GeneralizedTime structure into time_t
31 * and optionally into struct tm.
32 * If as_gmt is given, the resulting _optional_tm4fill will have a GMT zone,
33 * instead of default local one.
34 * On error returns -1 and errno set to EINVAL
35 */
36time_t asn_GT2time(const GeneralizedTime_t *, struct tm *_optional_tm4fill,
37 int as_gmt);
38
Lev Walkin535612a2005-07-03 05:32:40 +000039/* A version of the above function also returning the fractions of seconds */
40time_t asn_GT2time_frac(const GeneralizedTime_t *,
Lev Walkin3a522782005-07-04 12:21:51 +000041 int *frac_value, int *frac_digits, /* (value / (10 ^ digits)) */
42 struct tm *_optional_tm4fill, int as_gmt);
43
44/*
45 * Another version returning fractions with defined precision
46 * For example, parsing of the time ending with ".1" seconds
47 * with frac_digits=3 (msec) would yield frac_value = 100.
48 */
49time_t asn_GT2time_prec(const GeneralizedTime_t *,
50 int *frac_value, int frac_digits,
Lev Walkin535612a2005-07-03 05:32:40 +000051 struct tm *_optional_tm4fill, int as_gmt);
52
Lev Walkin99006362004-08-07 03:52:26 +000053/*
54 * Convert a struct tm into GeneralizedTime.
Lev Walkin535612a2005-07-03 05:32:40 +000055 * If _optional_gt is not given, this function will try to allocate one.
Lev Walkin99006362004-08-07 03:52:26 +000056 * If force_gmt is given, the resulting GeneralizedTime will be forced
Lev Walkin5e033762004-09-29 13:26:15 +000057 * into a GMT time zone (encoding ends with a "Z").
Lev Walkin99006362004-08-07 03:52:26 +000058 * On error, this function returns 0 and sets errno.
59 */
Lev Walkin535612a2005-07-03 05:32:40 +000060GeneralizedTime_t *asn_time2GT(GeneralizedTime_t *_optional_gt,
61 const struct tm *, int force_gmt);
62GeneralizedTime_t *asn_time2GT_frac(GeneralizedTime_t *_optional_gt,
Lev Walkin3a522782005-07-04 12:21:51 +000063 const struct tm *, int frac_value, int frac_digits, int force_gmt);
Lev Walkinf15320b2004-06-03 03:38:44 +000064
Lev Walkin21b41ac2005-07-24 09:03:44 +000065#ifdef __cplusplus
66}
67#endif
68
Lev Walkinf15320b2004-06-03 03:38:44 +000069#endif /* _GeneralizedTime_H_ */