summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/asn1/a_utctm.c
diff options
context:
space:
mode:
authortedu <>2014-04-18 00:10:08 +0000
committertedu <>2014-04-18 00:10:08 +0000
commit07f5c09b19f56c323fa22ebd5efb5a4df9f5dc4d (patch)
tree6327d50d69a1982f840dc68fe928ea459e2c41e0 /src/lib/libcrypto/asn1/a_utctm.c
parent288a9e368d9d4a72792b12a00ad69e3592d94073 (diff)
downloadopenbsd-07f5c09b19f56c323fa22ebd5efb5a4df9f5dc4d.tar.gz
openbsd-07f5c09b19f56c323fa22ebd5efb5a4df9f5dc4d.tar.bz2
openbsd-07f5c09b19f56c323fa22ebd5efb5a4df9f5dc4d.zip
putting most of the braces in the right column is the very least we can do.
Diffstat (limited to 'src/lib/libcrypto/asn1/a_utctm.c')
-rw-r--r--src/lib/libcrypto/asn1/a_utctm.c80
1 files changed, 40 insertions, 40 deletions
diff --git a/src/lib/libcrypto/asn1/a_utctm.c b/src/lib/libcrypto/asn1/a_utctm.c
index 0e7aca90a7..e75f2ecbb6 100644
--- a/src/lib/libcrypto/asn1/a_utctm.c
+++ b/src/lib/libcrypto/asn1/a_utctm.c
@@ -64,41 +64,41 @@
64 64
65#if 0 65#if 0
66int i2d_ASN1_UTCTIME(ASN1_UTCTIME *a, unsigned char **pp) 66int i2d_ASN1_UTCTIME(ASN1_UTCTIME *a, unsigned char **pp)
67 { 67{
68 return(i2d_ASN1_bytes((ASN1_STRING *)a,pp, 68 return(i2d_ASN1_bytes((ASN1_STRING *)a,pp,
69 V_ASN1_UTCTIME,V_ASN1_UNIVERSAL)); 69 V_ASN1_UTCTIME,V_ASN1_UNIVERSAL));
70 } 70}
71 71
72 72
73ASN1_UTCTIME *d2i_ASN1_UTCTIME(ASN1_UTCTIME **a, unsigned char **pp, 73ASN1_UTCTIME *d2i_ASN1_UTCTIME(ASN1_UTCTIME **a, unsigned char **pp,
74 long length) 74 long length)
75 { 75{
76 ASN1_UTCTIME *ret=NULL; 76 ASN1_UTCTIME *ret=NULL;
77 77
78 ret=(ASN1_UTCTIME *)d2i_ASN1_bytes((ASN1_STRING **)a,pp,length, 78 ret=(ASN1_UTCTIME *)d2i_ASN1_bytes((ASN1_STRING **)a,pp,length,
79 V_ASN1_UTCTIME,V_ASN1_UNIVERSAL); 79 V_ASN1_UTCTIME,V_ASN1_UNIVERSAL);
80 if (ret == NULL) 80 if (ret == NULL)
81 { 81 {
82 ASN1err(ASN1_F_D2I_ASN1_UTCTIME,ERR_R_NESTED_ASN1_ERROR); 82 ASN1err(ASN1_F_D2I_ASN1_UTCTIME,ERR_R_NESTED_ASN1_ERROR);
83 return(NULL); 83 return(NULL);
84 } 84 }
85 if (!ASN1_UTCTIME_check(ret)) 85 if (!ASN1_UTCTIME_check(ret))
86 { 86 {
87 ASN1err(ASN1_F_D2I_ASN1_UTCTIME,ASN1_R_INVALID_TIME_FORMAT); 87 ASN1err(ASN1_F_D2I_ASN1_UTCTIME,ASN1_R_INVALID_TIME_FORMAT);
88 goto err; 88 goto err;
89 } 89 }
90 90
91 return(ret); 91 return(ret);
92err: 92err:
93 if ((ret != NULL) && ((a == NULL) || (*a != ret))) 93 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
94 M_ASN1_UTCTIME_free(ret); 94 M_ASN1_UTCTIME_free(ret);
95 return(NULL); 95 return(NULL);
96 } 96}
97 97
98#endif 98#endif
99 99
100int ASN1_UTCTIME_check(ASN1_UTCTIME *d) 100int ASN1_UTCTIME_check(ASN1_UTCTIME *d)
101 { 101{
102 static const int min[8]={ 0, 1, 1, 0, 0, 0, 0, 0}; 102 static const int min[8]={ 0, 1, 1, 0, 0, 0, 0, 0};
103 static const int max[8]={99,12,31,23,59,59,12,59}; 103 static const int max[8]={99,12,31,23,59,59,12,59};
104 char *a; 104 char *a;
@@ -111,10 +111,10 @@ int ASN1_UTCTIME_check(ASN1_UTCTIME *d)
111 111
112 if (l < 11) goto err; 112 if (l < 11) goto err;
113 for (i=0; i<6; i++) 113 for (i=0; i<6; i++)
114 { 114 {
115 if ((i == 5) && ((a[o] == 'Z') || 115 if ((i == 5) && ((a[o] == 'Z') ||
116 (a[o] == '+') || (a[o] == '-'))) 116 (a[o] == '+') || (a[o] == '-')))
117 { i++; break; } 117 { i++; break; }
118 if ((a[o] < '0') || (a[o] > '9')) goto err; 118 if ((a[o] < '0') || (a[o] > '9')) goto err;
119 n= a[o]-'0'; 119 n= a[o]-'0';
120 if (++o > l) goto err; 120 if (++o > l) goto err;
@@ -124,15 +124,15 @@ int ASN1_UTCTIME_check(ASN1_UTCTIME *d)
124 if (++o > l) goto err; 124 if (++o > l) goto err;
125 125
126 if ((n < min[i]) || (n > max[i])) goto err; 126 if ((n < min[i]) || (n > max[i])) goto err;
127 } 127 }
128 if (a[o] == 'Z') 128 if (a[o] == 'Z')
129 o++; 129 o++;
130 else if ((a[o] == '+') || (a[o] == '-')) 130 else if ((a[o] == '+') || (a[o] == '-'))
131 { 131 {
132 o++; 132 o++;
133 if (o+4 > l) goto err; 133 if (o+4 > l) goto err;
134 for (i=6; i<8; i++) 134 for (i=6; i<8; i++)
135 { 135 {
136 if ((a[o] < '0') || (a[o] > '9')) goto err; 136 if ((a[o] < '0') || (a[o] > '9')) goto err;
137 n= a[o]-'0'; 137 n= a[o]-'0';
138 o++; 138 o++;
@@ -140,43 +140,43 @@ int ASN1_UTCTIME_check(ASN1_UTCTIME *d)
140 n=(n*10)+ a[o]-'0'; 140 n=(n*10)+ a[o]-'0';
141 if ((n < min[i]) || (n > max[i])) goto err; 141 if ((n < min[i]) || (n > max[i])) goto err;
142 o++; 142 o++;
143 }
144 } 143 }
144 }
145 return(o == l); 145 return(o == l);
146err: 146err:
147 return(0); 147 return(0);
148 } 148}
149 149
150int ASN1_UTCTIME_set_string(ASN1_UTCTIME *s, const char *str) 150int ASN1_UTCTIME_set_string(ASN1_UTCTIME *s, const char *str)
151 { 151{
152 ASN1_UTCTIME t; 152 ASN1_UTCTIME t;
153 153
154 t.type=V_ASN1_UTCTIME; 154 t.type=V_ASN1_UTCTIME;
155 t.length=strlen(str); 155 t.length=strlen(str);
156 t.data=(unsigned char *)str; 156 t.data=(unsigned char *)str;
157 if (ASN1_UTCTIME_check(&t)) 157 if (ASN1_UTCTIME_check(&t))
158 { 158 {
159 if (s != NULL) 159 if (s != NULL)
160 { 160 {
161 if (!ASN1_STRING_set((ASN1_STRING *)s, 161 if (!ASN1_STRING_set((ASN1_STRING *)s,
162 (unsigned char *)str,t.length)) 162 (unsigned char *)str,t.length))
163 return 0; 163 return 0;
164 s->type = V_ASN1_UTCTIME; 164 s->type = V_ASN1_UTCTIME;
165 }
166 return(1);
167 } 165 }
166 return(1);
167 }
168 else 168 else
169 return(0); 169 return(0);
170 } 170}
171 171
172ASN1_UTCTIME *ASN1_UTCTIME_set(ASN1_UTCTIME *s, time_t t) 172ASN1_UTCTIME *ASN1_UTCTIME_set(ASN1_UTCTIME *s, time_t t)
173 { 173{
174 return ASN1_UTCTIME_adj(s, t, 0, 0); 174 return ASN1_UTCTIME_adj(s, t, 0, 0);
175 } 175}
176 176
177ASN1_UTCTIME *ASN1_UTCTIME_adj(ASN1_UTCTIME *s, time_t t, 177ASN1_UTCTIME *ASN1_UTCTIME_adj(ASN1_UTCTIME *s, time_t t,
178 int offset_day, long offset_sec) 178 int offset_day, long offset_sec)
179 { 179{
180 char *p; 180 char *p;
181 struct tm *ts; 181 struct tm *ts;
182 struct tm data; 182 struct tm data;
@@ -192,38 +192,38 @@ ASN1_UTCTIME *ASN1_UTCTIME_adj(ASN1_UTCTIME *s, time_t t,
192 return(NULL); 192 return(NULL);
193 193
194 if (offset_day || offset_sec) 194 if (offset_day || offset_sec)
195 { 195 {
196 if (!OPENSSL_gmtime_adj(ts, offset_day, offset_sec)) 196 if (!OPENSSL_gmtime_adj(ts, offset_day, offset_sec))
197 return NULL; 197 return NULL;
198 } 198 }
199 199
200 if((ts->tm_year < 50) || (ts->tm_year >= 150)) 200 if((ts->tm_year < 50) || (ts->tm_year >= 150))
201 return NULL; 201 return NULL;
202 202
203 p=(char *)s->data; 203 p=(char *)s->data;
204 if ((p == NULL) || ((size_t)s->length < len)) 204 if ((p == NULL) || ((size_t)s->length < len))
205 { 205 {
206 p=malloc(len); 206 p=malloc(len);
207 if (p == NULL) 207 if (p == NULL)
208 { 208 {
209 ASN1err(ASN1_F_ASN1_UTCTIME_ADJ,ERR_R_MALLOC_FAILURE); 209 ASN1err(ASN1_F_ASN1_UTCTIME_ADJ,ERR_R_MALLOC_FAILURE);
210 return(NULL); 210 return(NULL);
211 } 211 }
212 if (s->data != NULL) 212 if (s->data != NULL)
213 free(s->data); 213 free(s->data);
214 s->data=(unsigned char *)p; 214 s->data=(unsigned char *)p;
215 } 215 }
216 216
217 (void) snprintf(p,len,"%02d%02d%02d%02d%02d%02dZ",ts->tm_year%100, 217 (void) snprintf(p,len,"%02d%02d%02d%02d%02d%02dZ",ts->tm_year%100,
218 ts->tm_mon+1,ts->tm_mday,ts->tm_hour,ts->tm_min,ts->tm_sec); 218 ts->tm_mon+1,ts->tm_mday,ts->tm_hour,ts->tm_min,ts->tm_sec);
219 s->length=strlen(p); 219 s->length=strlen(p);
220 s->type=V_ASN1_UTCTIME; 220 s->type=V_ASN1_UTCTIME;
221 return(s); 221 return(s);
222 } 222}
223 223
224 224
225int ASN1_UTCTIME_cmp_time_t(const ASN1_UTCTIME *s, time_t t) 225int ASN1_UTCTIME_cmp_time_t(const ASN1_UTCTIME *s, time_t t)
226 { 226{
227 struct tm *tm; 227 struct tm *tm;
228 struct tm data; 228 struct tm data;
229 int offset; 229 int offset;
@@ -234,11 +234,11 @@ int ASN1_UTCTIME_cmp_time_t(const ASN1_UTCTIME *s, time_t t)
234 if (s->data[12] == 'Z') 234 if (s->data[12] == 'Z')
235 offset=0; 235 offset=0;
236 else 236 else
237 { 237 {
238 offset = g2(s->data+13)*60+g2(s->data+15); 238 offset = g2(s->data+13)*60+g2(s->data+15);
239 if (s->data[12] == '-') 239 if (s->data[12] == '-')
240 offset = -offset; 240 offset = -offset;
241 } 241 }
242 242
243 t -= offset*60; /* FIXME: may overflow in extreme cases */ 243 t -= offset*60; /* FIXME: may overflow in extreme cases */
244 244
@@ -258,12 +258,12 @@ int ASN1_UTCTIME_cmp_time_t(const ASN1_UTCTIME *s, time_t t)
258#undef return_cmp 258#undef return_cmp
259 259
260 return 0; 260 return 0;
261 } 261}
262 262
263 263
264#if 0 264#if 0
265time_t ASN1_UTCTIME_get(const ASN1_UTCTIME *s) 265time_t ASN1_UTCTIME_get(const ASN1_UTCTIME *s)
266 { 266{
267 struct tm tm; 267 struct tm tm;
268 int offset; 268 int offset;
269 269
@@ -281,11 +281,11 @@ time_t ASN1_UTCTIME_get(const ASN1_UTCTIME *s)
281 if(s->data[12] == 'Z') 281 if(s->data[12] == 'Z')
282 offset=0; 282 offset=0;
283 else 283 else
284 { 284 {
285 offset=g2(s->data+13)*60+g2(s->data+15); 285 offset=g2(s->data+13)*60+g2(s->data+15);
286 if(s->data[12] == '-') 286 if(s->data[12] == '-')
287 offset= -offset; 287 offset= -offset;
288 } 288 }
289#undef g2 289#undef g2
290 290
291 return mktime(&tm)-offset*60; /* FIXME: mktime assumes the current timezone 291 return mktime(&tm)-offset*60; /* FIXME: mktime assumes the current timezone
@@ -296,5 +296,5 @@ time_t ASN1_UTCTIME_get(const ASN1_UTCTIME *s)
296 * non-standard. 296 * non-standard.
297 * Also time_t is inappropriate for general 297 * Also time_t is inappropriate for general
298 * UTC times because it may a 32 bit type. */ 298 * UTC times because it may a 32 bit type. */
299 } 299}
300#endif 300#endif