vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1 | #define __NO_ASN_TABLE__ |
vlm | d3da851 | 2004-08-19 13:26:54 +0000 | [diff] [blame] | 2 | #include <GeneralizedTime.c> |
| 3 | #include <constraints.c> |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 4 | |
| 5 | static void |
vlm | 81057a8 | 2004-08-07 03:52:26 +0000 | [diff] [blame] | 6 | check(char *time_str, time_t expect, int as_gmt) { |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 7 | GeneralizedTime_t gt; |
| 8 | struct tm tm; |
| 9 | time_t tloc; |
| 10 | |
| 11 | gt.buf = time_str; |
| 12 | gt.size = strlen(time_str); |
| 13 | |
vlm | 81057a8 | 2004-08-07 03:52:26 +0000 | [diff] [blame] | 14 | tloc = asn_GT2time(>, &tm, as_gmt); |
| 15 | printf("%s: [%s] -> %ld == %ld\n", |
| 16 | as_gmt?"GMT":"ofs", time_str, (long)tloc, (long)expect); |
vlm | 6534a8d | 2004-10-20 15:40:04 +0000 | [diff] [blame] | 17 | |
| 18 | if(tloc != -1) { |
| 19 | printf("\t%04d-%02d-%02dT%02d:%02d:%02d%+03ld%02ld\n", |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 20 | tm.tm_year + 1900, |
| 21 | tm.tm_mon + 1, |
| 22 | tm.tm_mday, |
| 23 | tm.tm_hour, |
| 24 | tm.tm_min, |
| 25 | tm.tm_sec, |
vlm | 6534a8d | 2004-10-20 15:40:04 +0000 | [diff] [blame] | 26 | (GMTOFF(tm) / 3600), |
| 27 | labs(GMTOFF(tm) % 3600) |
| 28 | ); |
| 29 | } |
vlm | 81057a8 | 2004-08-07 03:52:26 +0000 | [diff] [blame] | 30 | assert(tloc == expect); |
| 31 | |
vlm | 6534a8d | 2004-10-20 15:40:04 +0000 | [diff] [blame] | 32 | #ifdef HAVE_TM_GMTOFF |
| 33 | assert(tloc == -1 || as_gmt == 0 || GMTOFF(tm) == 0); |
| 34 | #endif |
vlm | 81057a8 | 2004-08-07 03:52:26 +0000 | [diff] [blame] | 35 | |
| 36 | if(!as_gmt) check(time_str, expect, 1); |
| 37 | } |
| 38 | |
| 39 | static void |
| 40 | rcheck(time_t tloc, const char *expect, int force_gmt) { |
| 41 | GeneralizedTime_t *gt; |
| 42 | struct tm tm, *tmp; |
| 43 | |
| 44 | tmp = localtime_r(&tloc, &tm); |
| 45 | assert(tmp); |
| 46 | |
| 47 | gt = asn_time2GT(0, &tm, force_gmt); |
| 48 | if(gt) { |
| 49 | assert(expect); |
| 50 | printf("[%s] vs [%s] (%d)\n", |
| 51 | gt->buf, expect, force_gmt); |
vlm | d3da851 | 2004-08-19 13:26:54 +0000 | [diff] [blame] | 52 | assert(gt->size == (int)strlen(gt->buf)); |
vlm | 81057a8 | 2004-08-07 03:52:26 +0000 | [diff] [blame] | 53 | assert(!strcmp(gt->buf, expect)); |
| 54 | } else { |
| 55 | assert(!expect); |
| 56 | } |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | int |
| 60 | main(int ac, char **av) { |
| 61 | |
vlm | d3da851 | 2004-08-19 13:26:54 +0000 | [diff] [blame] | 62 | (void)av; |
| 63 | |
vlm | 81057a8 | 2004-08-07 03:52:26 +0000 | [diff] [blame] | 64 | check("200401250", -1, 0); |
| 65 | check("2004012509300", -1, 0); |
| 66 | check("20040125093000-", -1, 0); |
| 67 | check("20040125093007-0", -1, 0); |
| 68 | check("20040125093007-080", -1, 0); |
| 69 | check("200401250930.01Z", -1, 0); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 70 | |
vlm | 81057a8 | 2004-08-07 03:52:26 +0000 | [diff] [blame] | 71 | /* These six are from X.690:11.7.5 */ |
| 72 | check("19920520240000Z", -1, 0); /* midnight represented incorrectly */ |
| 73 | //check("19920622123421.0Z", -1, 0); /* spurious trailing zeros */ |
| 74 | //check("19920722132100.30Z", -1, 0); /* spurious trailing zeros */ |
| 75 | check("19920521000000Z", 706406400, 0); |
| 76 | check("19920622123421Z", 709216461, 0); |
| 77 | check("19920722132100.3Z", 711811260, 0); |
| 78 | |
| 79 | check("20040125093007Z", 1075023007, 0); |
| 80 | check("20040125093007+00", 1075023007, 0); |
| 81 | check("20040125093007.01+0000", 1075023007, 0); |
| 82 | check("20040125093007,1+0000", 1075023007, 0); |
| 83 | check("20040125093007-0800", 1075051807, 0); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 84 | |
vlm | 0f8e5c1 | 2004-08-07 04:16:42 +0000 | [diff] [blame] | 85 | rcheck(1075023007, "20040125093007Z", 1); |
| 86 | |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 87 | if(ac > 1) { |
| 88 | /* These will be valid only inside PST time zone */ |
vlm | 81057a8 | 2004-08-07 03:52:26 +0000 | [diff] [blame] | 89 | check("20040125093007", 1075051807, 0); |
| 90 | check("200401250930", 1075051800, 0); |
| 91 | check("20040125093000,01", 1075051800, 0); |
| 92 | check("20040125093000,1234", 1075051800, 0); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 93 | |
vlm | 0f8e5c1 | 2004-08-07 04:16:42 +0000 | [diff] [blame] | 94 | rcheck(1075023007, "20040125013007-0800", 0); |
| 95 | } |
vlm | 81057a8 | 2004-08-07 03:52:26 +0000 | [diff] [blame] | 96 | |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 97 | return 0; |
| 98 | } |
vlm | 81057a8 | 2004-08-07 03:52:26 +0000 | [diff] [blame] | 99 | |
| 100 | /* |
| 101 | * Dummy function. |
| 102 | */ |
| 103 | |
vlm | 39ba4c4 | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 104 | asn_enc_rval_t |
vlm | ef6355b | 2004-09-29 13:26:15 +0000 | [diff] [blame] | 105 | OCTET_STRING_encode_der(asn_TYPE_descriptor_t *td, void *ptr, int tag_mode, ber_tlv_tag_t tag, asn_app_consume_bytes_f *cb, void *app_key) { |
vlm | 39ba4c4 | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 106 | asn_enc_rval_t erval; |
vlm | d3da851 | 2004-08-19 13:26:54 +0000 | [diff] [blame] | 107 | |
| 108 | (void)td; |
| 109 | (void)ptr; |
| 110 | (void)tag_mode; |
| 111 | (void)tag; |
| 112 | (void)cb; |
| 113 | (void)app_key; |
| 114 | |
vlm | 81057a8 | 2004-08-07 03:52:26 +0000 | [diff] [blame] | 115 | return erval; |
| 116 | } |
vlm | 39ba4c4 | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 117 | |
| 118 | asn_enc_rval_t |
vlm | 9de248e | 2004-10-20 15:50:55 +0000 | [diff] [blame] | 119 | OCTET_STRING_encode_xer_utf8(asn_TYPE_descriptor_t *td, void *ptr, int ilevel, enum xer_encoder_flags_e flags, asn_app_consume_bytes_f *cb, void *app_key) { |
vlm | 39ba4c4 | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 120 | asn_enc_rval_t erval; |
| 121 | |
| 122 | (void)td; |
| 123 | (void)ptr; |
| 124 | (void)ilevel; |
| 125 | (void)flags; |
| 126 | (void)cb; |
| 127 | (void)app_key; |
| 128 | |
| 129 | return erval; |
| 130 | } |