# kio Library API Documentation

Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Source Files

# ksslutils.cc

    00001 /* This file is part of the KDE project
    00002  *
    00003  * Copyright (C) 2000,2001 George Staikos <staikos@kde.org>
    00004  *
    00005  * This library is free software; you can redistribute it and/or
    00006  * modify it under the terms of the GNU Library General Public
    00007  * License as published by the Free Software Foundation; either
    00008  * version 2 of the License, or (at your option) any later version.
    00009  *
    00010  * This library is distributed in the hope that it will be useful,
    00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00013  * Library General Public License for more details.
    00014  *
    00015  * You should have received a copy of the GNU Library General Public License
    00016  * along with this library; see the file COPYING.LIB.  If not, write to
    00017  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    00018  * Boston, MA 02111-1307, USA.
    00019  */
    00020
    00021
    00022 #include "ksslutils.h"
    00023
    00024 #include <qstring.h>
    00025 #include <kglobal.h>
    00026 #include <klocale.h>
    00027 #include <qdatetime.h>
    00028
    00029 #include "kopenssl.h"
    00030
    00031 #ifdef KSSL_HAVE_SSL
    00032 // This code is mostly taken from OpenSSL v0.9.5a
    00033 // by Eric Young
    00034 QDateTime ASN1_UTCTIME_QDateTime(ASN1_UTCTIME *tm, int *isGmt) {
    00035 QDateTime qdt;
    00036 char *v;
    00037 int gmt=0;
    00038 int i;
    00039 int y=0,M=0,d=0,h=0,m=0,s=0;
    00040 QDate qdate;
    00041 QTime qtime;
    00042
    00043   i = tm->length;
    00044   v = (char *)tm->data;
    00045
    00046   if (i < 10) goto auq_err;
    00047   if (v[i-1] == 'Z') gmt=1;
    00048   for (i=0; i<10; i++)
    00049           if ((v[i] > '9') || (v[i] < '0')) goto auq_err;
    00050   y = (v[0]-'0')*10+(v[1]-'0');
    00051   if (y < 50) y+=100;
    00052   M = (v[2]-'0')*10+(v[3]-'0');
    00053   if ((M > 12) || (M < 1)) goto auq_err;
    00054   d = (v[4]-'0')*10+(v[5]-'0');
    00055   h = (v[6]-'0')*10+(v[7]-'0');
    00056   m =  (v[8]-'0')*10+(v[9]-'0');
    00057   if (    (v[10] >= '0') && (v[10] <= '9') &&
    00058           (v[11] >= '0') && (v[11] <= '9'))
    00059           s = (v[10]-'0')*10+(v[11]-'0');
    00060
    00061   // localize the date and display it.
    00062   qdate.setYMD(y+1900, M, d);
    00063   qtime.setHMS(h,m,s);
    00064   qdt.setDate(qdate); qdt.setTime(qtime);
    00065   auq_err:
    00066   if (isGmt) *isGmt = gmt;
    00067 return qdt;
    00068 }
    00069
    00070
    00071 QString ASN1_UTCTIME_QString(ASN1_UTCTIME *tm) {
    00072   QString qstr;
    00073   int gmt;
    00074   QDateTime qdt = ASN1_UTCTIME_QDateTime(tm, &gmt);
    00075
    00076   qstr = KGlobal::locale()->formatDateTime(qdt, false, true);
    00077   if (gmt) {
    00078     qstr += " ";
    00079     qstr += i18n("GMT");
    00080   }
    00081   return qstr;
    00082 }
    00083
    00084
    00085 QString ASN1_INTEGER_QString(ASN1_INTEGER *aint) {
    00086 char *rep = KOSSL::self()->i2s_ASN1_INTEGER(NULL, aint);
    00087 QString yy = rep;
    00088 KOSSL::self()->OPENSSL_free(rep);
    00089 return yy;
    00090 }
    00091
    00092
    00093 #endif
    00094

This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 13:14:27 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001