blob: 8dd6f27b6e79b0645451b86d28a388faaa133494 [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
Bi-Ruei, Chiu1fa31c92016-05-16 13:50:09 +080023#define GeneralizedTime_free OCTET_STRING_free
24#define GeneralizedTime_decode_ber OCTET_STRING_decode_ber
25#define GeneralizedTime_decode_xer OCTET_STRING_decode_xer_utf8
26#define GeneralizedTime_decode_uper OCTET_STRING_decode_uper
27#define GeneralizedTime_encode_uper OCTET_STRING_encode_uper
28
Lev Walkinf15320b2004-06-03 03:38:44 +000029/***********************
30 * Some handy helpers. *
31 ***********************/
32
Lev Walkinf15320b2004-06-03 03:38:44 +000033struct tm; /* <time.h> */
Lev Walkin99006362004-08-07 03:52:26 +000034
35/*
36 * Convert a GeneralizedTime structure into time_t
37 * and optionally into struct tm.
38 * If as_gmt is given, the resulting _optional_tm4fill will have a GMT zone,
39 * instead of default local one.
40 * On error returns -1 and errno set to EINVAL
41 */
42time_t asn_GT2time(const GeneralizedTime_t *, struct tm *_optional_tm4fill,
43 int as_gmt);
44
Lev Walkin535612a2005-07-03 05:32:40 +000045/* A version of the above function also returning the fractions of seconds */
46time_t asn_GT2time_frac(const GeneralizedTime_t *,
Lev Walkin3a522782005-07-04 12:21:51 +000047 int *frac_value, int *frac_digits, /* (value / (10 ^ digits)) */
48 struct tm *_optional_tm4fill, int as_gmt);
49
50/*
51 * Another version returning fractions with defined precision
52 * For example, parsing of the time ending with ".1" seconds
53 * with frac_digits=3 (msec) would yield frac_value = 100.
54 */
55time_t asn_GT2time_prec(const GeneralizedTime_t *,
56 int *frac_value, int frac_digits,
Lev Walkin535612a2005-07-03 05:32:40 +000057 struct tm *_optional_tm4fill, int as_gmt);
58
Lev Walkin99006362004-08-07 03:52:26 +000059/*
60 * Convert a struct tm into GeneralizedTime.
Lev Walkin535612a2005-07-03 05:32:40 +000061 * If _optional_gt is not given, this function will try to allocate one.
Lev Walkin99006362004-08-07 03:52:26 +000062 * If force_gmt is given, the resulting GeneralizedTime will be forced
Lev Walkin5e033762004-09-29 13:26:15 +000063 * into a GMT time zone (encoding ends with a "Z").
Lev Walkin99006362004-08-07 03:52:26 +000064 * On error, this function returns 0 and sets errno.
65 */
Lev Walkin535612a2005-07-03 05:32:40 +000066GeneralizedTime_t *asn_time2GT(GeneralizedTime_t *_optional_gt,
67 const struct tm *, int force_gmt);
68GeneralizedTime_t *asn_time2GT_frac(GeneralizedTime_t *_optional_gt,
Lev Walkin3a522782005-07-04 12:21:51 +000069 const struct tm *, int frac_value, int frac_digits, int force_gmt);
Lev Walkinf15320b2004-06-03 03:38:44 +000070
Lev Walkin21b41ac2005-07-24 09:03:44 +000071#ifdef __cplusplus
72}
73#endif
74
Lev Walkinf15320b2004-06-03 03:38:44 +000075#endif /* _GeneralizedTime_H_ */