| OLD | NEW |
| 1 /* crypto/asn1/a_gentm.c */ | 1 /* crypto/asn1/a_gentm.c */ |
| 2 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
| 3 * All rights reserved. | 3 * All rights reserved. |
| 4 * | 4 * |
| 5 * This package is an SSL implementation written | 5 * This package is an SSL implementation written |
| 6 * by Eric Young (eay@cryptsoft.com). | 6 * by Eric Young (eay@cryptsoft.com). |
| 7 * The implementation was written so as to conform with Netscapes SSL. | 7 * The implementation was written so as to conform with Netscapes SSL. |
| 8 * | 8 * |
| 9 * This library is free for commercial and non-commercial use as long as | 9 * This library is free for commercial and non-commercial use as long as |
| 10 * the following conditions are aheared to. The following conditions | 10 * the following conditions are aheared to. The following conditions |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 err: | 110 err: |
| 111 if ((ret != NULL) && ((a == NULL) || (*a != ret))) | 111 if ((ret != NULL) && ((a == NULL) || (*a != ret))) |
| 112 M_ASN1_GENERALIZEDTIME_free(ret); | 112 M_ASN1_GENERALIZEDTIME_free(ret); |
| 113 return(NULL); | 113 return(NULL); |
| 114 } | 114 } |
| 115 | 115 |
| 116 #endif | 116 #endif |
| 117 | 117 |
| 118 int ASN1_GENERALIZEDTIME_check(ASN1_GENERALIZEDTIME *d) | 118 int ASN1_GENERALIZEDTIME_check(ASN1_GENERALIZEDTIME *d) |
| 119 { | 119 { |
| 120 » static int min[9]={ 0, 0, 1, 1, 0, 0, 0, 0, 0}; | 120 » static const int min[9]={ 0, 0, 1, 1, 0, 0, 0, 0, 0}; |
| 121 » static int max[9]={99, 99,12,31,23,59,59,12,59}; | 121 » static const int max[9]={99, 99,12,31,23,59,59,12,59}; |
| 122 char *a; | 122 char *a; |
| 123 int n,i,l,o; | 123 int n,i,l,o; |
| 124 | 124 |
| 125 if (d->type != V_ASN1_GENERALIZEDTIME) return(0); | 125 if (d->type != V_ASN1_GENERALIZEDTIME) return(0); |
| 126 l=d->length; | 126 l=d->length; |
| 127 a=(char *)d->data; | 127 a=(char *)d->data; |
| 128 o=0; | 128 o=0; |
| 129 /* GENERALIZEDTIME is similar to UTCTIME except the year is | 129 /* GENERALIZEDTIME is similar to UTCTIME except the year is |
| 130 * represented as YYYY. This stuff treats everything as a two digit | 130 * represented as YYYY. This stuff treats everything as a two digit |
| 131 * field so make first two fields 00 to 99 | 131 * field so make first two fields 00 to 99 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 { | 169 { |
| 170 if ((a[o] < '0') || (a[o] > '9')) goto err; | 170 if ((a[o] < '0') || (a[o] > '9')) goto err; |
| 171 n= a[o]-'0'; | 171 n= a[o]-'0'; |
| 172 o++; | 172 o++; |
| 173 if ((a[o] < '0') || (a[o] > '9')) goto err; | 173 if ((a[o] < '0') || (a[o] > '9')) goto err; |
| 174 n=(n*10)+ a[o]-'0'; | 174 n=(n*10)+ a[o]-'0'; |
| 175 if ((n < min[i]) || (n > max[i])) goto err; | 175 if ((n < min[i]) || (n > max[i])) goto err; |
| 176 o++; | 176 o++; |
| 177 } | 177 } |
| 178 } | 178 } |
| 179 else |
| 180 { |
| 181 /* Missing time zone information. */ |
| 182 goto err; |
| 183 } |
| 179 return(o == l); | 184 return(o == l); |
| 180 err: | 185 err: |
| 181 return(0); | 186 return(0); |
| 182 } | 187 } |
| 183 | 188 |
| 184 int ASN1_GENERALIZEDTIME_set_string(ASN1_GENERALIZEDTIME *s, const char *str) | 189 int ASN1_GENERALIZEDTIME_set_string(ASN1_GENERALIZEDTIME *s, const char *str) |
| 185 { | 190 { |
| 186 ASN1_GENERALIZEDTIME t; | 191 ASN1_GENERALIZEDTIME t; |
| 187 | 192 |
| 188 t.type=V_ASN1_GENERALIZEDTIME; | 193 t.type=V_ASN1_GENERALIZEDTIME; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 199 } | 204 } |
| 200 return(1); | 205 return(1); |
| 201 } | 206 } |
| 202 else | 207 else |
| 203 return(0); | 208 return(0); |
| 204 } | 209 } |
| 205 | 210 |
| 206 ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_set(ASN1_GENERALIZEDTIME *s, | 211 ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_set(ASN1_GENERALIZEDTIME *s, |
| 207 time_t t) | 212 time_t t) |
| 208 { | 213 { |
| 214 return ASN1_GENERALIZEDTIME_adj(s, t, 0, 0); |
| 215 } |
| 216 |
| 217 ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_adj(ASN1_GENERALIZEDTIME *s, |
| 218 time_t t, int offset_day, long offset_sec) |
| 219 { |
| 209 char *p; | 220 char *p; |
| 210 struct tm *ts; | 221 struct tm *ts; |
| 211 struct tm data; | 222 struct tm data; |
| 212 size_t len = 20; | 223 size_t len = 20; |
| 213 | 224 |
| 214 if (s == NULL) | 225 if (s == NULL) |
| 215 s=M_ASN1_GENERALIZEDTIME_new(); | 226 s=M_ASN1_GENERALIZEDTIME_new(); |
| 216 if (s == NULL) | 227 if (s == NULL) |
| 217 return(NULL); | 228 return(NULL); |
| 218 | 229 |
| 219 ts=OPENSSL_gmtime(&t, &data); | 230 ts=OPENSSL_gmtime(&t, &data); |
| 220 if (ts == NULL) | 231 if (ts == NULL) |
| 221 return(NULL); | 232 return(NULL); |
| 222 | 233 |
| 234 if (offset_day || offset_sec) |
| 235 { |
| 236 if (!OPENSSL_gmtime_adj(ts, offset_day, offset_sec)) |
| 237 return NULL; |
| 238 } |
| 239 |
| 223 p=(char *)s->data; | 240 p=(char *)s->data; |
| 224 if ((p == NULL) || ((size_t)s->length < len)) | 241 if ((p == NULL) || ((size_t)s->length < len)) |
| 225 { | 242 { |
| 226 p=OPENSSL_malloc(len); | 243 p=OPENSSL_malloc(len); |
| 227 if (p == NULL) | 244 if (p == NULL) |
| 228 { | 245 { |
| 229 » » » ASN1err(ASN1_F_ASN1_GENERALIZEDTIME_SET, | 246 » » » ASN1err(ASN1_F_ASN1_GENERALIZEDTIME_ADJ, |
| 230 ERR_R_MALLOC_FAILURE); | 247 ERR_R_MALLOC_FAILURE); |
| 231 return(NULL); | 248 return(NULL); |
| 232 } | 249 } |
| 233 if (s->data != NULL) | 250 if (s->data != NULL) |
| 234 OPENSSL_free(s->data); | 251 OPENSSL_free(s->data); |
| 235 s->data=(unsigned char *)p; | 252 s->data=(unsigned char *)p; |
| 236 } | 253 } |
| 237 | 254 |
| 238 BIO_snprintf(p,len,"%04d%02d%02d%02d%02d%02dZ",ts->tm_year + 1900, | 255 BIO_snprintf(p,len,"%04d%02d%02d%02d%02d%02dZ",ts->tm_year + 1900, |
| 239 ts->tm_mon+1,ts->tm_mday,ts->tm_hour,ts->tm_min,ts->tm_sec)
; | 256 ts->tm_mon+1,ts->tm_mday,ts->tm_hour,ts->tm_min,ts->tm_sec)
; |
| 240 s->length=strlen(p); | 257 s->length=strlen(p); |
| 241 s->type=V_ASN1_GENERALIZEDTIME; | 258 s->type=V_ASN1_GENERALIZEDTIME; |
| 242 #ifdef CHARSET_EBCDIC_not | 259 #ifdef CHARSET_EBCDIC_not |
| 243 ebcdic2ascii(s->data, s->data, s->length); | 260 ebcdic2ascii(s->data, s->data, s->length); |
| 244 #endif | 261 #endif |
| 245 return(s); | 262 return(s); |
| 246 } | 263 } |
| OLD | NEW |