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