diff options
author | beck <> | 1999-09-29 04:37:45 +0000 |
---|---|---|
committer | beck <> | 1999-09-29 04:37:45 +0000 |
commit | de8f24ea083384bb66b32ec105dc4743c5663cdf (patch) | |
tree | 1412176ae62a3cab2cf2b0b92150fcbceaac6092 /src/lib/libcrypto/asn1/a_utctm.c | |
parent | cb929d29896bcb87c2a97417fbd03e50078fc178 (diff) | |
download | openbsd-de8f24ea083384bb66b32ec105dc4743c5663cdf.tar.gz openbsd-de8f24ea083384bb66b32ec105dc4743c5663cdf.tar.bz2 openbsd-de8f24ea083384bb66b32ec105dc4743c5663cdf.zip |
OpenSSL 0.9.4 merge
Diffstat (limited to 'src/lib/libcrypto/asn1/a_utctm.c')
-rw-r--r-- | src/lib/libcrypto/asn1/a_utctm.c | 98 |
1 files changed, 73 insertions, 25 deletions
diff --git a/src/lib/libcrypto/asn1/a_utctm.c b/src/lib/libcrypto/asn1/a_utctm.c index 17a7abbb67..688199fdd2 100644 --- a/src/lib/libcrypto/asn1/a_utctm.c +++ b/src/lib/libcrypto/asn1/a_utctm.c | |||
@@ -58,26 +58,35 @@ | |||
58 | 58 | ||
59 | #include <stdio.h> | 59 | #include <stdio.h> |
60 | #include <time.h> | 60 | #include <time.h> |
61 | #ifdef VMS | ||
62 | #include <descrip.h> | ||
63 | #include <lnmdef.h> | ||
64 | #include <starlet.h> | ||
65 | #endif | ||
61 | #include "cryptlib.h" | 66 | #include "cryptlib.h" |
62 | #include "asn1.h" | 67 | #include <openssl/asn1.h> |
63 | |||
64 | /* ASN1err(ASN1_F_ASN1_UTCTIME_NEW,ASN1_R_UTCTIME_TOO_LONG); | ||
65 | * ASN1err(ASN1_F_D2I_ASN1_UTCTIME,ASN1_R_EXPECTING_A_UTCTIME); | ||
66 | */ | ||
67 | 68 | ||
68 | int i2d_ASN1_UTCTIME(a,pp) | 69 | int i2d_ASN1_UTCTIME(ASN1_UTCTIME *a, unsigned char **pp) |
69 | ASN1_UTCTIME *a; | ||
70 | unsigned char **pp; | ||
71 | { | 70 | { |
71 | #ifndef CHARSET_EBCDIC | ||
72 | return(i2d_ASN1_bytes((ASN1_STRING *)a,pp, | 72 | return(i2d_ASN1_bytes((ASN1_STRING *)a,pp, |
73 | V_ASN1_UTCTIME,V_ASN1_UNIVERSAL)); | 73 | V_ASN1_UTCTIME,V_ASN1_UNIVERSAL)); |
74 | #else | ||
75 | /* KLUDGE! We convert to ascii before writing DER */ | ||
76 | int len; | ||
77 | char tmp[24]; | ||
78 | ASN1_STRING x = *(ASN1_STRING *)a; | ||
79 | |||
80 | len = x.length; | ||
81 | ebcdic2ascii(tmp, x.data, (len >= sizeof tmp) ? sizeof tmp : len); | ||
82 | x.data = tmp; | ||
83 | return i2d_ASN1_bytes(&x, pp, V_ASN1_UTCTIME,V_ASN1_UNIVERSAL); | ||
84 | #endif | ||
74 | } | 85 | } |
75 | 86 | ||
76 | 87 | ||
77 | ASN1_UTCTIME *d2i_ASN1_UTCTIME(a, pp, length) | 88 | ASN1_UTCTIME *d2i_ASN1_UTCTIME(ASN1_UTCTIME **a, unsigned char **pp, |
78 | ASN1_UTCTIME **a; | 89 | long length) |
79 | unsigned char **pp; | ||
80 | long length; | ||
81 | { | 90 | { |
82 | ASN1_UTCTIME *ret=NULL; | 91 | ASN1_UTCTIME *ret=NULL; |
83 | 92 | ||
@@ -85,9 +94,12 @@ long length; | |||
85 | V_ASN1_UTCTIME,V_ASN1_UNIVERSAL); | 94 | V_ASN1_UTCTIME,V_ASN1_UNIVERSAL); |
86 | if (ret == NULL) | 95 | if (ret == NULL) |
87 | { | 96 | { |
88 | ASN1err(ASN1_F_D2I_ASN1_UTCTIME,ASN1_R_ERROR_STACK); | 97 | ASN1err(ASN1_F_D2I_ASN1_UTCTIME,ERR_R_NESTED_ASN1_ERROR); |
89 | return(NULL); | 98 | return(NULL); |
90 | } | 99 | } |
100 | #ifdef CHARSET_EBCDIC | ||
101 | ascii2ebcdic(ret->data, ret->data, ret->length); | ||
102 | #endif | ||
91 | if (!ASN1_UTCTIME_check(ret)) | 103 | if (!ASN1_UTCTIME_check(ret)) |
92 | { | 104 | { |
93 | ASN1err(ASN1_F_D2I_ASN1_UTCTIME,ASN1_R_INVALID_TIME_FORMAT); | 105 | ASN1err(ASN1_F_D2I_ASN1_UTCTIME,ASN1_R_INVALID_TIME_FORMAT); |
@@ -101,8 +113,7 @@ err: | |||
101 | return(NULL); | 113 | return(NULL); |
102 | } | 114 | } |
103 | 115 | ||
104 | int ASN1_UTCTIME_check(d) | 116 | int ASN1_UTCTIME_check(ASN1_UTCTIME *d) |
105 | ASN1_UTCTIME *d; | ||
106 | { | 117 | { |
107 | static int min[8]={ 0, 1, 1, 0, 0, 0, 0, 0}; | 118 | static int min[8]={ 0, 1, 1, 0, 0, 0, 0, 0}; |
108 | static int max[8]={99,12,31,23,59,59,12,59}; | 119 | static int max[8]={99,12,31,23,59,59,12,59}; |
@@ -152,9 +163,7 @@ err: | |||
152 | return(0); | 163 | return(0); |
153 | } | 164 | } |
154 | 165 | ||
155 | int ASN1_UTCTIME_set_string(s,str) | 166 | int ASN1_UTCTIME_set_string(ASN1_UTCTIME *s, char *str) |
156 | ASN1_UTCTIME *s; | ||
157 | char *str; | ||
158 | { | 167 | { |
159 | ASN1_UTCTIME t; | 168 | ASN1_UTCTIME t; |
160 | 169 | ||
@@ -174,13 +183,11 @@ char *str; | |||
174 | return(0); | 183 | return(0); |
175 | } | 184 | } |
176 | 185 | ||
177 | ASN1_UTCTIME *ASN1_UTCTIME_set(s, t) | 186 | ASN1_UTCTIME *ASN1_UTCTIME_set(ASN1_UTCTIME *s, time_t t) |
178 | ASN1_UTCTIME *s; | ||
179 | time_t t; | ||
180 | { | 187 | { |
181 | char *p; | 188 | char *p; |
182 | struct tm *ts; | 189 | struct tm *ts; |
183 | #if defined(THREADS) | 190 | #if defined(THREADS) && !defined(WIN32) |
184 | struct tm data; | 191 | struct tm data; |
185 | #endif | 192 | #endif |
186 | 193 | ||
@@ -189,10 +196,48 @@ time_t t; | |||
189 | if (s == NULL) | 196 | if (s == NULL) |
190 | return(NULL); | 197 | return(NULL); |
191 | 198 | ||
192 | #if defined(THREADS) | 199 | #if defined(THREADS) && !defined(WIN32) |
193 | ts=(struct tm *)gmtime_r(&t,&data); | 200 | gmtime_r(&t,&data); /* should return &data, but doesn't on some systems, so we don't even look at the return value */ |
201 | ts=&data; | ||
194 | #else | 202 | #else |
195 | ts=(struct tm *)gmtime(&t); | 203 | ts=gmtime(&t); |
204 | #endif | ||
205 | #ifdef VMS | ||
206 | if (ts == NULL) | ||
207 | { | ||
208 | static $DESCRIPTOR(tabnam,"LNM$DCL_LOGICAL"); | ||
209 | static $DESCRIPTOR(lognam,"SYS$TIMEZONE_DIFFERENTIAL"); | ||
210 | char result[256]; | ||
211 | unsigned int reslen = 0; | ||
212 | struct { | ||
213 | short buflen; | ||
214 | short code; | ||
215 | void *bufaddr; | ||
216 | unsigned int *reslen; | ||
217 | } itemlist[] = { | ||
218 | { 0, LNM$_STRING, 0, 0 }, | ||
219 | { 0, 0, 0, 0 }, | ||
220 | }; | ||
221 | int status; | ||
222 | |||
223 | /* Get the value for SYS$TIMEZONE_DIFFERENTIAL */ | ||
224 | itemlist[0].buflen = sizeof(result); | ||
225 | itemlist[0].bufaddr = result; | ||
226 | itemlist[0].reslen = &reslen; | ||
227 | status = sys$trnlnm(0, &tabnam, &lognam, 0, itemlist); | ||
228 | if (!(status & 1)) | ||
229 | return NULL; | ||
230 | result[reslen] = '\0'; | ||
231 | |||
232 | /* Get the numerical value of the equivalence string */ | ||
233 | status = atoi(result); | ||
234 | |||
235 | /* and use it to move time to GMT */ | ||
236 | t -= status; | ||
237 | |||
238 | /* then convert the result to the time structure */ | ||
239 | ts=(struct tm *)localtime(&t); | ||
240 | } | ||
196 | #endif | 241 | #endif |
197 | p=(char *)s->data; | 242 | p=(char *)s->data; |
198 | if ((p == NULL) || (s->length < 14)) | 243 | if ((p == NULL) || (s->length < 14)) |
@@ -208,5 +253,8 @@ time_t t; | |||
208 | ts->tm_mon+1,ts->tm_mday,ts->tm_hour,ts->tm_min,ts->tm_sec); | 253 | ts->tm_mon+1,ts->tm_mday,ts->tm_hour,ts->tm_min,ts->tm_sec); |
209 | s->length=strlen(p); | 254 | s->length=strlen(p); |
210 | s->type=V_ASN1_UTCTIME; | 255 | s->type=V_ASN1_UTCTIME; |
256 | #ifdef CHARSET_EBCDIC_not | ||
257 | ebcdic2ascii(s->data, s->data, s->length); | ||
258 | #endif | ||
211 | return(s); | 259 | return(s); |
212 | } | 260 | } |