Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1 | /*- |
| 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 Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 8 | #include <OCTET_STRING.h> |
| 9 | |
Lev Walkin | 21b41ac | 2005-07-24 09:03:44 +0000 | [diff] [blame] | 10 | #ifdef __cplusplus |
| 11 | extern "C" { |
| 12 | #endif |
| 13 | |
Lev Walkin | 11c3e17 | 2004-09-24 21:00:50 +0000 | [diff] [blame] | 14 | typedef OCTET_STRING_t GeneralizedTime_t; /* Implemented via OCTET STRING */ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 15 | |
Lev Walkin | 5e03376 | 2004-09-29 13:26:15 +0000 | [diff] [blame] | 16 | extern asn_TYPE_descriptor_t asn_DEF_GeneralizedTime; |
Bi-Ruei, Chiu | 1f87ac0 | 2017-08-20 01:25:45 +0800 | [diff] [blame] | 17 | extern asn_TYPE_operation_t asn_OP_GeneralizedTime; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 18 | |
Lev Walkin | a9cc46e | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 19 | asn_struct_print_f GeneralizedTime_print; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 20 | asn_constr_check_f GeneralizedTime_constraint; |
Lev Walkin | 9900636 | 2004-08-07 03:52:26 +0000 | [diff] [blame] | 21 | der_type_encoder_f GeneralizedTime_encode_der; |
Lev Walkin | a9cc46e | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 22 | xer_type_encoder_f GeneralizedTime_encode_xer; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 23 | |
Bi-Ruei, Chiu | 1fa31c9 | 2016-05-16 13:50:09 +0800 | [diff] [blame] | 24 | #define GeneralizedTime_free OCTET_STRING_free |
Bi-Ruei, Chiu | e1bf219 | 2017-08-19 00:55:25 +0800 | [diff] [blame] | 25 | #define GeneralizedTime_compare OCTET_STRING_compare |
Bi-Ruei, Chiu | 1fa31c9 | 2016-05-16 13:50:09 +0800 | [diff] [blame] | 26 | #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 Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 31 | /*********************** |
| 32 | * Some handy helpers. * |
| 33 | ***********************/ |
| 34 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 35 | struct tm; /* <time.h> */ |
Lev Walkin | 9900636 | 2004-08-07 03:52:26 +0000 | [diff] [blame] | 36 | |
| 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 | */ |
| 44 | time_t asn_GT2time(const GeneralizedTime_t *, struct tm *_optional_tm4fill, |
| 45 | int as_gmt); |
| 46 | |
Lev Walkin | 535612a | 2005-07-03 05:32:40 +0000 | [diff] [blame] | 47 | /* A version of the above function also returning the fractions of seconds */ |
| 48 | time_t asn_GT2time_frac(const GeneralizedTime_t *, |
Lev Walkin | 3a52278 | 2005-07-04 12:21:51 +0000 | [diff] [blame] | 49 | 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 | */ |
| 57 | time_t asn_GT2time_prec(const GeneralizedTime_t *, |
| 58 | int *frac_value, int frac_digits, |
Lev Walkin | 535612a | 2005-07-03 05:32:40 +0000 | [diff] [blame] | 59 | struct tm *_optional_tm4fill, int as_gmt); |
| 60 | |
Lev Walkin | 9900636 | 2004-08-07 03:52:26 +0000 | [diff] [blame] | 61 | /* |
| 62 | * Convert a struct tm into GeneralizedTime. |
Lev Walkin | 535612a | 2005-07-03 05:32:40 +0000 | [diff] [blame] | 63 | * If _optional_gt is not given, this function will try to allocate one. |
Lev Walkin | 9900636 | 2004-08-07 03:52:26 +0000 | [diff] [blame] | 64 | * If force_gmt is given, the resulting GeneralizedTime will be forced |
Lev Walkin | 5e03376 | 2004-09-29 13:26:15 +0000 | [diff] [blame] | 65 | * into a GMT time zone (encoding ends with a "Z"). |
Lev Walkin | 9900636 | 2004-08-07 03:52:26 +0000 | [diff] [blame] | 66 | * On error, this function returns 0 and sets errno. |
| 67 | */ |
Lev Walkin | 535612a | 2005-07-03 05:32:40 +0000 | [diff] [blame] | 68 | GeneralizedTime_t *asn_time2GT(GeneralizedTime_t *_optional_gt, |
| 69 | const struct tm *, int force_gmt); |
| 70 | GeneralizedTime_t *asn_time2GT_frac(GeneralizedTime_t *_optional_gt, |
Lev Walkin | 3a52278 | 2005-07-04 12:21:51 +0000 | [diff] [blame] | 71 | const struct tm *, int frac_value, int frac_digits, int force_gmt); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 72 | |
Lev Walkin | 21b41ac | 2005-07-24 09:03:44 +0000 | [diff] [blame] | 73 | #ifdef __cplusplus |
| 74 | } |
| 75 | #endif |
| 76 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 77 | #endif /* _GeneralizedTime_H_ */ |