OLD | NEW |
1 /* crypto/asn1/a_time.c */ | 1 /* crypto/asn1/a_time.c */ |
2 /* ==================================================================== | 2 /* ==================================================================== |
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | 3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * | 8 * |
9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 return(i2d_ASN1_bytes((ASN1_STRING *)a,pp, | 93 return(i2d_ASN1_bytes((ASN1_STRING *)a,pp, |
94 a->type ,V_ASN1_UNIVERSAL)); | 94 a->type ,V_ASN1_UNIVERSAL)); |
95 ASN1err(ASN1_F_I2D_ASN1_TIME,ASN1_R_EXPECTING_A_TIME); | 95 ASN1err(ASN1_F_I2D_ASN1_TIME,ASN1_R_EXPECTING_A_TIME); |
96 return -1; | 96 return -1; |
97 } | 97 } |
98 #endif | 98 #endif |
99 | 99 |
100 | 100 |
101 ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s, time_t t) | 101 ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s, time_t t) |
102 { | 102 { |
| 103 return ASN1_TIME_adj(s, t, 0, 0); |
| 104 } |
| 105 |
| 106 ASN1_TIME *ASN1_TIME_adj(ASN1_TIME *s, time_t t, |
| 107 int offset_day, long offset_sec) |
| 108 { |
103 struct tm *ts; | 109 struct tm *ts; |
104 struct tm data; | 110 struct tm data; |
105 | 111 |
106 ts=OPENSSL_gmtime(&t,&data); | 112 ts=OPENSSL_gmtime(&t,&data); |
107 if (ts == NULL) | 113 if (ts == NULL) |
108 { | 114 { |
109 » » ASN1err(ASN1_F_ASN1_TIME_SET, ASN1_R_ERROR_GETTING_TIME); | 115 » » ASN1err(ASN1_F_ASN1_TIME_ADJ, ASN1_R_ERROR_GETTING_TIME); |
110 return NULL; | 116 return NULL; |
111 } | 117 } |
| 118 if (offset_day || offset_sec) |
| 119 { |
| 120 if (!OPENSSL_gmtime_adj(ts, offset_day, offset_sec)) |
| 121 return NULL; |
| 122 } |
112 if((ts->tm_year >= 50) && (ts->tm_year < 150)) | 123 if((ts->tm_year >= 50) && (ts->tm_year < 150)) |
113 » » » » » return ASN1_UTCTIME_set(s, t); | 124 » » » return ASN1_UTCTIME_adj(s, t, offset_day, offset_sec); |
114 » return ASN1_GENERALIZEDTIME_set(s,t); | 125 » return ASN1_GENERALIZEDTIME_adj(s, t, offset_day, offset_sec); |
115 } | 126 } |
116 | 127 |
117 int ASN1_TIME_check(ASN1_TIME *t) | 128 int ASN1_TIME_check(ASN1_TIME *t) |
118 { | 129 { |
119 if (t->type == V_ASN1_GENERALIZEDTIME) | 130 if (t->type == V_ASN1_GENERALIZEDTIME) |
120 return ASN1_GENERALIZEDTIME_check(t); | 131 return ASN1_GENERALIZEDTIME_check(t); |
121 else if (t->type == V_ASN1_UTCTIME) | 132 else if (t->type == V_ASN1_UTCTIME) |
122 return ASN1_UTCTIME_check(t); | 133 return ASN1_UTCTIME_check(t); |
123 return 0; | 134 return 0; |
124 } | 135 } |
(...skipping 30 matching lines...) Expand all Loading... |
155 newlen = t->length + 2 + 1; | 166 newlen = t->length + 2 + 1; |
156 str = (char *)ret->data; | 167 str = (char *)ret->data; |
157 /* Work out the century and prepend */ | 168 /* Work out the century and prepend */ |
158 if (t->data[0] >= '5') BUF_strlcpy(str, "19", newlen); | 169 if (t->data[0] >= '5') BUF_strlcpy(str, "19", newlen); |
159 else BUF_strlcpy(str, "20", newlen); | 170 else BUF_strlcpy(str, "20", newlen); |
160 | 171 |
161 BUF_strlcat(str, (char *)t->data, newlen); | 172 BUF_strlcat(str, (char *)t->data, newlen); |
162 | 173 |
163 return ret; | 174 return ret; |
164 } | 175 } |
| 176 |
| 177 int ASN1_TIME_set_string(ASN1_TIME *s, const char *str) |
| 178 { |
| 179 ASN1_TIME t; |
| 180 |
| 181 t.length = strlen(str); |
| 182 t.data = (unsigned char *)str; |
| 183 t.flags = 0; |
| 184 |
| 185 t.type = V_ASN1_UTCTIME; |
| 186 |
| 187 if (!ASN1_TIME_check(&t)) |
| 188 { |
| 189 t.type = V_ASN1_GENERALIZEDTIME; |
| 190 if (!ASN1_TIME_check(&t)) |
| 191 return 0; |
| 192 } |
| 193 |
| 194 if (s && !ASN1_STRING_copy((ASN1_STRING *)s, (ASN1_STRING *)&t)) |
| 195 return 0; |
| 196 |
| 197 return 1; |
| 198 } |
OLD | NEW |