From ad1b9e1b0722954d63cacb1dc22434dcce26b9e8 Mon Sep 17 00:00:00 2001 From: Albert Astals Cid Date: Thu, 13 Feb 2020 00:59:09 +0100 Subject: [PATCH] Enable QT_NO_CAST_FROM_ASCII --- CMakeLists.txt | 1 + examples/aes-cmac/aes-cmac.cpp | 4 +- examples/certtest/certtest.cpp | 3 +- examples/keyloader/keyloader.cpp | 3 +- examples/md5crypt/md5crypt.cpp | 6 +- examples/saslclient/saslclient.cpp | 20 +-- examples/saslserver/saslserver.cpp | 16 +-- examples/sslservtest/sslservtest.cpp | 6 +- examples/ssltest/ssltest.cpp | 8 +- plugins/qca-cyrus-sasl/qca-cyrus-sasl.cpp | 12 +- plugins/qca-gnupg/gpgaction.cpp | 30 ++--- plugins/qca-gnupg/gpgop.cpp | 8 +- plugins/qca-gnupg/gpgproc/gpgproc.cpp | 2 +- plugins/qca-gnupg/mykeystorelist.cpp | 6 +- plugins/qca-gnupg/mypgpkeycontext.cpp | 2 +- plugins/qca-gnupg/ringwatch.cpp | 2 +- plugins/qca-gnupg/utils.cpp | 22 ++-- plugins/qca-logger/qca-logger.cpp | 4 +- plugins/qca-ossl/qca-ossl.cpp | 14 +-- plugins/qca-pkcs11/qca-pkcs11.cpp | 30 ++--- plugins/qca-softstore/qca-softstore.cpp | 16 +-- src/qca_basic.cpp | 6 +- src/qca_cert.cpp | 114 +++++++++--------- src/qca_core.cpp | 12 +- src/qca_default.cpp | 34 +++--- src/qca_plugin.cpp | 10 +- src/qca_tools.cpp | 6 +- src/support/console.cpp | 6 +- tools/mozcerts/main.cpp | 28 ++--- tools/qcatool/main.cpp | 90 +++++++------- unittest/certunittest/certunittest.cpp | 34 +++--- unittest/cms/cms.cpp | 16 +-- unittest/hashunittest/hashunittest.cpp | 12 +- unittest/hexunittest/hexunittest.cpp | 2 +- unittest/pgpunittest/pgpunittest.cpp | 4 +- unittest/pkits/pkits.cpp | 56 ++++----- unittest/rsaunittest/rsaunittest.cpp | 2 +- .../symmetrickeyunittest.cpp | 2 +- 38 files changed, 326 insertions(+), 323 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d3ecc608..1b2b9dd1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -104,6 +104,7 @@ if (CMAKE_COMPILER_IS_GNUCXX) endif (CMAKE_COMPILER_IS_GNUCXX) add_definitions(-DQT_NO_CAST_TO_ASCII + -DQT_NO_CAST_FROM_ASCII -DQT_NO_URL_CAST_FROM_STRING -DQT_NO_CAST_FROM_BYTEARRAY -DQT_NO_SIGNALS_SLOTS_KEYWORDS diff --git a/examples/aes-cmac/aes-cmac.cpp b/examples/aes-cmac/aes-cmac.cpp index eeada39a..0605d73c 100644 --- a/examples/aes-cmac/aes-cmac.cpp +++ b/examples/aes-cmac/aes-cmac.cpp @@ -273,10 +273,10 @@ int main(int argc, char **argv) // set the MAC to use the key cmacObject.setup(key); - QCA::SecureArray message = QCA::hexToArray("6bc1bee22e409f96e93d7e117393172a" + QCA::SecureArray message = QCA::hexToArray(QStringLiteral("6bc1bee22e409f96e93d7e117393172a" "ae2d8a571e03ac9c9eb76fac45af8e51" "30c81c46a35ce411e5fbc1191a0a52ef" - "f69f2445df4f9b17ad2b417be66c3710"); + "f69f2445df4f9b17ad2b417be66c3710")); QCA::SecureArray message1(message); message1.resize(0); qDebug(); diff --git a/examples/certtest/certtest.cpp b/examples/certtest/certtest.cpp index 2b63ac2a..c350e4b0 100644 --- a/examples/certtest/certtest.cpp +++ b/examples/certtest/certtest.cpp @@ -24,6 +24,7 @@ #include #include +#include #include @@ -108,7 +109,7 @@ int main(int argc, char** argv) QCA::ConvertResult importResult; // This imports all the PEM encoded certificates from the file specified as the argument // Note that you pass in a pointer to the result argument. - filecerts = QCA::CertificateCollection::fromFlatTextFile( argv[1], &importResult ); + filecerts = QCA::CertificateCollection::fromFlatTextFile( QFile::decodeName(argv[1]), &importResult ); if ( QCA::ConvertGood == importResult) { std::cout << "Import succeeded" << std::endl; // this turns the CertificateCollection into a QList of Certificate objects diff --git a/examples/keyloader/keyloader.cpp b/examples/keyloader/keyloader.cpp index e876a966..db54b205 100644 --- a/examples/keyloader/keyloader.cpp +++ b/examples/keyloader/keyloader.cpp @@ -23,6 +23,7 @@ #include #include +#include #include #include @@ -109,7 +110,7 @@ int main(int argc, char **argv) PassphraseHandler passphraseHandler; App app; - app.str = argv[1]; + app.str = QFile::decodeName(argv[1]); QObject::connect(&app, &App::quit, &qapp, QCoreApplication::quit); QTimer::singleShot(0, &app, &App::start); qapp.exec(); diff --git a/examples/md5crypt/md5crypt.cpp b/examples/md5crypt/md5crypt.cpp index cc23b7d9..85ccf353 100644 --- a/examples/md5crypt/md5crypt.cpp +++ b/examples/md5crypt/md5crypt.cpp @@ -146,9 +146,9 @@ QString qca_md5crypt( const QCA::SecureArray &password, const QCA::SecureArray & // Salt is part of the encoded password ($1$$) QString encodedString; - encodedString.append ( magic_string.toByteArray() ); - encodedString.append ( salt.toByteArray() ); - encodedString.append ( "$" ); + encodedString.append ( QString::fromLatin1( magic_string.toByteArray() ) ); + encodedString.append ( QString::fromLatin1( salt.toByteArray() ) ); + encodedString.append ( QStringLiteral("$") ); long l; diff --git a/examples/saslclient/saslclient.cpp b/examples/saslclient/saslclient.cpp index 8145aa23..63d62b54 100644 --- a/examples/saslclient/saslclient.cpp +++ b/examples/saslclient/saslclient.cpp @@ -39,8 +39,8 @@ static QString prompt(const QString &s) fflush(stdout); char line[256]; fgets(line, 255, stdin); - QString result = line; - if(result[result.length()-1] == '\n') + QString result = QString::fromLatin1(line); + if(result[result.length()-1] == QLatin1Char('\n')) result.truncate(result.length()-1); return result; } @@ -236,7 +236,7 @@ private Q_SLOTS: { if(sock->canReadLine()) { - QString line = sock->readLine(); + QString line = QString::fromLatin1(sock->readLine()); line.truncate(line.length() - 1); // chop the newline handleLine(line); } @@ -249,7 +249,7 @@ private Q_SLOTS: QString line = sasl->mechanism(); if(clientInit) { - line += ' '; + line += QLatin1Char(' '); line += arrayToString(clientInitData); } sendLine(line); @@ -260,7 +260,7 @@ private Q_SLOTS: QString line = QStringLiteral("C"); if(!stepData.isEmpty()) { - line += ','; + line += QLatin1Char(','); line += arrayToString(stepData); } sendLine(line); @@ -388,7 +388,7 @@ private: void sendLine(const QString &line) { printf("Writing: {%s}\n", qPrintable(line)); - QString s = line + '\n'; + QString s = line + QLatin1Char('\n'); QByteArray a = s.toUtf8(); if(mode == 2) // app mode sasl->write(a); // write to sasl @@ -418,14 +418,14 @@ private: if(mode == 0) { // first line is the method list - QStringList mechlist = line.split(' '); + QStringList mechlist = line.split(QLatin1Char(' ')); mode = 1; // switch to sasl negotiation mode sasl->startClient(proto, host, mechlist); } else if(mode == 1) { QString type, rest; - int n = line.indexOf(','); + int n = line.indexOf(QLatin1Char(',')); if(n != -1) { type = line.mid(0, n); @@ -494,7 +494,7 @@ int main(int argc, char **argv) QString opt = args[n].mid(2); QString var, val; - int at = opt.indexOf('='); + int at = opt.indexOf(QLatin1Char('=')); if(at != -1) { var = opt.mid(0, at); @@ -543,7 +543,7 @@ int main(int argc, char **argv) if(args.count() >= 3) pass = args[2]; - int at = hostinput.indexOf(':'); + int at = hostinput.indexOf(QLatin1Char(':')); if(at != -1) { host = hostinput.mid(0, at); diff --git a/examples/saslserver/saslserver.cpp b/examples/saslserver/saslserver.cpp index cecf22cd..79c61b26 100644 --- a/examples/saslserver/saslserver.cpp +++ b/examples/saslserver/saslserver.cpp @@ -213,7 +213,7 @@ private Q_SLOTS: { if(sock->canReadLine()) { - QString line = sock->readLine(); + QString line = QString::fromLatin1(sock->readLine()); line.truncate(line.length() - 1); // chop the newline handleLine(line); } @@ -237,7 +237,7 @@ private Q_SLOTS: QString line = QStringLiteral("C"); if(!stepData.isEmpty()) { - line += ','; + line += QLatin1Char(','); line += arrayToString(stepData); } sendLine(line); @@ -317,11 +317,11 @@ private: printf("%d: Reading: [%s]\n", id, qPrintable(line)); if(mode == 0) { - int n = line.indexOf(' '); + int n = line.indexOf(QLatin1Char(' ')); if(n != -1) { QString mech = line.mid(0, n); - QString rest = line.mid(n + 1).toUtf8(); + QString rest = QString::fromLatin1(line.mid(n + 1).toUtf8()); sasl->putServerFirstStep(mech, stringToArray(rest)); } else @@ -331,7 +331,7 @@ private: else if(mode == 1) { QString type, rest; - int n = line.indexOf(','); + int n = line.indexOf(QLatin1Char(',')); if(n != -1) { type = line.mid(0, n); @@ -371,7 +371,7 @@ private: void sendLine(const QString &line) { printf("%d: Writing: {%s}\n", id, qPrintable(line)); - QString s = line + '\n'; + QString s = line + QLatin1Char('\n'); QByteArray a = s.toUtf8(); if(mode == 2) // app mode { @@ -456,7 +456,7 @@ int main(int argc, char **argv) QString opt = args[n].mid(2); QString var, val; - int at = opt.indexOf('='); + int at = opt.indexOf(QLatin1Char('=')); if(at != -1) { var = opt.mid(0, at); @@ -488,7 +488,7 @@ int main(int argc, char **argv) if(args.count() >= 2) str = args[1]; - int at = hostinput.indexOf(':'); + int at = hostinput.indexOf(QLatin1Char(':')); if(at != -1) { host = hostinput.mid(0, at); diff --git a/examples/sslservtest/sslservtest.cpp b/examples/sslservtest/sslservtest.cpp index 989843cf..70510e1c 100644 --- a/examples/sslservtest/sslservtest.cpp +++ b/examples/sslservtest/sslservtest.cpp @@ -88,8 +88,8 @@ public: connect(ssl, &QCA::TLS::closed, this, &SecureServer::ssl_closed); connect(ssl, &QCA::TLS::error, this, &SecureServer::ssl_error); - cert = QCA::Certificate::fromPEM(pemdata_cert); - privkey = QCA::PrivateKey::fromPEM(pemdata_privkey); + cert = QCA::Certificate::fromPEM(QString::fromLatin1(pemdata_cert)); + privkey = QCA::PrivateKey::fromPEM(QString::fromLatin1(pemdata_privkey)); mode = Idle; } @@ -255,7 +255,7 @@ int main(int argc, char **argv) QCA::Initializer init; QCoreApplication app(argc, argv); - int port = argc > 1 ? QString(argv[1]).toInt() : 8000; + int port = argc > 1 ? QString::fromLatin1(argv[1]).toInt() : 8000; if(!QCA::isSupported("tls")) { qDebug() << "TLS not supported!"; diff --git a/examples/ssltest/ssltest.cpp b/examples/ssltest/ssltest.cpp index 2f0e9084..78ccd511 100644 --- a/examples/ssltest/ssltest.cpp +++ b/examples/ssltest/ssltest.cpp @@ -132,7 +132,7 @@ public: void start(const QString &_host) { - int n = _host.indexOf(':'); + int n = _host.indexOf(QLatin1Char(':')); int port; if(n != -1) { @@ -164,7 +164,7 @@ private Q_SLOTS: // We add this one to show how, and to make it work with // the server example. - rootCerts.addCertificate(QCA::Certificate::fromPEM(exampleCA_cert)); + rootCerts.addCertificate(QCA::Certificate::fromPEM(QString::fromLatin1(exampleCA_cert))); if(!QCA::haveSystemStore()) printf("Warning: no root certs\n"); @@ -236,7 +236,7 @@ private Q_SLOTS: ssl->continueAfterStep(); printf("Let's try a GET request now.\n"); - QString req = "GET / HTTP/1.0\nHost: " + host + "\n\n"; + QString req = QStringLiteral("GET / HTTP/1.0\nHost: ") + host + QStringLiteral("\n\n"); ssl->write(req.toLatin1()); } @@ -316,7 +316,7 @@ int main(int argc, char **argv) QCA::Initializer init; QCoreApplication app(argc, argv); - QString host = argc > 1 ? argv[1] : QStringLiteral("andbit.net"); + QString host = argc > 1 ? QString::fromLocal8Bit(argv[1]) : QStringLiteral("andbit.net"); if(!QCA::isSupported("tls")) { diff --git a/plugins/qca-cyrus-sasl/qca-cyrus-sasl.cpp b/plugins/qca-cyrus-sasl/qca-cyrus-sasl.cpp index f5778f24..7c0074cc 100644 --- a/plugins/qca-cyrus-sasl/qca-cyrus-sasl.cpp +++ b/plugins/qca-cyrus-sasl/qca-cyrus-sasl.cpp @@ -204,7 +204,7 @@ static QByteArray makeByteArray(const void *in, unsigned int len) static QString addrString(const SASLContext::HostPort &hp) { - return (hp.addr + ';' + QString::number(hp.port)); + return (hp.addr + QLatin1Char(';') + QString::number(hp.port)); } //---------------------------------------------------------------------------- @@ -365,8 +365,8 @@ private: static int scb_checkauth(sasl_conn_t *, void *context, const char *requested_user, unsigned, const char *auth_identity, unsigned, const char *, unsigned, struct propctx *) { saslContext *that = (saslContext *)context; - that->sc_username = auth_identity; // yeah yeah, it looks - that->sc_authzid = requested_user; // backwards, but it is right + that->sc_username = QString::fromLatin1(auth_identity); // yeah yeah, it looks + that->sc_authzid = QString::fromLatin1(requested_user); // backwards, but it is right that->ca_flag = true; return SASL_OK; } @@ -395,7 +395,7 @@ private: params.applyInteract(need); if(params.missingAny()) { - out_mech = m; + out_mech = QString::fromLatin1(m); result_result = Params; return; } @@ -406,7 +406,7 @@ private: return; } - out_mech = m; + out_mech = QString::fromLatin1(m); if(in_sendFirst && clientout) { out_buf = makeByteArray(clientout, clientoutlen); result_haveClientInit = true; @@ -713,7 +713,7 @@ public: r = sasl_listmech(con, nullptr, nullptr, " ", nullptr, &ml, nullptr, nullptr); if(r != SASL_OK) return; - result_mechlist = QString::fromUtf8(ml).split(' '); + result_mechlist = QString::fromUtf8(ml).split(QLatin1Char(' ')); servermode = true; step = 0; diff --git a/plugins/qca-gnupg/gpgaction.cpp b/plugins/qca-gnupg/gpgaction.cpp index 3c0a268e..43704534 100644 --- a/plugins/qca-gnupg/gpgaction.cpp +++ b/plugins/qca-gnupg/gpgaction.cpp @@ -32,7 +32,7 @@ static QDateTime getTimestamp(const QString &s) if(s.isEmpty()) return QDateTime(); - if(s.contains('T')) + if(s.contains(QLatin1Char('T'))) { return QDateTime::fromString(s, Qt::ISODate); } @@ -90,7 +90,7 @@ static QByteArray getCString(const QByteArray &a) static bool stringToKeyList(const QString &outstr, GpgOp::KeyList *_keylist, QString *_keyring) { GpgOp::KeyList keyList; - QStringList lines = outstr.split('\n'); + const QStringList lines = outstr.split(QLatin1Char('\n')); if(lines.count() < 1) return false; @@ -103,7 +103,7 @@ static bool stringToKeyList(const QString &outstr, GpgOp::KeyList *_keylist, QSt // if the second line isn't a divider, we are dealing // with a new version of gnupg that doesn't give us // the keyring file on gpg --list-keys --with-colons - if(it == lines.constEnd() || (*it).isEmpty() || (*it).at(0) != '-') + if(it == lines.constEnd() || (*it).isEmpty() || (*it).at(0) != QLatin1Char('-')) { // first line wasn't the keyring name... keyring.clear(); @@ -118,7 +118,7 @@ static bool stringToKeyList(const QString &outstr, GpgOp::KeyList *_keylist, QSt for(; it != lines.constEnd(); ++it) { - QStringList f = (*it).split(':'); + const QStringList f = (*it).split(QLatin1Char(':')); if(f.count() < 1) continue; QString type = f[0]; @@ -175,13 +175,13 @@ static bool stringToKeyList(const QString &outstr, GpgOp::KeyList *_keylist, QSt item.id = f[4]; item.creationDate = getTimestamp(f[5]); item.expirationDate = getTimestamp(f[6]); - if(caps.contains('e')) + if(caps.contains(QLatin1Char('e'))) item.caps |= GpgOp::KeyItem::Encrypt; - if(caps.contains('s')) + if(caps.contains(QLatin1Char('s'))) item.caps |= GpgOp::KeyItem::Sign; - if(caps.contains('c')) + if(caps.contains(QLatin1Char('c'))) item.caps |= GpgOp::KeyItem::Certify; - if(caps.contains('a')) + if(caps.contains(QLatin1Char('a'))) item.caps |= GpgOp::KeyItem::Auth; keyList.last().keyItems += item; @@ -208,7 +208,7 @@ static bool stringToKeyList(const QString &outstr, GpgOp::KeyList *_keylist, QSt static bool findKeyringFilename(const QString &outstr, QString *_keyring) { - QStringList lines = outstr.split('\n'); + const QStringList lines = outstr.split(QLatin1Char('\n')); if(lines.count() < 1) return false; @@ -605,7 +605,7 @@ void GpgAction::submitCommand(const QByteArray &a) // since str is taken as a value, it is ok to use the same variable for 'rest' QString GpgAction::nextArg(QString str, QString *rest) { - int n = str.indexOf(' '); + int n = str.indexOf(QLatin1Char(' ')); if(n == -1) { if(rest) @@ -622,7 +622,7 @@ QString GpgAction::nextArg(QString str, QString *rest) void GpgAction::processStatusLine(const QString &line) { - appendDiagnosticText("{" + line + "}"); + appendDiagnosticText(QStringLiteral("{") + line + QStringLiteral("}")); ensureDTextEmit(); if(!proc.isActive()) @@ -748,14 +748,14 @@ void GpgAction::processStatusLine(const QString &line) else if(s == QLatin1String("ERRSIG")) { output.wasSigned = true; - QStringList list = rest.split(' ', QString::SkipEmptyParts); + const QStringList list = rest.split(QLatin1Char(' '), QString::SkipEmptyParts); output.signerId = list[0]; output.timestamp = getTimestamp(list[4]); output.verifyResult = GpgOp::VerifyNoKey; } else if(s == QLatin1String("VALIDSIG")) { - QStringList list = rest.split(' ', QString::SkipEmptyParts); + const QStringList list = rest.split(QLatin1Char(' '), QString::SkipEmptyParts); output.timestamp = getTimestamp(list[2]); } } @@ -809,7 +809,7 @@ void GpgAction::processResult(int code) if (!str.startsWith(QLatin1String("Home: "))) continue; - output.homeDir = str.section(' ', 1); + output.homeDir = str.section(QLatin1Char(' '), 1); break; } output.success = true; @@ -939,7 +939,7 @@ void GpgAction::proc_bytesWrittenCommand(int) void GpgAction::proc_debug(const QString &str) { - appendDiagnosticText("GPGProc: " + str); + appendDiagnosticText(QStringLiteral("GPGProc: ") + str); ensureDTextEmit(); } diff --git a/plugins/qca-gnupg/gpgop.cpp b/plugins/qca-gnupg/gpgop.cpp index 1eeb78b3..dc1a5226 100644 --- a/plugins/qca-gnupg/gpgop.cpp +++ b/plugins/qca-gnupg/gpgop.cpp @@ -195,13 +195,13 @@ void GpgOp::Private::act_finished() if(output.wasSigned) { - const char *s; + QString s; if(output.verifyResult == GpgOp::VerifyGood) - s = "VerifyGood"; + s = QStringLiteral("VerifyGood"); else if(output.verifyResult == GpgOp::VerifyBad) - s = "VerifyBad"; + s = QStringLiteral("VerifyBad"); else - s = "VerifyNoKey"; + s = QStringLiteral("VerifyNoKey"); diagnosticText += QStringLiteral("wasSigned: verifyResult: %1\n").arg(s); } diff --git a/plugins/qca-gnupg/gpgproc/gpgproc.cpp b/plugins/qca-gnupg/gpgproc/gpgproc.cpp index 494a1f8e..c52d8918 100644 --- a/plugins/qca-gnupg/gpgproc/gpgproc.cpp +++ b/plugins/qca-gnupg/gpgproc/gpgproc.cpp @@ -196,7 +196,7 @@ void GPGProc::Private::setupArguments() } QString fullcmd = fullargs.join(QStringLiteral(" ")); - emit q->debug(QStringLiteral("Running: [") + bin + ' ' + fullcmd + ']'); + emit q->debug(QStringLiteral("Running: [") + bin + QLatin1Char(' ') + fullcmd + QLatin1Char(']')); args = fullargs; } diff --git a/plugins/qca-gnupg/mykeystorelist.cpp b/plugins/qca-gnupg/mykeystorelist.cpp index 558daa9f..894fbebf 100644 --- a/plugins/qca-gnupg/mykeystorelist.cpp +++ b/plugins/qca-gnupg/mykeystorelist.cpp @@ -154,7 +154,7 @@ KeyStoreEntryContext *MyKeyStoreList::entryPassive(const QString &serialized) { QMutexLocker locker(&ringMutex); - QStringList parts = serialized.split(':'); + const QStringList parts = serialized.split(QLatin1Char(':')); if(parts.count() < 2) return nullptr; if(unescape_string(parts[0]) != QLatin1String("qca-gnupg-1")) @@ -375,7 +375,7 @@ void MyKeyStoreList::gpg_finished() if(secring.isEmpty()) { - secring = homeDir + "/secring.gpg"; + secring = homeDir + QStringLiteral("/secring.gpg"); } ringWatch.add(secring); @@ -389,7 +389,7 @@ void MyKeyStoreList::gpg_finished() pubring = QFileInfo(gpg.keyringFile()).canonicalFilePath(); if(pubring.isEmpty()) { - pubring = homeDir + "/pubring.gpg"; + pubring = homeDir + QStringLiteral("/pubring.gpg"); } ringWatch.add(pubring); diff --git a/plugins/qca-gnupg/mypgpkeycontext.cpp b/plugins/qca-gnupg/mypgpkeycontext.cpp index 07a6e8f0..2d63b870 100644 --- a/plugins/qca-gnupg/mypgpkeycontext.cpp +++ b/plugins/qca-gnupg/mypgpkeycontext.cpp @@ -212,7 +212,7 @@ void MyPGPKeyContext::set(const GpgOp::Key &i, bool isSecret, bool inKeyring, bo void MyPGPKeyContext::cleanup_temp_keyring(const QString &name) { QFile::remove(name); - QFile::remove(name + '~'); // remove possible backup file + QFile::remove(name + QLatin1Char('~')); // remove possible backup file } } // end namespace gpgQCAPlugin diff --git a/plugins/qca-gnupg/ringwatch.cpp b/plugins/qca-gnupg/ringwatch.cpp index bd67c184..f67e4e3c 100644 --- a/plugins/qca-gnupg/ringwatch.cpp +++ b/plugins/qca-gnupg/ringwatch.cpp @@ -156,7 +156,7 @@ void RingWatch::handleChanged() for(int n = 0; n < files.count(); ++n) { FileItem &i = files[n]; - QString filePath = dir + '/' + i.fileName; + QString filePath = dir + QLatin1Char('/') + i.fileName; QFileInfo fi(filePath); // if the file didn't exist, and still doesn't, skip diff --git a/plugins/qca-gnupg/utils.cpp b/plugins/qca-gnupg/utils.cpp index 9f56744f..2c7f5e6c 100644 --- a/plugins/qca-gnupg/utils.cpp +++ b/plugins/qca-gnupg/utils.cpp @@ -123,9 +123,9 @@ QString find_bin() // Prefer bundled gpg foreach (const QString &bin, bins) { - if (check_bin(QCoreApplication::applicationDirPath() + "/" + bin)) + if (check_bin(QCoreApplication::applicationDirPath() + QLatin1Char('/') + bin)) { - return QCoreApplication::applicationDirPath() + "/" + bin; + return QCoreApplication::applicationDirPath() + QLatin1Char('/') + bin; } } @@ -159,9 +159,9 @@ QString find_bin() { foreach (const QString &bin, bins) { - if (check_bin(path + "/" + bin)) + if (check_bin(path + QLatin1Char('/') + bin)) { - return path + "/" + bin; + return path + QLatin1Char('/') + bin; } } } @@ -175,9 +175,9 @@ QString escape_string(const QString &in) QString out; for(const QChar &c : in) { - if(c == '\\') + if(c == QLatin1Char('\\')) out += QStringLiteral("\\\\"); - else if(c == ':') + else if(c == QLatin1Char(':')) out += QStringLiteral("\\c"); else out += c; @@ -190,14 +190,14 @@ QString unescape_string(const QString &in) QString out; for(int n = 0; n < in.length(); ++n) { - if(in[n] == '\\') + if(in[n] == QLatin1Char('\\')) { if(n + 1 < in.length()) { - if(in[n + 1] == '\\') - out += '\\'; - else if(in[n + 1] == 'c') - out += ':'; + if(in[n + 1] == QLatin1Char('\\')) + out += QLatin1Char('\\'); + else if(in[n + 1] == QLatin1Char('c')) + out += QLatin1Char(':'); ++n; } } diff --git a/plugins/qca-logger/qca-logger.cpp b/plugins/qca-logger/qca-logger.cpp index a9dd6fcd..7df24dbd 100644 --- a/plugins/qca-logger/qca-logger.cpp +++ b/plugins/qca-logger/qca-logger.cpp @@ -156,9 +156,9 @@ public: defaultConfig () const override { QVariantMap mytemplate; - mytemplate[QStringLiteral("formtype")] = "http://affinix.com/qca/forms/qca-logger#1.0"; + mytemplate[QStringLiteral("formtype")] = QStringLiteral("http://affinix.com/qca/forms/qca-logger#1.0"); mytemplate[QStringLiteral("enabled")] = false; - mytemplate[QStringLiteral("file")] = ""; + mytemplate[QStringLiteral("file")] = QLatin1String(""); mytemplate[QStringLiteral("level")] = (int)Logger::Quiet; return mytemplate; diff --git a/plugins/qca-ossl/qca-ossl.cpp b/plugins/qca-ossl/qca-ossl.cpp index 4b44e9c6..6824e587 100644 --- a/plugins/qca-ossl/qca-ossl.cpp +++ b/plugins/qca-ossl/qca-ossl.cpp @@ -1607,18 +1607,18 @@ static const int JCE_768_COUNTER = 263; static const char* JCE_1024_SEED = "8D515589 4229D5E6 89EE01E6 018A237E 2CAE64CD"; static const int JCE_1024_COUNTER = 92; -static QByteArray dehex(const QString &hex) +static QByteArray dehex(const QByteArray &hex) { QString str; - for(const QChar &c : hex) + for(const char c : hex) { if(c != ' ') - str += c; + str += QLatin1Char(c); } return hexToArray(str); } -static BigInteger decode(const QString &prime) +static BigInteger decode(const QByteArray &prime) { QByteArray a(1, 0); // 1 byte of zero padding a.append(dehex(prime)); @@ -1626,7 +1626,7 @@ static BigInteger decode(const QString &prime) } #ifndef OPENSSL_FIPS -static QByteArray decode_seed(const QString &hex_seed) +static QByteArray decode_seed(const QByteArray &hex_seed) { return dehex(hex_seed); } @@ -3620,7 +3620,7 @@ public: if(ai) { char *rep = i2s_ASN1_INTEGER(nullptr, ai); - QString str = rep; + QString str = QString::fromLatin1(rep); OPENSSL_free(rep); p.serial.fromString(str); } @@ -7251,7 +7251,7 @@ public: QString credit() const override { - return QString( + return QStringLiteral( "This product includes cryptographic software " "written by Eric Young (eay@cryptsoft.com)"); } diff --git a/plugins/qca-pkcs11/qca-pkcs11.cpp b/plugins/qca-pkcs11/qca-pkcs11.cpp index fdd6ea3e..ff5073c0 100644 --- a/plugins/qca-pkcs11/qca-pkcs11.cpp +++ b/plugins/qca-pkcs11/qca-pkcs11.cpp @@ -381,7 +381,7 @@ public: QString message () const { - return _msg + QStringLiteral(" ") + pkcs11h_getMessage (_rv); + return _msg + QStringLiteral(" ") + QString::fromLatin1(pkcs11h_getMessage (_rv)); } }; @@ -1649,7 +1649,7 @@ pkcs11KeyStoreListContext::name (int id) const { ); if (_storesById.contains (id)) { - ret = _storesById[id]->tokenId ()->label; + ret = QString::fromLatin1(_storesById[id]->tokenId ()->label); } QCA_logTextMessage ( @@ -1966,7 +1966,7 @@ pkcs11KeyStoreListContext::_tokenPrompt ( else { _registerTokenId (token_id); storeId = _tokenId2storeId (token_id); - storeName = token_id->label; + storeName = QString::fromLatin1(token_id->label); } TokenAsker asker; @@ -2023,7 +2023,7 @@ pkcs11KeyStoreListContext::_pinPrompt ( else { _registerTokenId (token_id); storeId = _tokenId2storeId (token_id); - storeName = token_id->label; + storeName = QString::fromLatin1(token_id->label); } PasswordAsker asker; @@ -2210,7 +2210,7 @@ pkcs11KeyStoreListContext::_keyStoreEntryByCertificateId ( QString description = _description; const Certificate &cert = chain.primary (); if (description.isEmpty ()) { - description = cert.subjectInfoOrdered ().toString () + " by " + cert.issuerInfo ().value (CommonName, QStringLiteral("Unknown")); + description = cert.subjectInfoOrdered ().toString () + QStringLiteral(" by ") + cert.issuerInfo ().value (CommonName, QStringLiteral("Unknown")); } if (has_private) { @@ -2235,7 +2235,7 @@ pkcs11KeyStoreListContext::_keyStoreEntryByCertificateId ( key, _tokenId2storeId (certificate_id->token_id), serialized, - certificate_id->token_id->label, + QString::fromLatin1(certificate_id->token_id->label), description, provider () ); @@ -2245,7 +2245,7 @@ pkcs11KeyStoreListContext::_keyStoreEntryByCertificateId ( cert, _tokenId2storeId (certificate_id->token_id), serialized, - certificate_id->token_id->label, + QString::fromLatin1(certificate_id->token_id->label), description, provider() ); @@ -2302,7 +2302,7 @@ pkcs11KeyStoreListContext::_tokenId2storeId ( buf.resize ((int)len); - storeId = "qca-pkcs11/" + _escapeString (QString::fromUtf8 (buf)); + storeId = QStringLiteral("qca-pkcs11/") + _escapeString (QString::fromUtf8 (buf)); QCA_logTextMessage ( QString::asprintf ( @@ -2490,7 +2490,7 @@ pkcs11KeyStoreListContext::_escapeString ( QString to; foreach (QChar c, from) { - if (c == '/' || c == '\\') { + if (c == QLatin1Char('/') || c == QLatin1Char('\\')) { to += QString::asprintf ("\\x%04x", c.unicode ()); } else { @@ -2510,7 +2510,7 @@ pkcs11KeyStoreListContext::_unescapeString ( for (int i=0;i &items, const QStringList &list, str = uniqueSubjectValue(Email, items, certs, i); if(!str.isEmpty()) { - name = list[items[i]] + QStringLiteral(" <") + str + '>'; + name = list[items[i]] + QStringLiteral(" <") + str + QLatin1Char('>'); goto end; } @@ -589,7 +589,7 @@ static QString makeUniqueName(const QList &items, const QStringList &list, str = uniqueSubjectValue(XMPP, items, certs, i); if(!str.isEmpty()) { - name = list[items[i]] + QStringLiteral(" '; + name = list[items[i]] + QStringLiteral(" '); goto end; } @@ -1199,9 +1199,9 @@ void CertificateOptions::setValidityPeriod(const QDateTime &start, const QDateTi static QByteArray ipaddr_str2bin(const QString &str) { // ipv6 - if(str.contains(':')) + if(str.contains(QLatin1Char(':'))) { - QStringList parts = str.split(':', QString::KeepEmptyParts); + QStringList parts = str.split(QLatin1Char(':'), QString::KeepEmptyParts); if(parts.count() < 3 || parts.count() > 8) return QByteArray(); @@ -1242,7 +1242,7 @@ static QByteArray ipaddr_str2bin(const QString &str) } else { - if(parts[n].indexOf('.') == -1) + if(parts[n].indexOf(QLatin1Char('.')) == -1) { bool ok; int x = parts[n].toInt(&ok, 16); @@ -1271,9 +1271,9 @@ static QByteArray ipaddr_str2bin(const QString &str) return ipv6; } - else if(str.contains('.')) + else if(str.contains(QLatin1Char('.'))) { - QStringList parts = str.split('.', QString::KeepEmptyParts); + QStringList parts = str.split(QLatin1Char('.'), QString::KeepEmptyParts); if(parts.count() != 4) return QByteArray(); @@ -1301,7 +1301,7 @@ static bool cert_match_domain(const QString &certname, const QString &acedomain) // KSSL strips trailing dot, even though the dot is probably not // legal anyway. (compat) - if(name.length() > 0 && name[name.length()-1] == '.') + if(name.length() > 0 && name[name.length()-1] == QLatin1Char('.')) name.truncate(name.length()-1); // after our compatibility modifications, make sure the name isn't @@ -1313,23 +1313,23 @@ static bool cert_match_domain(const QString &certname, const QString &acedomain) name = name.toLower(); // ensure the cert field contains valid characters only - if(QRegExp("[^a-z0-9\\.\\*\\-]").indexIn(name) >= 0) + if(QRegExp(QLatin1String("[^a-z0-9\\.\\*\\-]")).indexIn(name) >= 0) return false; // hack into parts, and require at least 1 part - QStringList parts_name = name.split('.', QString::KeepEmptyParts); + const QStringList parts_name = name.split(QLatin1Char('.'), QString::KeepEmptyParts); if(parts_name.isEmpty()) return false; // KSSL checks to make sure the last two parts don't contain // wildcards. I don't know where it is written that this // should be done, but for compat sake we'll do it. - if(parts_name[parts_name.count()-1].contains('*')) + if(parts_name[parts_name.count()-1].contains(QLatin1Char('*'))) return false; - if(parts_name.count() >= 2 && parts_name[parts_name.count()-2].contains('*')) + if(parts_name.count() >= 2 && parts_name[parts_name.count()-2].contains(QLatin1Char('*'))) return false; - QStringList parts_compare = acedomain.split('.', QString::KeepEmptyParts); + QStringList parts_compare = acedomain.split(QLatin1Char('.'), QString::KeepEmptyParts); if(parts_compare.isEmpty()) return false; @@ -1382,7 +1382,7 @@ static bool cert_match_ipaddress(const QString &certname, const QByteArray &ipad // KSSL accepts IPv6 in brackets, which is usually done for URIs, but // IMO sounds very strange for a certificate. We'll follow this // behavior anyway. (compat) - if(name.length() >= 2 && name[0] == '[' && name[name.length()-1] == ']') + if(name.length() >= 2 && name[0] == QLatin1Char('[') && name[name.length()-1] == QLatin1Char(']')) name = name.mid(1, name.length() - 2); // chop off brackets // after our compatibility modifications, make sure the name isn't @@ -1668,11 +1668,11 @@ bool Certificate::matchesHostName(const QString &host) const name = QString::fromLatin1(QUrl::toAce(name)); // don't allow wildcards in the comparison host - if(name.contains('*')) + if(name.contains(QLatin1Char('*'))) return false; // strip out trailing dot - if(name.length() > 0 && name[name.length()-1] == '.') + if(name.length() > 0 && name[name.length()-1] == QLatin1Char('.')) name.truncate(name.length()-1); // make sure the name is not empty after our modifications @@ -2278,20 +2278,20 @@ static QString readNextPem(QTextStream *ts, bool *isCRL) if(line.contains(QLatin1String("CERTIFICATE"))) { found = true; - pem += line + '\n'; + pem += line + QLatin1Char('\n'); crl = false; } else if(line.contains(QLatin1String("CRL"))) { found = true; - pem += line + '\n'; + pem += line + QLatin1Char('\n'); crl = true; } } } else { - pem += line + '\n'; + pem += line + QLatin1Char('\n'); if(line.startsWith(QLatin1String("-----END "))) { done = true; diff --git a/src/qca_core.cpp b/src/qca_core.cpp index ba12aa66..dab1aab1 100644 --- a/src/qca_core.cpp +++ b/src/qca_core.cpp @@ -365,7 +365,7 @@ bool isSupported(const QStringList &features, const QString &provider) bool isSupported(const char *features, const QString &provider) { - return isSupported(QString(features).split(',', QString::SkipEmptyParts), provider); + return isSupported(QString::fromLatin1(features).split(QLatin1Char(','), QString::SkipEmptyParts), provider); } QStringList supportedFeatures() @@ -458,17 +458,17 @@ QStringList pluginPaths() { QStringList paths; #ifndef DEVELOPER_MODE - const QString qcaPluginPath = qgetenv("QCA_PLUGIN_PATH"); + const QByteArray qcaPluginPath = qgetenv("QCA_PLUGIN_PATH"); if (!qcaPluginPath.isEmpty()) { #ifdef Q_OS_WIN - QLatin1Char pathSep(';'); + char pathSep(';'); #else - QLatin1Char pathSep(':'); + char pathSep(':'); #endif - foreach (const QString &path, qcaPluginPath.split(pathSep)) + foreach (const QByteArray &path, qcaPluginPath.split(pathSep)) { - QString canonicalPath = QDir(path).canonicalPath(); + QString canonicalPath = QDir(QFile::decodeName(path)).canonicalPath(); if (!canonicalPath.isEmpty()) paths << canonicalPath; } diff --git a/src/qca_default.cpp b/src/qca_default.cpp index bb0b274e..2620c7ce 100644 --- a/src/qca_default.cpp +++ b/src/qca_default.cpp @@ -779,13 +779,13 @@ static QString escape_string(const QString &in) QString out; for(const QChar &c : in) { - if(c == '\\') + if(c == QLatin1Char('\\')) out += QLatin1String("\\\\"); - else if(c == ':') + else if(c == QLatin1Char(':')) out += QLatin1String("\\c"); - else if(c == ',') + else if(c == QLatin1Char(',')) out += QLatin1String("\\o"); - else if(c == '\n') + else if(c == QLatin1Char('\n')) out += QLatin1String("\\n"); else out += c; @@ -798,19 +798,19 @@ static bool unescape_string(const QString &in, QString *_out) QString out; for(int n = 0; n < in.length(); ++n) { - if(in[n] == '\\') + if(in[n] == QLatin1Char('\\')) { if(n + 1 >= in.length()) return false; - if(in[n + 1] == '\\') - out += '\\'; - else if(in[n + 1] == 'c') - out += ':'; - else if(in[n + 1] == 'o') - out += ','; - else if(in[n + 1] == 'n') - out += '\n'; + if(in[n + 1] == QLatin1Char('\\')) + out += QLatin1Char('\\'); + else if(in[n + 1] == QLatin1Char('c')) + out += QLatin1Char(':'); + else if(in[n + 1] == QLatin1Char('o')) + out += QLatin1Char(','); + else if(in[n + 1] == QLatin1Char('n')) + out += QLatin1Char('\n'); else return false; ++n; @@ -833,7 +833,7 @@ static QString escape_stringlist(const QStringList &in) static bool unescape_stringlist(const QString &in, QStringList *_out) { QStringList out; - QStringList list = in.split(':'); + const QStringList list = in.split(QLatin1Char(':')); for(int n = 0; n < list.count(); ++n) { QString str; @@ -1171,7 +1171,7 @@ public: static bool unescape_config_stringlist(const QString &in, QStringList *_out) { QStringList out; - QStringList list = in.split(','); + const QStringList list = in.split(QLatin1Char(',')); for(int n = 0; n < list.count(); ++n) { QString str; @@ -1240,7 +1240,7 @@ public: QVariantMap defaultConfig() const override { QVariantMap config; - config[QStringLiteral("formtype")] = "http://affinix.com/qca/forms/default#1.0"; + config[QStringLiteral("formtype")] = QStringLiteral("http://affinix.com/qca/forms/default#1.0"); config[QStringLiteral("use_system")] = true; config[QStringLiteral("roots_file")] = QString(); config[QStringLiteral("skip_plugins")] = QString(); @@ -1270,7 +1270,7 @@ public: QString &s = plugin_priorities[n]; // make sure the entry ends with ":number" - int x = s.indexOf(':'); + int x = s.indexOf(QLatin1Char(':')); bool ok = false; if(x != -1) s.midRef(x + 1).toInt(&ok); diff --git a/src/qca_plugin.cpp b/src/qca_plugin.cpp index cb5a5096..0d23b27e 100644 --- a/src/qca_plugin.cpp +++ b/src/qca_plugin.cpp @@ -58,9 +58,9 @@ QString truncate_log(const QString &in, int size) // if the previous char is a newline, then this is a perfect cut. // otherwise, we need to skip to after the next newline. - if(in[at - 1] != '\n') + if(in[at - 1] != QLatin1Char('\n')) { - while(at < in.length() && in[at] != '\n') + while(at < in.length() && in[at] != QLatin1Char('\n')) { ++at; } @@ -68,7 +68,7 @@ QString truncate_log(const QString &in, int size) // at this point we either reached a newline, or end of // the entire buffer - if(in[at] == '\n') + if(in[at] == QLatin1Char('\n')) ++at; } @@ -80,7 +80,7 @@ static ProviderManager *g_pluginman = nullptr; static void logDebug(const QString &str) { if(g_pluginman) - g_pluginman->appendDiagnosticText(str + '\n'); + g_pluginman->appendDiagnosticText(str + QLatin1Char('\n')); } static bool validVersion(int ver) @@ -801,7 +801,7 @@ int ProviderManager::get_default_priority(const QString &name) const foreach(const QString &s, list) { // qca_default already sanity checks the strings - int n = s.indexOf(':'); + int n = s.indexOf(QLatin1Char(':')); QString sname = s.mid(0, n); int spriority = s.midRef(n + 1).toInt(); if(sname == name) diff --git a/src/qca_tools.cpp b/src/qca_tools.cpp index 471c63e6..bef2f78d 100644 --- a/src/qca_tools.cpp +++ b/src/qca_tools.cpp @@ -805,7 +805,7 @@ BigInteger::BigInteger(int i) BigInteger::BigInteger(const char *c) { d = new Private; - fromString(QString(c)); + fromString(QString::fromLatin1(c)); } BigInteger::BigInteger(const QString &s) @@ -967,7 +967,7 @@ QString BigInteger::toString() const QString str; if(d->n.is_negative()) - str += '-'; + str += QLatin1Char('-'); str += QString::fromLatin1(cs); return str; } @@ -979,7 +979,7 @@ bool BigInteger::fromString(const QString &s) QByteArray cs = s.toLatin1(); bool neg = false; - if(s[0] == '-') + if(s[0] == QLatin1Char('-')) neg = true; try diff --git a/src/support/console.cpp b/src/support/console.cpp index 8885197e..fe0825b1 100644 --- a/src/support/console.cpp +++ b/src/support/console.cpp @@ -826,7 +826,7 @@ public: } if(!charMode) - writeString(promptStr + ": "); + writeString(promptStr + QStringLiteral(": ")); return true; } @@ -847,14 +847,14 @@ public: return false; } - if(c == '\r' || c == '\n') + if(c == QLatin1Char('\r') || c == QLatin1Char('\n')) { writeString(QStringLiteral("\n")); done = true; return false; } - if(c == '\b' || c.unicode() == 0x7f) + if(c == QLatin1Char('\b') || c.unicode() == 0x7f) { if(at > 0) { diff --git a/tools/mozcerts/main.cpp b/tools/mozcerts/main.cpp index a113ac31..6e06f7b6 100644 --- a/tools/mozcerts/main.cpp +++ b/tools/mozcerts/main.cpp @@ -38,14 +38,14 @@ int main(int argc, char **argv) return 0; } - QFile infile(argv[1]); + QFile infile(QString::fromLocal8Bit(argv[1])); if(!infile.open(QFile::ReadOnly)) { fprintf(stderr, "Error opening input file\n"); return 1; } - QFile outfile(argv[2]); + QFile outfile(QString::fromLocal8Bit(argv[2])); if(!outfile.open(QFile::WriteOnly | QFile::Truncate)) { fprintf(stderr, "Error opening output file\n"); @@ -58,13 +58,13 @@ int main(int argc, char **argv) while(!ts.atEnd()) { QString line = ts.readLine(); - if(QRegExp("^#").indexIn(line) != -1) + if(QRegExp(QLatin1String("^#")).indexIn(line) != -1) continue; - if(QRegExp("^\\s*$").indexIn(line) != -1) + if(QRegExp(QLatin1String("^\\s*$")).indexIn(line) != -1) continue; line = line.trimmed(); - if(QRegExp("CKA_LABEL").indexIn(line) != -1) + if(QRegExp(QLatin1String("CKA_LABEL")).indexIn(line) != -1) { QStringList list = splitWithQuotes(line, ' '); if(list.count() != 3) @@ -78,16 +78,16 @@ int main(int argc, char **argv) // .replace(QRegExp(","), "_") + ".pem"; continue; } - else if(QRegExp("CKA_VALUE MULTILINE_OCTAL").indexIn(line) != -1) + else if(QRegExp(QLatin1String("CKA_VALUE MULTILINE_OCTAL")).indexIn(line) != -1) { QByteArray buf; while(!ts.atEnd()) { line = ts.readLine(); - if(QRegExp("^END").indexIn(line) != -1) + if(QRegExp(QLatin1String("^END")).indexIn(line) != -1) break; line = line.trimmed(); - QRegExp rx("\\\\([0-3][0-7][0-7])"); + QRegExp rx(QLatin1String("\\\\([0-3][0-7][0-7])")); int pos = 0; while((pos = rx.indexIn(line, pos)) != -1) { @@ -120,7 +120,7 @@ int find_notchar(const QString &str, char c, int offset) { for(int n = offset; n < str.length(); ++n) { - if(str[n] != c) + if(str[n] != QLatin1Char(c)) return n; } return -1; @@ -130,23 +130,23 @@ QStringList splitWithQuotes(const QString &in, char c) { QStringList result; int at = 0; - if(in[at] == c) + if(in[at] == QLatin1Char(c)) at = find_notchar(in, c, at); while(at != -1) { bool quote = false; int end; QString str; - if(in[at] == '\"') + if(in[at] == QLatin1Char('\"')) { quote = true; ++at; - end = in.indexOf('\"', at); + end = in.indexOf(QLatin1Char('\"'), at); if(end == -1) break; } else - end = in.indexOf(c, at); + end = in.indexOf(QLatin1Char(c), at); if(end != -1) str = in.mid(at, end - at); @@ -157,7 +157,7 @@ QStringList splitWithQuotes(const QString &in, char c) result += str; if(quote) - end = in.indexOf(c, end); + end = in.indexOf(QLatin1Char(c), end); if(end != -1) at = find_notchar(in, c, end); diff --git a/tools/qcatool/main.cpp b/tools/qcatool/main.cpp index 29def8b1..8bb97ab2 100644 --- a/tools/qcatool/main.cpp +++ b/tools/qcatool/main.cpp @@ -136,9 +136,9 @@ static void output_plugin_diagnostic_text() { QString str = QCA::pluginDiagnosticText(); QCA::clearPluginDiagnosticText(); - if(str[str.length()-1] == '\n') + if(str[str.length()-1] == QLatin1Char('\n')) str.truncate(str.length()-1); - QStringList lines = str.split('\n', QString::KeepEmptyParts); + QStringList lines = str.split(QLatin1Char('\n'), QString::KeepEmptyParts); for(int n = 0; n < lines.count(); ++n) fprintf(stderr, "plugin: %s\n", qPrintable(lines[n])); } @@ -147,9 +147,9 @@ static void output_keystore_diagnostic_text() { QString str = QCA::KeyStoreManager::diagnosticText(); QCA::KeyStoreManager::clearDiagnosticText(); - if(str[str.length()-1] == '\n') + if(str[str.length()-1] == QLatin1Char('\n')) str.truncate(str.length()-1); - QStringList lines = str.split('\n', QString::KeepEmptyParts); + QStringList lines = str.split(QLatin1Char('\n'), QString::KeepEmptyParts); for(int n = 0; n < lines.count(); ++n) fprintf(stderr, "keystore: %s\n", qPrintable(lines[n])); } @@ -157,9 +157,9 @@ static void output_keystore_diagnostic_text() static void output_message_diagnostic_text(QCA::SecureMessage *msg) { QString str = msg->diagnosticText(); - if(str[str.length()-1] == '\n') + if(str[str.length()-1] == QLatin1Char('\n')) str.truncate(str.length()-1); - QStringList lines = str.split('\n', QString::KeepEmptyParts); + QStringList lines = str.split(QLatin1Char('\n'), QString::KeepEmptyParts); for(int n = 0; n < lines.count(); ++n) fprintf(stderr, "message: %s\n", qPrintable(lines[n])); } @@ -325,7 +325,7 @@ private Q_SLOTS: void prompt_finished() { QChar c = prompt->resultChar(); - if(c == 'q' || c == 'Q') + if(c == QLatin1Char('q') || c == QLatin1Char('Q')) { eventLoop->exit(); return; @@ -447,7 +447,7 @@ private Q_SLOTS: else { if(e.keyStoreInfo().type() == QCA::KeyStore::SmartCard) - name = QStringLiteral("the '") + e.keyStoreInfo().name() + "' token"; + name = QStringLiteral("the '") + e.keyStoreInfo().name() + QStringLiteral("' token"); else name = e.keyStoreInfo().name(); } @@ -532,11 +532,11 @@ private Q_SLOTS: QString name; if(!entry.isNull()) { - name = QStringLiteral("Please make ") + entry.name() + " (of " + entry.storeName() + ") available"; + name = QStringLiteral("Please make ") + entry.name() + QStringLiteral(" (of ") + entry.storeName() + QStringLiteral(") available"); } else { - name = QStringLiteral("Please insert the '") + e.keyStoreInfo().name() + "' token"; + name = QStringLiteral("Please insert the '") + e.keyStoreInfo().name() + QStringLiteral("' token"); } QString str = QStringLiteral("%1 and press Enter (or 'q' to cancel) ...").arg(name); @@ -579,9 +579,9 @@ private Q_SLOTS: else { QChar c = prompt->resultChar(); - if(c == '\r' || c == '\n') + if(c == QLatin1Char('\r') || c == QLatin1Char('\n')) handler.tokenOkay(prompt_id); - else if(c == 'q' || c == 'Q') + else if(c == QLatin1Char('q') || c == QLatin1Char('Q')) handler.reject(prompt_id); else { @@ -742,9 +742,9 @@ static QString line_encode(const QString &in) QString out; for(const QChar &c : in) { - if(c == '\\') + if(c == QLatin1Char('\\')) out += QStringLiteral("\\\\"); - else if(c == '\n') + else if(c == QLatin1Char('\n')) out += QStringLiteral("\\n"); else out += c; @@ -757,14 +757,14 @@ static QString line_decode(const QString &in) QString out; for(int n = 0; n < in.length(); ++n) { - if(in[n] == '\\') + if(in[n] == QLatin1Char('\\')) { if(n + 1 < in.length()) { - if(in[n + 1] == '\\') - out += '\\'; - else if(in[n + 1] == 'n') - out += '\n'; + if(in[n + 1] == QLatin1Char('\\')) + out += QLatin1Char('\\'); + else if(in[n + 1] == QLatin1Char('n')) + out += QLatin1Char('\n'); ++n; } } @@ -778,7 +778,7 @@ static QString make_ksentry_string(const QString &id) { QString out; out += QStringLiteral("QCATOOL_KEYSTOREENTRY_1\n"); - out += line_encode(id) + '\n'; + out += line_encode(id) + QLatin1Char('\n'); return out; } @@ -946,7 +946,7 @@ static bool validOid(const QString &in) { for(const QChar &c : in) { - if(!c.isDigit() && c != '.') + if(!c.isDigit() && c != QLatin1Char('.')) return false; } return true; @@ -1272,9 +1272,9 @@ static QCA::CertificateOptions promptForCertAttributes(bool advanced, bool req) if(parts.count() == 1) out = parts[0]; else if(parts.count() == 2) - out = parts[0] + " and " + parts[1]; + out = parts[0] + QStringLiteral(" and ") + parts[1]; else if(parts.count() == 3) - out = parts[0] + ", " + parts[1] + ", and " + parts[2]; + out = parts[0] + QStringLiteral(", ") + parts[1] + QStringLiteral(", and ") + parts[2]; printf("Certificate will be valid for %s.\n", qPrintable(out)); break; } @@ -1510,7 +1510,7 @@ public: QVariantMap out = orig_config; // form type - out[QStringLiteral("formtype")] = "http://affinix.com/qca/forms/qca-pkcs11#1.0"; + out[QStringLiteral("formtype")] = QLatin1String("http://affinix.com/qca/forms/qca-pkcs11#1.0"); // base settings out[QStringLiteral("allow_load_rootca")] = allow_load_rootca; @@ -1541,7 +1541,7 @@ public: bool fromVariantMap(const QVariantMap &in) { - if(in[QStringLiteral("formtype")] != "http://affinix.com/qca/forms/qca-pkcs11#1.0") + if(in[QStringLiteral("formtype")] != QLatin1String("http://affinix.com/qca/forms/qca-pkcs11#1.0")) return false; allow_load_rootca = in[QStringLiteral("allow_load_rootca")].toBool(); @@ -1835,7 +1835,7 @@ static QVariantMap provider_config_edit_pkcs11(const QVariantMap &in) static QVariantMap provider_config_edit(const QVariantMap &in) { // see if we have a configurator for a known form type - if(in[QStringLiteral("formtype")] == "http://affinix.com/qca/forms/qca-pkcs11#1.0") + if(in[QStringLiteral("formtype")] == QLatin1String("http://affinix.com/qca/forms/qca-pkcs11#1.0")) return provider_config_edit_pkcs11(in); // otherwise, use the generic configurator @@ -1849,7 +1849,7 @@ static QString get_fingerprint(const QCA::Certificate &cert, const QString &hash for(int n = 0; n < hex.count(); ++n) { if(n != 0 && n % 2 == 0) - out += ':'; + out += QLatin1Char(':'); out += hex[n]; } return out; @@ -2106,7 +2106,7 @@ static QString format_pgp_fingerprint(const QString &in) for(int n = 0; n + 3 < in.length(); n += 4) { if(!first) - out += ' '; + out += QLatin1Char(' '); else first = false; out += in.mid(n, 4).toUpper(); @@ -2279,12 +2279,12 @@ static QString add_cr(const QString &in) int at = 0; while(true) { - at = out.indexOf('\n', at); + at = out.indexOf(QLatin1Char('\n'), at); if(at == -1) break; - if(at - 1 >= 0 && out[at - 1] != '\r') + if(at - 1 >= 0 && out[at - 1] != QLatin1Char('\r')) { - out.insert(at, '\r'); + out.insert(at, QLatin1Char('\r')); ++at; } ++at; @@ -2303,9 +2303,9 @@ static int indexOf_newline(const QString &in, int offset = 0) { for(int n = offset; n < in.length(); ++n) { - if(n + 1 < in.length() && in[n] == '\r' && in[n + 1] == '\n') + if(n + 1 < in.length() && in[n] == QLatin1Char('\r') && in[n + 1] == QLatin1Char('\n')) return n; - if(in[n] == '\n') + if(in[n] == QLatin1Char('\n')) return n; } return -1; @@ -2327,7 +2327,7 @@ static int indexOf_doublenewline(const QString &in, int offset = 0) } at = n; - if(in[n] == '\n') + if(in[n] == QLatin1Char('\n')) offset = n + 1; else offset = n + 2; @@ -2338,7 +2338,7 @@ static int indexOf_doublenewline(const QString &in, int offset = 0) // this is so gross static int newline_len(const QString &in, int offset = 0) { - if(in[offset] == '\r') + if(in[offset] == QLatin1Char('\r')) return 2; else return 1; @@ -2364,15 +2364,15 @@ static bool open_mime_data_sig(const QString &in, QString *data, QString *sig) return false; QString boundary; QString bregion = in.mid(n, i - n); - n = bregion.indexOf(';'); + n = bregion.indexOf(QLatin1Char(';')); if(n != -1) boundary = bregion.mid(0, n); else boundary = bregion; - if(boundary[0] == '\"') + if(boundary[0] == QLatin1Char('\"')) boundary.remove(0, 1); - if(boundary[boundary.length() - 1] == '\"') + if(boundary[boundary.length() - 1] == QLatin1Char('\"')) boundary.remove(boundary.length() - 1, 1); //printf("boundary: [%s]\n", qPrintable(boundary)); QString boundary_end = QStringLiteral("--") + boundary; @@ -2526,7 +2526,7 @@ static QCA::KeyStoreEntry get_E(const QString &name, bool nopassiveerror = false QCA::KeyStoreManager::start(); - int n = name.indexOf(':'); + int n = name.indexOf(QLatin1Char(':')); if(n != -1) { ksm_start_and_wait(); @@ -2570,7 +2570,7 @@ static QCA::PrivateKey get_K(const QString &name) { QCA::PrivateKey key; - int n = name.indexOf(':'); + int n = name.indexOf(QLatin1Char(':')); if(n != -1) { fprintf(stderr, "Error: cannot use store:obj notation for raw private keys.\n"); @@ -2792,7 +2792,7 @@ int main(int argc, char **argv) continue; QString var; QString val; - int x = s.indexOf('='); + int x = s.indexOf(QLatin1Char('=')); if(x != -1) { var = s.mid(2, x - 2); @@ -3484,7 +3484,7 @@ int main(int argc, char **argv) } QFileInfo fi(args[2]); - QString newFileName = fi.baseName() + "_new.p12"; + QString newFileName = fi.baseName() + QStringLiteral("_new.p12"); if(key.toFile(newFileName, newpass)) printf("Keybundle saved to %s\n", qPrintable(newFileName)); @@ -3922,7 +3922,7 @@ int main(int argc, char **argv) if(!pgp) { QString text = add_cr(QString::fromUtf8(plain)); - plain = QString(mime_signpart).arg(text).toUtf8(); + plain = QString::fromLatin1(mime_signpart).arg(text).toUtf8(); } QCA::SecureMessage *msg = new QCA::SecureMessage(sms); @@ -3970,7 +3970,7 @@ int main(int argc, char **argv) enc.setLineBreaksEnabled(true); enc.setLineBreaksColumn(76); QString sigtext = add_cr(enc.arrayToString(output)); - QString str = QString(mime_signed).arg(hashName, QString::fromUtf8(plain), sigtext); + QString str = QString::fromLatin1(mime_signed).arg(hashName, QString::fromUtf8(plain), sigtext); output = str.toUtf8(); } @@ -4073,7 +4073,7 @@ int main(int argc, char **argv) enc.setLineBreaksEnabled(true); enc.setLineBreaksColumn(76); QString enctext = add_cr(enc.arrayToString(output)); - QString str = QString(mime_enveloped).arg(enctext); + QString str = QString::fromLatin1(mime_enveloped).arg(enctext); output = str.toUtf8(); } diff --git a/unittest/certunittest/certunittest.cpp b/unittest/certunittest/certunittest.cpp index ad418370..d7bb1b48 100644 --- a/unittest/certunittest/certunittest.cpp +++ b/unittest/certunittest/certunittest.cpp @@ -77,7 +77,7 @@ void CertUnitTest::nullCert() foreach(const QString provider, providersToTest) { if( !QCA::isSupported( "cert", provider ) ) - QWARN( QString( "Certificate handling not supported for "+provider).toLocal8Bit().constData() ); + QWARN( (QStringLiteral( "Certificate handling not supported for ")+provider).toLocal8Bit().constData() ); else { QCA::Certificate nullCert; QVERIFY(nullCert.isNull()); @@ -96,7 +96,7 @@ void CertUnitTest::noSuchFile() foreach(const QString provider, providersToTest) { if( !QCA::isSupported( "cert", provider ) ) - QWARN( QString( "Certificate handling not supported for "+provider).toLocal8Bit().constData() ); + QWARN( (QStringLiteral( "Certificate handling not supported for ")+provider).toLocal8Bit().constData() ); else { QCA::ConvertResult resultNoFile; QCA::Certificate cert = QCA::Certificate::fromPEMFile( QStringLiteral("thisIsJustaFileNameThatWeDontHave"), &resultNoFile, provider); @@ -114,7 +114,7 @@ void CertUnitTest::CAcertstest() foreach(const QString provider, providersToTest) { if( !QCA::isSupported( "cert", provider ) ) - QWARN( QString( "Certificate handling not supported for "+provider).toLocal8Bit().constData() ); + QWARN( (QStringLiteral( "Certificate handling not supported for ")+provider).toLocal8Bit().constData() ); else { QCA::ConvertResult resultca1; QCA::Certificate ca1 = QCA::Certificate::fromPEMFile( QStringLiteral("certs/RootCAcert.pem"), &resultca1, provider); @@ -165,7 +165,7 @@ void CertUnitTest::qualitysslcatest() foreach(const QString provider, providersToTest) { if( !QCA::isSupported( "cert", provider ) ) - QWARN( QString( "Certificate handling not supported for "+provider).toLocal8Bit().constData() ); + QWARN( (QStringLiteral( "Certificate handling not supported for ")+provider).toLocal8Bit().constData() ); else { QCA::ConvertResult resultca1; QCA::Certificate ca1 = QCA::Certificate::fromPEMFile( QStringLiteral("certs/QualitySSLIntermediateCA.crt"), &resultca1, provider); @@ -217,7 +217,7 @@ void CertUnitTest::checkExpiredClientCerts() foreach(const QString provider, providersToTest) { if( !QCA::isSupported( "cert", provider ) ) - QWARN( QString( "Certificate handling not supported for "+provider).toLocal8Bit().constData() ); + QWARN( (QStringLiteral( "Certificate handling not supported for ")+provider).toLocal8Bit().constData() ); else { QCA::ConvertResult resultClient1; QCA::Certificate client1 = QCA::Certificate::fromPEMFile( QStringLiteral("certs/User.pem"), &resultClient1, provider); @@ -325,7 +325,7 @@ void CertUnitTest::checkClientCerts() foreach(const QString provider, providersToTest) { if( !QCA::isSupported( "cert", provider ) ) - QWARN( QString( "Certificate handling not supported for "+provider).toLocal8Bit().constData() ); + QWARN( (QStringLiteral( "Certificate handling not supported for ")+provider).toLocal8Bit().constData() ); else { QCA::ConvertResult resultClient2; QCA::Certificate client2 = QCA::Certificate::fromPEMFile( QStringLiteral("certs/QcaTestClientCert.pem"), &resultClient2, provider); @@ -434,7 +434,7 @@ void CertUnitTest::derCAcertstest() foreach(const QString provider, providersToTest) { if( !QCA::isSupported( "cert", provider ) ) - QWARN( QString( "Certificate handling not supported for "+provider).toLocal8Bit().constData() ); + QWARN( (QStringLiteral( "Certificate handling not supported for ")+provider).toLocal8Bit().constData() ); else { QFile f(QStringLiteral("certs/ov-root-ca-cert.crt")); QVERIFY(f.open(QFile::ReadOnly)); @@ -508,7 +508,7 @@ void CertUnitTest::altName() foreach(const QString provider, providersToTest) { if( !QCA::isSupported( "cert", provider ) ) - QWARN( QString( "Certificate handling not supported for "+provider).toLocal8Bit().constData() ); + QWARN( (QStringLiteral( "Certificate handling not supported for ")+provider).toLocal8Bit().constData() ); else { QCA::ConvertResult resultClient1; QCA::Certificate client1 = QCA::Certificate::fromPEMFile( QStringLiteral("certs/altname.pem"), &resultClient1, provider); @@ -584,7 +584,7 @@ void CertUnitTest::extXMPP() foreach(const QString provider, providersToTest) { if( !QCA::isSupported( "cert", provider ) ) - QWARN( QString( "Certificate handling not supported for "+provider).toLocal8Bit().constData() ); + QWARN( (QStringLiteral( "Certificate handling not supported for ")+provider).toLocal8Bit().constData() ); else { QCA::ConvertResult resultClient1; QCA::Certificate client1 = QCA::Certificate::fromPEMFile( QStringLiteral("certs/xmppcert.pem"), &resultClient1, provider); @@ -626,7 +626,7 @@ void CertUnitTest::altNames76() foreach(const QString provider, providersToTest) { if( !QCA::isSupported( "cert", provider ) ) - QWARN( QString( "Certificate handling not supported for "+provider).toLocal8Bit().constData() ); + QWARN( (QStringLiteral( "Certificate handling not supported for ")+provider).toLocal8Bit().constData() ); else { QCA::ConvertResult resultClient1; QCA::Certificate client1 = QCA::Certificate::fromPEMFile( QStringLiteral("certs/76.pem"), &resultClient1, provider); @@ -721,7 +721,7 @@ void CertUnitTest::sha256cert() foreach(const QString provider, providersToTest) { if( !QCA::isSupported( "cert", provider ) ) - QWARN( QString( "Certificate handling not supported for "+provider).toLocal8Bit().constData() ); + QWARN( (QStringLiteral( "Certificate handling not supported for ")+provider).toLocal8Bit().constData() ); else { QFile f(QStringLiteral("certs/RAIZ2007_CERTIFICATE_AND_CRL_SIGNING_SHA256.crt")); QVERIFY(f.open(QFile::ReadOnly)); @@ -760,7 +760,7 @@ void CertUnitTest::checkExpiredServerCerts() foreach(const QString provider, providersToTest) { if( !QCA::isSupported( "cert", provider ) ) - QWARN( QString( "Certificate handling not supported for "+provider).toLocal8Bit().constData() ); + QWARN( (QStringLiteral( "Certificate handling not supported for ")+provider).toLocal8Bit().constData() ); else { QCA::ConvertResult resultServer1; QCA::Certificate server1 = QCA::Certificate::fromPEMFile( QStringLiteral("certs/Server.pem"), &resultServer1, provider); @@ -863,7 +863,7 @@ void CertUnitTest::checkServerCerts() foreach(const QString provider, providersToTest) { if( !QCA::isSupported( "cert", provider ) ) - QWARN( QString( "Certificate handling not supported for "+provider).toLocal8Bit().constData() ); + QWARN( (QStringLiteral( "Certificate handling not supported for ")+provider).toLocal8Bit().constData() ); else { QCA::ConvertResult resultServer1; QCA::Certificate server1 = QCA::Certificate::fromPEMFile( QStringLiteral("certs/QcaTestServerCert.pem"), &resultServer1, provider); @@ -982,7 +982,7 @@ void CertUnitTest::crl() foreach(const QString provider, providersToTest) { if( !QCA::isSupported( "crl", provider ) ) - QWARN( QString( "Certificate revocation not supported for "+provider).toLocal8Bit().constData() ); + QWARN( (QStringLiteral( "Certificate revocation not supported for ")+provider).toLocal8Bit().constData() ); else { QCA::CRL emptyCRL; QVERIFY( emptyCRL.isNull() ); @@ -1043,7 +1043,7 @@ void CertUnitTest::crl2() foreach(const QString provider, providersToTest) { if( !QCA::isSupported( "crl", provider ) ) - QWARN( QString( "Certificate revocation not supported for "+provider).toLocal8Bit().constData() ); + QWARN( (QStringLiteral( "Certificate revocation not supported for ")+provider).toLocal8Bit().constData() ); else { QCA::ConvertResult resultCrl; QCA::CRL crl1 = QCA::CRL::fromPEMFile( QStringLiteral("certs/GoodCACRL.pem"), &resultCrl, provider); @@ -1110,7 +1110,7 @@ void CertUnitTest::csr() foreach(const QString provider, providersToTest) { if( !QCA::isSupported( "csr", provider ) ) - QWARN( QString( "Certificate signing requests not supported for "+provider).toLocal8Bit().constData() ); + QWARN( (QStringLiteral( "Certificate signing requests not supported for ")+provider).toLocal8Bit().constData() ); else { QCA::CertificateRequest nullCSR; QVERIFY( nullCSR.isNull() ); @@ -1154,7 +1154,7 @@ void CertUnitTest::csr2() foreach(const QString provider, providersToTest) { if( !QCA::isSupported( "csr", provider ) ) - QWARN( QString( "Certificate signing requests not supported for "+provider).toLocal8Bit().constData() ); + QWARN( (QStringLiteral( "Certificate signing requests not supported for ")+provider).toLocal8Bit().constData() ); else { QCA::ConvertResult resultCsr; QCA::CertificateRequest csr1 = QCA::CertificateRequest::fromPEMFile( QStringLiteral("certs/newreq.pem"), &resultCsr, provider); diff --git a/unittest/cms/cms.cpp b/unittest/cms/cms.cpp index 0e974047..ca83dbc6 100644 --- a/unittest/cms/cms.cpp +++ b/unittest/cms/cms.cpp @@ -79,9 +79,9 @@ void CMSut::xcrypt() foreach(const QString provider, providersToTest) { if( !QCA::isSupported( "cert", provider ) ) - QWARN( QString( "Certificate not supported for "+provider).toLocal8Bit().constData() ); + QWARN( (QStringLiteral( "Certificate not supported for ")+provider).toLocal8Bit().constData() ); else if( !QCA::isSupported( "cms", provider ) ) - QWARN( QString( "CMS not supported for "+provider).toLocal8Bit().constData() ); + QWARN( (QStringLiteral( "CMS not supported for ")+provider).toLocal8Bit().constData() ); else { QCA::Certificate pubCert = QCA::Certificate::fromPEMFile( QStringLiteral("QcaTestClientCert.pem"),nullptr, provider ); QCOMPARE( pubCert.isNull(), false ); @@ -178,9 +178,9 @@ void CMSut::signverify() foreach(const QString provider, providersToTest) { if( !QCA::isSupported( "cert", provider ) ) - QWARN( QString( "Certificate not supported for "+provider).toLocal8Bit().constData() ); + QWARN( (QStringLiteral( "Certificate not supported for ")+provider).toLocal8Bit().constData() ); else if( !QCA::isSupported( "cms", provider ) ) - QWARN( QString( "CMS not supported for "+provider).toLocal8Bit().constData() ); + QWARN( (QStringLiteral( "CMS not supported for ")+provider).toLocal8Bit().constData() ); else { QCA::ConvertResult res; QCA::SecureArray passPhrase = "start"; @@ -310,9 +310,9 @@ void CMSut::signverify_message() foreach(const QString provider, providersToTest) { if( !QCA::isSupported( "cert", provider ) ) - QWARN( QString( "Certificate not supported for "+provider).toLocal8Bit().constData() ); + QWARN( (QStringLiteral( "Certificate not supported for ")+provider).toLocal8Bit().constData() ); else if( !QCA::isSupported( "cms", provider ) ) - QWARN( QString( "CMS not supported for "+provider).toLocal8Bit().constData() ); + QWARN( (QStringLiteral( "CMS not supported for ")+provider).toLocal8Bit().constData() ); else { QCA::ConvertResult res; QCA::SecureArray passPhrase = "start"; @@ -428,9 +428,9 @@ void CMSut::signverify_message_invalid() foreach(const QString provider, providersToTest) { if( !QCA::isSupported( "cert", provider ) ) - QWARN( QString( "Certificate not supported for "+provider).toLocal8Bit().constData() ); + QWARN( (QStringLiteral( "Certificate not supported for ")+provider).toLocal8Bit().constData() ); else if( !QCA::isSupported( "cms", provider ) ) - QWARN( QString( "CMS not supported for "+provider).toLocal8Bit().constData() ); + QWARN( (QStringLiteral( "CMS not supported for ")+provider).toLocal8Bit().constData() ); else { QCA::ConvertResult res; QCA::SecureArray passPhrase = "start"; diff --git a/unittest/hashunittest/hashunittest.cpp b/unittest/hashunittest/hashunittest.cpp index 725064a7..0ce462b3 100644 --- a/unittest/hashunittest/hashunittest.cpp +++ b/unittest/hashunittest/hashunittest.cpp @@ -219,7 +219,7 @@ void HashUnitTest::md5filetest() { foreach(QString provider, providersToTest) { if(!QCA::isSupported("md5", provider)) { - QFile f1( TEST_DATA_DIR "/data/empty" ); + QFile f1( QStringLiteral(TEST_DATA_DIR "/data/empty") ); QVERIFY( f1.open( QIODevice::ReadOnly ) ); { QCA::Hash hashObj(QStringLiteral("md5"), provider); @@ -228,7 +228,7 @@ void HashUnitTest::md5filetest() QStringLiteral( "d41d8cd98f00b204e9800998ecf8427e" ) ); } - QFile f2( TEST_DATA_DIR "/data/twobytes" ); + QFile f2( QStringLiteral(TEST_DATA_DIR "/data/twobytes") ); QVERIFY( f2.open( QIODevice::ReadOnly ) ); { QCA::Hash hashObj(QStringLiteral("md5"), provider); @@ -238,7 +238,7 @@ void HashUnitTest::md5filetest() } - QFile f3( TEST_DATA_DIR "/data/twohundredbytes" ); + QFile f3( QStringLiteral(TEST_DATA_DIR "/data/twohundredbytes") ); QVERIFY( f3.open( QIODevice::ReadOnly ) ); { QCA::Hash hashObj(QStringLiteral("md5"), provider); @@ -368,7 +368,7 @@ void HashUnitTest::sha1longtest() QCOMPARE( QString(QCA::arrayToHex(shaHash.final().toByteArray())), QStringLiteral("34aa973cd4c4daa4f61eeb2bdbad27316534016f") ); - QFile f1( TEST_DATA_DIR "/data/empty" ); + QFile f1( QStringLiteral(TEST_DATA_DIR "/data/empty") ); QVERIFY( f1.open( QIODevice::ReadOnly ) ); { QCA::Hash hashObj(QStringLiteral("sha1"), provider); @@ -377,7 +377,7 @@ void HashUnitTest::sha1longtest() QStringLiteral( "da39a3ee5e6b4b0d3255bfef95601890afd80709" ) ); } - QFile f2( TEST_DATA_DIR "/data/twobytes" ); + QFile f2( QStringLiteral(TEST_DATA_DIR "/data/twobytes") ); QVERIFY( f2.open( QIODevice::ReadOnly ) ); { QCA::Hash hashObj(QStringLiteral("sha1"), provider); @@ -386,7 +386,7 @@ void HashUnitTest::sha1longtest() QStringLiteral( "efbd6de3c51ca16094391e837bf52f7452593e5c" ) ); } - QFile f3( TEST_DATA_DIR "/data/twohundredbytes" ); + QFile f3( QStringLiteral(TEST_DATA_DIR "/data/twohundredbytes") ); QVERIFY( f3.open( QIODevice::ReadOnly ) ); { QCA::Hash hashObj(QStringLiteral("sha1"), provider); diff --git a/unittest/hexunittest/hexunittest.cpp b/unittest/hexunittest/hexunittest.cpp index dfe0d8f5..f5588ea1 100644 --- a/unittest/hexunittest/hexunittest.cpp +++ b/unittest/hexunittest/hexunittest.cpp @@ -64,7 +64,7 @@ void HexUnitTest::testHexString_data() QTest::newRow("ABCD") << QStringLiteral("ABCD") << QStringLiteral("41424344"); QTest::newRow("empty") << QString(QLatin1String("")) << QString(QLatin1String("")); QTest::newRow("abcddef") << QStringLiteral("abcddef") << QStringLiteral("61626364646566"); - QTest::newRow("empty too") << QString("\0") << QString(""); // Empty QString. clazy:exclude=qstring-allocations + QTest::newRow("empty too") << QString::fromLatin1("\0") << QString::fromLatin1(""); // Empty QString. clazy:exclude=qstring-allocations QTest::newRow("BEL") << QStringLiteral("\a") << QStringLiteral("07"); // BEL QTest::newRow("BS") << QStringLiteral("\b") << QStringLiteral("08"); // BS QTest::newRow("HT") << QStringLiteral("\t") << QStringLiteral("09"); // HT diff --git a/unittest/pgpunittest/pgpunittest.cpp b/unittest/pgpunittest/pgpunittest.cpp index 1e25f4f0..b8c2da36 100644 --- a/unittest/pgpunittest/pgpunittest.cpp +++ b/unittest/pgpunittest/pgpunittest.cpp @@ -462,7 +462,7 @@ void PgpUnitTest::testClearsign() if(msg2.success()) { // The trimmed() call is needed because clearsigning // trashes whitespace - QCOMPARE( QString(msg2.read()).trimmed(), QString(plain).trimmed() ); + QCOMPARE( msg2.read().trimmed(), plain.trimmed() ); } else { qDebug() << "Failure:" << msg2.errorCode(); QFAIL("Failed to verify clearsigned message"); @@ -673,7 +673,7 @@ void PgpUnitTest::testSignaturesWithExpiredSubkeys() QByteArray signedResult = msg1.read(); QVERIFY(msg1.verifySuccess()); - QCOMPARE(QString(signedResult).trimmed(), QString(validMessage).trimmed()); + QCOMPARE(signedResult.trimmed(), validMessage.trimmed()); // Test signature made by the expired subkey QByteArray expiredKeySignature("-----BEGIN PGP SIGNED MESSAGE-----\n" diff --git a/unittest/pkits/pkits.cpp b/unittest/pkits/pkits.cpp index cdd11388..dffe0465 100644 --- a/unittest/pkits/pkits.cpp +++ b/unittest/pkits/pkits.cpp @@ -112,7 +112,7 @@ void Pkits::pkits4_1_1() foreach(const QString provider, providersToTest) { if( !QCA::isSupported( "cert", provider ) ) - QWARN( QString( "Certificate handling not supported for "+provider).toLocal8Bit().constData() ); + QWARN( (QStringLiteral( "Certificate handling not supported for ")+provider).toLocal8Bit().constData() ); else { QCA::Certificate cert = certFromDERFile(QStringLiteral("certs/ValidCertificatePathTest1EE.crt"), provider); QCOMPARE( cert.isNull(), false ); @@ -149,7 +149,7 @@ void Pkits::pkits4_1_2() foreach(const QString provider, providersToTest) { if( !QCA::isSupported( "cert", provider ) ) - QWARN( QString( "Certificate handling not supported for "+provider).toLocal8Bit().constData() ); + QWARN( (QStringLiteral( "Certificate handling not supported for ")+provider).toLocal8Bit().constData() ); else { QCA::Certificate cert = certFromDERFile(QStringLiteral("certs/InvalidCASignatureTest2EE.crt"), provider); QCOMPARE( cert.isNull(), false ); @@ -186,7 +186,7 @@ void Pkits::pkits4_1_3() foreach(const QString provider, providersToTest) { if( !QCA::isSupported( "cert", provider ) ) - QWARN( QString( "Certificate handling not supported for "+provider).toLocal8Bit().constData() ); + QWARN( (QStringLiteral( "Certificate handling not supported for ")+provider).toLocal8Bit().constData() ); else { QCA::Certificate cert = certFromDERFile(QStringLiteral("certs/InvalidEESignatureTest3EE.crt"), provider); QCOMPARE( cert.isNull(), false ); @@ -223,7 +223,7 @@ void Pkits::pkits4_1_4() foreach(const QString provider, providersToTest) { if( !QCA::isSupported( "cert", provider ) ) - QWARN( QString( "Certificate handling not supported for "+provider).toLocal8Bit().constData() ); + QWARN( (QStringLiteral( "Certificate handling not supported for ")+provider).toLocal8Bit().constData() ); else { QCA::Certificate cert = certFromDERFile(QStringLiteral("certs/ValidDSASignaturesTest4EE.crt"), provider); QCOMPARE( cert.isNull(), false ); @@ -260,7 +260,7 @@ void Pkits::pkits4_1_5() foreach(const QString provider, providersToTest) { if( !QCA::isSupported( "cert", provider ) ) - QWARN( QString( "Certificate handling not supported for "+provider).toLocal8Bit().constData() ); + QWARN( (QStringLiteral( "Certificate handling not supported for ")+provider).toLocal8Bit().constData() ); else { QCA::Certificate cert = certFromDERFile(QStringLiteral("certs/ValidDSAParameterInheritanceTest5EE.crt"), provider); QCOMPARE( cert.isNull(), false ); @@ -304,7 +304,7 @@ void Pkits::pkits4_1_6() foreach(const QString provider, providersToTest) { if( !QCA::isSupported( "cert", provider ) ) - QWARN( QString( "Certificate handling not supported for "+provider).toLocal8Bit().constData() ); + QWARN( (QStringLiteral( "Certificate handling not supported for ")+provider).toLocal8Bit().constData() ); else { QCA::Certificate cert = certFromDERFile(QStringLiteral("certs/InvalidDSASignatureTest6EE.crt"), provider); QCOMPARE( cert.isNull(), false ); @@ -339,7 +339,7 @@ void Pkits::pkits4_2_1() foreach(const QString provider, providersToTest) { if( !QCA::isSupported( "cert", provider ) ) - QWARN( QString( "Certificate handling not supported for "+provider).toLocal8Bit().constData() ); + QWARN( (QStringLiteral( "Certificate handling not supported for ")+provider).toLocal8Bit().constData() ); else { QCA::Certificate cert = certFromDERFile(QStringLiteral("certs/InvalidCAnotBeforeDateTest1EE.crt"), provider); QCOMPARE( cert.isNull(), false ); @@ -374,7 +374,7 @@ void Pkits::pkits4_2_2() foreach(const QString provider, providersToTest) { if( !QCA::isSupported( "cert", provider ) ) - QWARN( QString( "Certificate handling not supported for "+provider).toLocal8Bit().constData() ); + QWARN( (QStringLiteral( "Certificate handling not supported for ")+provider).toLocal8Bit().constData() ); else { QCA::Certificate cert = certFromDERFile(QStringLiteral("certs/InvalidEEnotBeforeDateTest2EE.crt"), provider); QCOMPARE( cert.isNull(), false ); @@ -409,7 +409,7 @@ void Pkits::pkits4_2_3() foreach(const QString provider, providersToTest) { if( !QCA::isSupported( "cert", provider ) ) - QWARN( QString( "Certificate handling not supported for "+provider).toLocal8Bit().constData() ); + QWARN( (QStringLiteral( "Certificate handling not supported for ")+provider).toLocal8Bit().constData() ); else { QCA::Certificate cert = certFromDERFile(QStringLiteral("certs/Validpre2000UTCnotBeforeDateTest3EE.crt"), provider); QCOMPARE( cert.isNull(), false ); @@ -444,7 +444,7 @@ void Pkits::pkits4_2_4() foreach(const QString provider, providersToTest) { if( !QCA::isSupported( "cert", provider ) ) - QWARN( QString( "Certificate handling not supported for "+provider).toLocal8Bit().constData() ); + QWARN( (QStringLiteral( "Certificate handling not supported for ")+provider).toLocal8Bit().constData() ); else { QCA::Certificate cert = certFromDERFile(QStringLiteral("certs/ValidGeneralizedTimenotBeforeDateTest4EE.crt"), provider); QCOMPARE( cert.isNull(), false ); @@ -480,7 +480,7 @@ void Pkits::pkits4_2_5() foreach(const QString provider, providersToTest) { if( !QCA::isSupported( "cert", provider ) ) - QWARN( QString( "Certificate handling not supported for "+provider).toLocal8Bit().constData() ); + QWARN( (QStringLiteral( "Certificate handling not supported for ")+provider).toLocal8Bit().constData() ); else { QCA::Certificate cert = certFromDERFile(QStringLiteral("certs/InvalidCAnotAfterDateTest5EE.crt"), provider); QCOMPARE( cert.isNull(), false ); @@ -515,7 +515,7 @@ void Pkits::pkits4_2_6() foreach(const QString provider, providersToTest) { if( !QCA::isSupported( "cert", provider ) ) - QWARN( QString( "Certificate handling not supported for "+provider).toLocal8Bit().constData() ); + QWARN( (QStringLiteral( "Certificate handling not supported for ")+provider).toLocal8Bit().constData() ); else { QCA::Certificate cert = certFromDERFile(QStringLiteral("certs/InvalidEEnotAfterDateTest6EE.crt"), provider); QCOMPARE( cert.isNull(), false ); @@ -550,7 +550,7 @@ void Pkits::pkits4_2_7() foreach(const QString provider, providersToTest) { if( !QCA::isSupported( "cert", provider ) ) - QWARN( QString( "Certificate handling not supported for "+provider).toLocal8Bit().constData() ); + QWARN( (QStringLiteral( "Certificate handling not supported for ")+provider).toLocal8Bit().constData() ); else { QCA::Certificate cert = certFromDERFile(QStringLiteral("certs/Invalidpre2000UTCEEnotAfterDateTest7EE.crt"), provider); QCOMPARE( cert.isNull(), false ); @@ -585,7 +585,7 @@ void Pkits::pkits4_2_8() foreach(const QString provider, providersToTest) { if( !QCA::isSupported( "cert", provider ) ) - QWARN( QString( "Certificate handling not supported for "+provider).toLocal8Bit().constData() ); + QWARN( (QStringLiteral( "Certificate handling not supported for ")+provider).toLocal8Bit().constData() ); else { QCA::Certificate cert = certFromDERFile(QStringLiteral("certs/ValidGeneralizedTimenotAfterDateTest8EE.crt"), provider); QCOMPARE( cert.isNull(), false ); @@ -620,7 +620,7 @@ void Pkits::pkits4_3_1() foreach(const QString provider, providersToTest) { if( !QCA::isSupported( "cert", provider ) ) - QWARN( QString( "Certificate handling not supported for "+provider).toLocal8Bit().constData() ); + QWARN( (QStringLiteral( "Certificate handling not supported for ")+provider).toLocal8Bit().constData() ); else { QCA::Certificate cert = certFromDERFile(QStringLiteral("certs/InvalidNameChainingTest1EE.crt"), provider); QCOMPARE( cert.isNull(), false ); @@ -655,7 +655,7 @@ void Pkits::pkits4_3_2() foreach(const QString provider, providersToTest) { if( !QCA::isSupported( "cert", provider ) ) - QWARN( QString( "Certificate handling not supported for "+provider).toLocal8Bit().constData() ); + QWARN( (QStringLiteral( "Certificate handling not supported for ")+provider).toLocal8Bit().constData() ); else { QCA::Certificate cert = certFromDERFile(QStringLiteral("certs/InvalidNameChainingOrderTest2EE.crt"), provider); QCOMPARE( cert.isNull(), false ); @@ -690,7 +690,7 @@ void Pkits::pkits4_3_3() foreach(const QString provider, providersToTest) { if( !QCA::isSupported( "cert", provider ) ) - QWARN( QString( "Certificate handling not supported for "+provider).toLocal8Bit().constData() ); + QWARN( (QStringLiteral( "Certificate handling not supported for ")+provider).toLocal8Bit().constData() ); else { QCA::Certificate cert = certFromDERFile(QStringLiteral("certs/ValidNameChainingWhitespaceTest3EE.crt"), provider); QCOMPARE( cert.isNull(), false ); @@ -726,7 +726,7 @@ void Pkits::pkits4_3_4() foreach(const QString provider, providersToTest) { if( !QCA::isSupported( "cert", provider ) ) - QWARN( QString( "Certificate handling not supported for "+provider).toLocal8Bit().constData() ); + QWARN( (QStringLiteral( "Certificate handling not supported for ")+provider).toLocal8Bit().constData() ); else { QCA::Certificate cert = certFromDERFile(QStringLiteral("certs/ValidNameChainingWhitespaceTest4EE.crt"), provider); QCOMPARE( cert.isNull(), false ); @@ -761,7 +761,7 @@ void Pkits::pkits4_3_5() foreach(const QString provider, providersToTest) { if( !QCA::isSupported( "cert", provider ) ) - QWARN( QString( "Certificate handling not supported for "+provider).toLocal8Bit().constData() ); + QWARN( (QStringLiteral( "Certificate handling not supported for ")+provider).toLocal8Bit().constData() ); else { QCA::Certificate cert = certFromDERFile(QStringLiteral("certs/ValidNameChainingCapitalizationTest5EE.crt"), provider); QCOMPARE( cert.isNull(), false ); @@ -796,7 +796,7 @@ void Pkits::pkits4_3_6() foreach(const QString provider, providersToTest) { if( !QCA::isSupported( "cert", provider ) ) - QWARN( QString( "Certificate handling not supported for "+provider).toLocal8Bit().constData() ); + QWARN( (QStringLiteral( "Certificate handling not supported for ")+provider).toLocal8Bit().constData() ); else { QCA::Certificate cert = certFromDERFile(QStringLiteral("certs/ValidNameUIDsTest6EE.crt"), provider); QCOMPARE( cert.isNull(), false ); @@ -832,7 +832,7 @@ void Pkits::pkits4_3_7() foreach(const QString provider, providersToTest) { if( !QCA::isSupported( "cert", provider ) ) - QWARN( QString( "Certificate handling not supported for "+provider).toLocal8Bit().constData() ); + QWARN( (QStringLiteral( "Certificate handling not supported for ")+provider).toLocal8Bit().constData() ); else { QCA::Certificate cert = certFromDERFile(QStringLiteral("certs/ValidRFC3280MandatoryAttributeTypesTest7EE.crt"), provider); QCOMPARE( cert.isNull(), false ); @@ -869,7 +869,7 @@ void Pkits::pkits4_3_8() foreach(const QString provider, providersToTest) { if( !QCA::isSupported( "cert", provider ) ) - QWARN( QString( "Certificate handling not supported for "+provider).toLocal8Bit().constData() ); + QWARN( (QStringLiteral( "Certificate handling not supported for ")+provider).toLocal8Bit().constData() ); else { QCA::Certificate cert = certFromDERFile(QStringLiteral("certs/ValidRFC3280OptionalAttributeTypesTest8EE.crt"), provider); QCOMPARE( cert.isNull(), false ); @@ -905,7 +905,7 @@ void Pkits::pkits4_3_9() foreach(const QString provider, providersToTest) { if( !QCA::isSupported( "cert", provider ) ) - QWARN( QString( "Certificate handling not supported for "+provider).toLocal8Bit().constData() ); + QWARN( (QStringLiteral( "Certificate handling not supported for ")+provider).toLocal8Bit().constData() ); else { QCA::Certificate cert = certFromDERFile(QStringLiteral("certs/ValidUTF8StringEncodedNamesTest9EE.crt"), provider); QCOMPARE( cert.isNull(), false ); @@ -941,7 +941,7 @@ void Pkits::pkits4_3_10() foreach(const QString provider, providersToTest) { if( !QCA::isSupported( "cert", provider ) ) - QWARN( QString( "Certificate handling not supported for "+provider).toLocal8Bit().constData() ); + QWARN( (QStringLiteral( "Certificate handling not supported for ")+provider).toLocal8Bit().constData() ); else { QCA::Certificate cert = certFromDERFile(QStringLiteral("certs/ValidRolloverfromPrintableStringtoUTF8StringTest10EE.crt"), provider); QCOMPARE( cert.isNull(), false ); @@ -978,7 +978,7 @@ void Pkits::pkits4_3_11() foreach(const QString provider, providersToTest) { if( !QCA::isSupported( "cert", provider ) ) - QWARN( QString( "Certificate handling not supported for "+provider).toLocal8Bit().constData() ); + QWARN( (QStringLiteral( "Certificate handling not supported for ")+provider).toLocal8Bit().constData() ); else { QCA::Certificate cert = certFromDERFile(QStringLiteral("certs/ValidUTF8StringCaseInsensitiveMatchTest11EE.crt"), provider); QCOMPARE( cert.isNull(), false ); @@ -1017,7 +1017,7 @@ void Pkits::pkits4_4_1() foreach(const QString provider, providersToTest) { if( !QCA::isSupported( "cert", provider ) ) - QWARN( QString( "Certificate handling not supported for "+provider).toLocal8Bit().constData() ); + QWARN( (QStringLiteral( "Certificate handling not supported for ")+provider).toLocal8Bit().constData() ); else { QCA::Certificate cert = certFromDERFile(QStringLiteral("certs/InvalidMissingCRLTest1EE.crt"), provider); QCOMPARE( cert.isNull(), false ); @@ -1052,7 +1052,7 @@ void Pkits::pkits4_4_2() foreach(const QString provider, providersToTest) { if( !QCA::isSupported( "cert", provider ) ) - QWARN( QString( "Certificate handling not supported for "+provider).toLocal8Bit().constData() ); + QWARN( (QStringLiteral( "Certificate handling not supported for ")+provider).toLocal8Bit().constData() ); else { QCA::Certificate cert = certFromDERFile(QStringLiteral("certs/InvalidRevokedCATest2EE.crt"), provider); QCOMPARE( cert.isNull(), false ); @@ -1097,7 +1097,7 @@ void Pkits::pkits4_4_3() foreach(const QString provider, providersToTest) { if( !QCA::isSupported( "cert", provider ) ) - QWARN( QString( "Certificate handling not supported for "+provider).toLocal8Bit().constData() ); + QWARN( (QStringLiteral( "Certificate handling not supported for ")+provider).toLocal8Bit().constData() ); else { QCA::Certificate cert = certFromDERFile(QStringLiteral("certs/InvalidRevokedEETest3EE.crt"), provider); QCOMPARE( cert.isNull(), false ); diff --git a/unittest/rsaunittest/rsaunittest.cpp b/unittest/rsaunittest/rsaunittest.cpp index 29e24743..4e6017cc 100644 --- a/unittest/rsaunittest/rsaunittest.cpp +++ b/unittest/rsaunittest/rsaunittest.cpp @@ -64,7 +64,7 @@ void RSAUnitTest::testrsa() if(!QCA::isSupported("pkey", provider) || !QCA::PKey::supportedTypes(provider).contains(QCA::PKey::RSA) || !QCA::PKey::supportedIOTypes(provider).contains(QCA::PKey::RSA)) - QWARN(QString("RSA not supported for "+provider).toLocal8Bit().constData()); + QWARN((QStringLiteral("RSA not supported for ")+provider).toLocal8Bit().constData()); else { QCA::KeyGenerator keygen; QCOMPARE( keygen.isBusy(), false ); diff --git a/unittest/symmetrickeyunittest/symmetrickeyunittest.cpp b/unittest/symmetrickeyunittest/symmetrickeyunittest.cpp index 05177785..5248a2ae 100644 --- a/unittest/symmetrickeyunittest/symmetrickeyunittest.cpp +++ b/unittest/symmetrickeyunittest/symmetrickeyunittest.cpp @@ -110,7 +110,7 @@ void SymmetricKeyUnitTest::weakKey() QFETCH( QByteArray, keyText ); QFETCH( bool, isWeak ); - QCA::SymmetricKey key( QCA::hexToArray( QByteArray( keyText ) ) ); + QCA::SymmetricKey key( QCA::hexToArray( QString::fromLatin1(keyText) ) ); QCOMPARE( key.isWeakDESKey(), isWeak ); }