3
* Copyright (C) 2001 - 2007 Christian Hohnstaedt.
10
#include <openssl/x509.h>
11
#include <openssl/err.h>
12
#include <openssl/opensslv.h>
16
time = ASN1_GENERALIZEDTIME_new();
20
a1time::a1time(const ASN1_TIME *a)
26
a1time::a1time(const a1time &a)
37
ASN1_TIME *a1time::get() const
39
return M_ASN1_TIME_dup(time);
42
ASN1_TIME *a1time::get_utc() const
47
a1time &a1time::set(const ASN1_TIME *a)
53
ASN1_TIME *siko = time;
54
time = ASN1_TIME_to_generalizedtime((ASN1_TIME *)a, &siko);
56
if (siko) ASN1_TIME_free(siko);
57
time=M_ASN1_TIME_dup(a);
63
a1time &a1time::set(time_t t)
65
ASN1_GENERALIZEDTIME_set(time, t);
69
a1time &a1time::set(int y, int mon, int d, int h, int m, int s)
72
gt.sprintf("%04d%02d%02d%02d%02d%02dZ", y, mon, d, h, m ,s);
77
QString a1time::toPretty() const
81
BIO * bio = BIO_new(BIO_s_mem());
83
ASN1_TIME_print(bio, time);
84
BIO_gets(bio, buf, 200);
90
QString a1time::toPlain() const
95
memcpy(b, time->data, time->length);
96
b[time->length] = '\0';
101
QString a1time::toSortable() const
106
if (ymdg( &y ,&m ,&d ,&g)) {
107
// openssl_error("time error");
110
sprintf(buf, "%04d-%02d-%02d %s",y,m,d,(g==1)?"GMT":"");
115
a1time &a1time::set(const QString &s)
117
const char *x = s.toAscii();
118
ASN1_GENERALIZEDTIME_set_string(time, (char*)x);
122
int a1time::ymdg(int *y, int *m, int *d, int *g) const
125
return ymdg(y,m,d, &h, &M, &s, g);
128
int a1time::ymdg(int *y, int *m, int *d, int *h, int *M, int *s, int *g) const
132
*y=0, *m=0, *d=0, *g=0;
135
v=(char *)time->data;
137
if (i < 14) return 1; /* it is at least 10 digits */
138
if (v[i-1] == 'Z') *g=1;
140
if ((v[i] > '9') || (v[i] < '0')) return 1;
141
*y= (v[0]-'0')*1000+(v[1]-'0')*100+(v[2]-'0')*10+(v[3]-'0');
142
*m= (v[4]-'0')*10+(v[5]-'0');
143
if ((*m > 12) || (*m < 1)) return 1;
144
*d= (v[6]-'0')*10+(v[7]-'0');
145
if ((*d > 31) || (*d < 1)) return 1;
146
*h= (v[8]-'0')*10+(v[9]-'0');
147
if ((*h > 23) || (*h < 0)) return 1;
148
*M= (v[10]-'0')*10+(v[11]-'0');
149
if ((*M > 59) || (*M < 0)) return 1;
150
*s= (v[12]-'0')*10+(v[13]-'0');
151
if ((*s > 59) || (*s < 0)) return 1;
155
a1time &a1time::now(int delta)
157
X509_gmtime_adj(time, delta);
161
a1time &a1time::operator = (const a1time &a)
167
bool const a1time::operator > (const a1time &a)
169
return (ASN1_STRING_cmp(time, a.time) == 1);
172
bool const a1time::operator < (const a1time &a)
174
return (ASN1_STRING_cmp(time, a.time) == -1);
177
bool const a1time::operator == (const a1time &a)
179
return (ASN1_STRING_cmp(time, a.time) == 0);
182
bool const a1time::operator != (const a1time &a)
184
return (ASN1_STRING_cmp(time, a.time) != 0);
187
unsigned char *a1time::d2i(const unsigned char *p, int size)
190
ASN1_TIME_free(time);
191
time = D2I_CLASH(d2i_ASN1_TIME, NULL, &p, size);
192
return (unsigned char *)p;
195
unsigned char *a1time::i2d(unsigned char *p)
197
unsigned char *mp = p;
198
i2d_ASN1_TIME(time, &mp);
202
int a1time::derSize() const
204
return i2d_ASN1_TIME(time, NULL);
208
ASN1_UTCTIME *a1time::toUTCtime() const
212
// if (!ASN1_TIME_check(t)) return NULL;
213
for (i=0; i<4; i++) {
215
year += time->data[i] - '0';
217
if (year > 2049 || year <1950)
220
if (!(ret = ASN1_UTCTIME_new ()))
223
/* If already UTC Time just copy across */
224
if (time->type == V_ASN1_UTCTIME) {
225
if(!ASN1_STRING_set(ret, time->data, time->length))
230
/* copy w/o 19 or 20 */
231
if (!ASN1_STRING_set(ret, time->data+2, time->length - 2))