You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
104 lines
2.8 KiB
104 lines
2.8 KiB
15 years ago
|
/* This file is part of the KDE project
|
||
|
*
|
||
|
* Copyright (C) 2000,2001 George Staikos <staikos@kde.org>
|
||
|
*
|
||
|
* This library is free software; you can redistribute it and/or
|
||
|
* modify it under the terms of the GNU Library General Public
|
||
|
* License as published by the Free Software Foundation; either
|
||
|
* version 2 of the License, or (at your option) any later version.
|
||
|
*
|
||
|
* This library is distributed in the hope that it will be useful,
|
||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
* Library General Public License for more details.
|
||
|
*
|
||
|
* You should have received a copy of the GNU Library General Public License
|
||
|
* along with this library; see the file COPYING.LIB. If not, write to
|
||
|
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
* Boston, MA 02110-1301, USA.
|
||
|
*/
|
||
|
|
||
|
|
||
|
#include "ksslutils.h"
|
||
|
|
||
15 years ago
|
#include <tqstring.h>
|
||
12 years ago
|
#include <tdeglobal.h>
|
||
|
#include <tdelocale.h>
|
||
15 years ago
|
#include <tqdatetime.h>
|
||
15 years ago
|
|
||
|
#include "kopenssl.h"
|
||
|
|
||
|
#ifdef KSSL_HAVE_SSL
|
||
|
// This code is mostly taken from OpenSSL v0.9.5a
|
||
|
// by Eric Young
|
||
15 years ago
|
TQDateTime ASN1_UTCTIME_QDateTime(ASN1_UTCTIME *tm, int *isGmt) {
|
||
|
TQDateTime qdt;
|
||
15 years ago
|
char *v;
|
||
|
int gmt=0;
|
||
8 years ago
|
int gentime=0;
|
||
|
int yoffset=0;
|
||
|
int yearbase=1900;
|
||
15 years ago
|
int i;
|
||
|
int y=0,M=0,d=0,h=0,m=0,s=0;
|
||
15 years ago
|
TQDate qdate;
|
||
|
TQTime qtime;
|
||
15 years ago
|
|
||
|
i = tm->length;
|
||
|
v = (char *)tm->data;
|
||
8 years ago
|
if ((i == 15) || (i == 21)) {
|
||
|
gentime=1;
|
||
|
yoffset=2;
|
||
|
yearbase=0;
|
||
|
}
|
||
15 years ago
|
if (i < 10) goto auq_err;
|
||
|
if (v[i-1] == 'Z') gmt=1;
|
||
8 years ago
|
for (i=0; i<10+yoffset; i++)
|
||
15 years ago
|
if ((v[i] > '9') || (v[i] < '0')) goto auq_err;
|
||
8 years ago
|
y = (v[0+yoffset]-'0')*10+(v[1+yoffset]-'0');
|
||
|
if (gentime)
|
||
|
y += (v[0]-'0')*1000+(v[1]-'0')*100;
|
||
15 years ago
|
if (y < 50) y+=100;
|
||
8 years ago
|
M = (v[2+yoffset]-'0')*10+(v[3+yoffset]-'0');
|
||
15 years ago
|
if ((M > 12) || (M < 1)) goto auq_err;
|
||
8 years ago
|
d = (v[4+yoffset]-'0')*10+(v[5+yoffset]-'0');
|
||
|
h = (v[6+yoffset]-'0')*10+(v[7+yoffset]-'0');
|
||
|
m = (v[8+yoffset]-'0')*10+(v[9+yoffset]-'0');
|
||
|
if ( (v[10+yoffset] >= '0') && (v[10+yoffset] <= '9') &&
|
||
|
(v[11+yoffset] >= '0') && (v[11+yoffset] <= '9'))
|
||
|
s = (v[10+yoffset]-'0')*10+(v[11+yoffset]-'0');
|
||
|
|
||
15 years ago
|
// localize the date and display it.
|
||
8 years ago
|
qdate.setYMD(y+yearbase, M, d);
|
||
15 years ago
|
qtime.setHMS(h,m,s);
|
||
|
qdt.setDate(qdate); qdt.setTime(qtime);
|
||
|
auq_err:
|
||
|
if (isGmt) *isGmt = gmt;
|
||
|
return qdt;
|
||
|
}
|
||
|
|
||
|
|
||
15 years ago
|
TQString ASN1_UTCTIME_QString(ASN1_UTCTIME *tm) {
|
||
|
TQString qstr;
|
||
15 years ago
|
int gmt;
|
||
15 years ago
|
TQDateTime qdt = ASN1_UTCTIME_QDateTime(tm, &gmt);
|
||
15 years ago
|
|
||
12 years ago
|
qstr = TDEGlobal::locale()->formatDateTime(qdt, false, true);
|
||
15 years ago
|
if (gmt) {
|
||
|
qstr += " ";
|
||
|
qstr += i18n("GMT");
|
||
|
}
|
||
|
return qstr;
|
||
|
}
|
||
|
|
||
|
|
||
15 years ago
|
TQString ASN1_INTEGER_QString(ASN1_INTEGER *aint) {
|
||
8 years ago
|
char *rep = KOSSL::self()->i2s_ASN1_INTEGER(NULL, aint);
|
||
|
TQString yy = rep;
|
||
|
KOSSL::self()->CRYPTO_free(rep);
|
||
|
return yy;
|
||
15 years ago
|
}
|
||
|
|
||
|
|
||
|
#endif
|
||
|
|