src/network/ssl/qsslcertificate.cpp
changeset 33 3e2da88830cd
parent 18 2f34d5167611
--- a/src/network/ssl/qsslcertificate.cpp	Tue Jul 06 15:10:48 2010 +0300
+++ b/src/network/ssl/qsslcertificate.cpp	Wed Aug 18 10:37:55 2010 +0300
@@ -259,13 +259,28 @@
 
 /*!
     Returns the certificate's serial number string in decimal format.
+    In case the serial number cannot be converted to decimal format
+    (i.e. if it is bigger than 4294967295, which means it does not fit into 4 bytes),
+    its hexadecimal version is returned.
 */
 QByteArray QSslCertificate::serialNumber() const
 {
-    if (d->serialNumberString.isEmpty() && d->x509)
-        d->serialNumberString =
-            QByteArray::number(qlonglong(q_ASN1_INTEGER_get(d->x509->cert_info->serialNumber)));
-
+    if (d->serialNumberString.isEmpty() && d->x509) {
+        ASN1_INTEGER *serialNumber = d->x509->cert_info->serialNumber;
+        // if we cannot convert to a long, just output the hexadecimal number
+        if (serialNumber->length > 4) {
+            QByteArray hexString;
+            hexString.reserve(serialNumber->length * 3);
+            for (int a = 0; a < serialNumber->length; ++a) {
+                hexString += QByteArray::number(serialNumber->data[a], 16).rightJustified(2, '0');
+                hexString += ':';
+            }
+            hexString.chop(1);
+            d->serialNumberString = hexString;
+        } else {
+            d->serialNumberString = QByteArray::number(qlonglong(q_ASN1_INTEGER_get(serialNumber)));
+        }
+    }
     return d->serialNumberString;
 }
 
@@ -533,8 +548,13 @@
     // chop off the first two characters from the glob'ed paths.
     int startIndex = 0;
     if (pathPrefix.trimmed().isEmpty()) {
-        startIndex = 2;
-        pathPrefix = QLatin1String(".");
+        if(path.startsWith(QLatin1Char('/'))) {
+            pathPrefix = path.left(path.indexOf(QRegExp(QLatin1String("[\\*\\?\\[]"))));
+            pathPrefix = path.left(path.lastIndexOf(QLatin1Char('/')));
+        } else {
+            startIndex = 2;
+            pathPrefix = QLatin1String(".");
+        }
     }
 
     // The path is a file.