blob: 84ee481b102c938d0090844c022312d01508ca3b [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;
Bi-Ruei, Chiu1f87ac02017-08-20 01:25:45 +080017extern asn_TYPE_operation_t asn_OP_GeneralizedTime;
Lev Walkinf15320b2004-06-03 03:38:44 +000018
Lev Walkina9cc46e2004-09-22 16:06:28 +000019asn_struct_print_f GeneralizedTime_print;
Lev Walkinf15320b2004-06-03 03:38:44 +000020asn_constr_check_f GeneralizedTime_constraint;
Lev Walkin99006362004-08-07 03:52:26 +000021der_type_encoder_f GeneralizedTime_encode_der;
Lev Walkina9cc46e2004-09-22 16:06:28 +000022xer_type_encoder_f GeneralizedTime_encode_xer;
Lev Walkina5972be2017-09-29 23:15:58 -070023asn_random_fill_f GeneralizedTime_random_fill;
Lev Walkinf15320b2004-06-03 03:38:44 +000024
Bi-Ruei, Chiu1fa31c92016-05-16 13:50:09 +080025#define GeneralizedTime_free OCTET_STRING_free
Bi-Ruei, Chiue1bf2192017-08-19 00:55:25 +080026#define GeneralizedTime_compare OCTET_STRING_compare
Bi-Ruei, Chiu1fa31c92016-05-16 13:50:09 +080027#define GeneralizedTime_decode_ber OCTET_STRING_decode_ber
28#define GeneralizedTime_decode_xer OCTET_STRING_decode_xer_utf8
29#define GeneralizedTime_decode_uper OCTET_STRING_decode_uper
30#define GeneralizedTime_encode_uper OCTET_STRING_encode_uper
31
Lev Walkinf15320b2004-06-03 03:38:44 +000032/***********************
33 * Some handy helpers. *
34 ***********************/
35
Lev Walkinf15320b2004-06-03 03:38:44 +000036struct tm; /* <time.h> */
Lev Walkin99006362004-08-07 03:52:26 +000037
38/*
39 * Convert a GeneralizedTime structure into time_t
40 * and optionally into struct tm.
41 * If as_gmt is given, the resulting _optional_tm4fill will have a GMT zone,
42 * instead of default local one.
43 * On error returns -1 and errno set to EINVAL
44 */
45time_t asn_GT2time(const GeneralizedTime_t *, struct tm *_optional_tm4fill,
46 int as_gmt);
47
Lev Walkin535612a2005-07-03 05:32:40 +000048/* A version of the above function also returning the fractions of seconds */
49time_t asn_GT2time_frac(const GeneralizedTime_t *,
Lev Walkin3a522782005-07-04 12:21:51 +000050 int *frac_value, int *frac_digits, /* (value / (10 ^ digits)) */
51 struct tm *_optional_tm4fill, int as_gmt);
52
53/*
54 * Another version returning fractions with defined precision
55 * For example, parsing of the time ending with ".1" seconds
56 * with frac_digits=3 (msec) would yield frac_value = 100.
57 */
58time_t asn_GT2time_prec(const GeneralizedTime_t *,
59 int *frac_value, int frac_digits,
Lev Walkin535612a2005-07-03 05:32:40 +000060 struct tm *_optional_tm4fill, int as_gmt);
61
Lev Walkin99006362004-08-07 03:52:26 +000062/*
63 * Convert a struct tm into GeneralizedTime.
Lev Walkin535612a2005-07-03 05:32:40 +000064 * If _optional_gt is not given, this function will try to allocate one.
Lev Walkin99006362004-08-07 03:52:26 +000065 * If force_gmt is given, the resulting GeneralizedTime will be forced
Lev Walkin5e033762004-09-29 13:26:15 +000066 * into a GMT time zone (encoding ends with a "Z").
Lev Walkin99006362004-08-07 03:52:26 +000067 * On error, this function returns 0 and sets errno.
68 */
Lev Walkin535612a2005-07-03 05:32:40 +000069GeneralizedTime_t *asn_time2GT(GeneralizedTime_t *_optional_gt,
70 const struct tm *, int force_gmt);
71GeneralizedTime_t *asn_time2GT_frac(GeneralizedTime_t *_optional_gt,
Lev Walkin3a522782005-07-04 12:21:51 +000072 const struct tm *, int frac_value, int frac_digits, int force_gmt);
Lev Walkinf15320b2004-06-03 03:38:44 +000073
Lev Walkin21b41ac2005-07-24 09:03:44 +000074#ifdef __cplusplus
75}
76#endif
77
Lev Walkinf15320b2004-06-03 03:38:44 +000078#endif /* _GeneralizedTime_H_ */