blob: ace9c027150a21db20a60da42c9143a2735ac7a0 [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 Walkinf15320b2004-06-03 03:38:44 +000023
Bi-Ruei, Chiu1fa31c92016-05-16 13:50:09 +080024#define GeneralizedTime_free OCTET_STRING_free
Bi-Ruei, Chiue1bf2192017-08-19 00:55:25 +080025#define GeneralizedTime_compare OCTET_STRING_compare
Bi-Ruei, Chiu1fa31c92016-05-16 13:50:09 +080026#define GeneralizedTime_decode_ber OCTET_STRING_decode_ber
27#define GeneralizedTime_decode_xer OCTET_STRING_decode_xer_utf8
28#define GeneralizedTime_decode_uper OCTET_STRING_decode_uper
29#define GeneralizedTime_encode_uper OCTET_STRING_encode_uper
30
Lev Walkinf15320b2004-06-03 03:38:44 +000031/***********************
32 * Some handy helpers. *
33 ***********************/
34
Lev Walkinf15320b2004-06-03 03:38:44 +000035struct tm; /* <time.h> */
Lev Walkin99006362004-08-07 03:52:26 +000036
37/*
38 * Convert a GeneralizedTime structure into time_t
39 * and optionally into struct tm.
40 * If as_gmt is given, the resulting _optional_tm4fill will have a GMT zone,
41 * instead of default local one.
42 * On error returns -1 and errno set to EINVAL
43 */
44time_t asn_GT2time(const GeneralizedTime_t *, struct tm *_optional_tm4fill,
45 int as_gmt);
46
Lev Walkin535612a2005-07-03 05:32:40 +000047/* A version of the above function also returning the fractions of seconds */
48time_t asn_GT2time_frac(const GeneralizedTime_t *,
Lev Walkin3a522782005-07-04 12:21:51 +000049 int *frac_value, int *frac_digits, /* (value / (10 ^ digits)) */
50 struct tm *_optional_tm4fill, int as_gmt);
51
52/*
53 * Another version returning fractions with defined precision
54 * For example, parsing of the time ending with ".1" seconds
55 * with frac_digits=3 (msec) would yield frac_value = 100.
56 */
57time_t asn_GT2time_prec(const GeneralizedTime_t *,
58 int *frac_value, int frac_digits,
Lev Walkin535612a2005-07-03 05:32:40 +000059 struct tm *_optional_tm4fill, int as_gmt);
60
Lev Walkin99006362004-08-07 03:52:26 +000061/*
62 * Convert a struct tm into GeneralizedTime.
Lev Walkin535612a2005-07-03 05:32:40 +000063 * If _optional_gt is not given, this function will try to allocate one.
Lev Walkin99006362004-08-07 03:52:26 +000064 * If force_gmt is given, the resulting GeneralizedTime will be forced
Lev Walkin5e033762004-09-29 13:26:15 +000065 * into a GMT time zone (encoding ends with a "Z").
Lev Walkin99006362004-08-07 03:52:26 +000066 * On error, this function returns 0 and sets errno.
67 */
Lev Walkin535612a2005-07-03 05:32:40 +000068GeneralizedTime_t *asn_time2GT(GeneralizedTime_t *_optional_gt,
69 const struct tm *, int force_gmt);
70GeneralizedTime_t *asn_time2GT_frac(GeneralizedTime_t *_optional_gt,
Lev Walkin3a522782005-07-04 12:21:51 +000071 const struct tm *, int frac_value, int frac_digits, int force_gmt);
Lev Walkinf15320b2004-06-03 03:38:44 +000072
Lev Walkin21b41ac2005-07-24 09:03:44 +000073#ifdef __cplusplus
74}
75#endif
76
Lev Walkinf15320b2004-06-03 03:38:44 +000077#endif /* _GeneralizedTime_H_ */