summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/asn1/a_time.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/asn1/a_time.c')
-rw-r--r--src/lib/libcrypto/asn1/a_time.c40
1 files changed, 37 insertions, 3 deletions
diff --git a/src/lib/libcrypto/asn1/a_time.c b/src/lib/libcrypto/asn1/a_time.c
index 159681fbcb..e2eb9b243e 100644
--- a/src/lib/libcrypto/asn1/a_time.c
+++ b/src/lib/libcrypto/asn1/a_time.c
@@ -100,18 +100,29 @@ int i2d_ASN1_TIME(ASN1_TIME *a, unsigned char **pp)
100 100
101ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s, time_t t) 101ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s, time_t t)
102 { 102 {
103 return ASN1_TIME_adj(s, t, 0, 0);
104 }
105
106ASN1_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
117int ASN1_TIME_check(ASN1_TIME *t) 128int ASN1_TIME_check(ASN1_TIME *t)
@@ -162,3 +173,26 @@ ASN1_GENERALIZEDTIME *ASN1_TIME_to_generalizedtime(ASN1_TIME *t, ASN1_GENERALIZE
162 173
163 return ret; 174 return ret;
164 } 175 }
176
177int 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 }