Skip to content

Commit

Permalink
Fix compile errors
Browse files Browse the repository at this point in the history
  • Loading branch information
varjolintu committed Dec 3, 2023
1 parent 3843e83 commit 5948fcd
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 24 deletions.
18 changes: 17 additions & 1 deletion src/sshagent/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
# Copyright (C) 2023 KeePassXC Team <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 or (at your option)
# version 3 of the License.
#
# This program 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

if(WITH_XC_SSHAGENT)
include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})

Expand All @@ -13,6 +28,7 @@ if(WITH_XC_SSHAGENT)
SSHAgent.cpp
)

find_package(Qt6 REQUIRED COMPONENTS Core5Compat)
add_library(sshagent STATIC ${sshagent_SOURCES})
target_link_libraries(sshagent Qt5::Core Qt5::Widgets Qt5::Network)
target_link_libraries(sshagent Qt6::Core Qt6::Core5Compat Qt6::Widgets Qt6::Network)
endif()
29 changes: 15 additions & 14 deletions src/sshagent/KeeAgentSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ void KeeAgentSettings::setFileName(const QString& fileName)
bool KeeAgentSettings::readBool(QXmlStreamReader& reader)
{
reader.readNext();
bool ret = (reader.text().startsWith("t", Qt::CaseInsensitive));
bool ret = (reader.text().toString().startsWith("t", Qt::CaseInsensitive));
reader.readNext(); // tag end
return ret;
}
Expand Down Expand Up @@ -234,37 +234,37 @@ bool KeeAgentSettings::fromXml(const QByteArray& ba)
return false;
}

if (reader.qualifiedName() != "EntrySettings") {
if (reader.qualifiedName().toString() != "EntrySettings") {
m_error = QCoreApplication::translate("KeeAgentSettings", "Invalid KeeAgent settings file structure.");
return false;
}

while (!reader.error() && reader.readNextStartElement()) {
if (reader.name() == "AllowUseOfSshKey") {
if (reader.name().toString() == "AllowUseOfSshKey") {
m_allowUseOfSshKey = readBool(reader);
} else if (reader.name() == "AddAtDatabaseOpen") {
} else if (reader.name().toString() == "AddAtDatabaseOpen") {
m_addAtDatabaseOpen = readBool(reader);
} else if (reader.name() == "RemoveAtDatabaseClose") {
} else if (reader.name().toString() == "RemoveAtDatabaseClose") {
m_removeAtDatabaseClose = readBool(reader);
} else if (reader.name() == "UseConfirmConstraintWhenAdding") {
} else if (reader.name().toString() == "UseConfirmConstraintWhenAdding") {
m_useConfirmConstraintWhenAdding = readBool(reader);
} else if (reader.name() == "UseLifetimeConstraintWhenAdding") {
} else if (reader.name().toString() == "UseLifetimeConstraintWhenAdding") {
m_useLifetimeConstraintWhenAdding = readBool(reader);
} else if (reader.name() == "LifetimeConstraintDuration") {
} else if (reader.name().toString() == "LifetimeConstraintDuration") {
m_lifetimeConstraintDuration = readInt(reader);
} else if (reader.name() == "Location") {
} else if (reader.name().toString() == "Location") {
while (!reader.error() && reader.readNextStartElement()) {
if (reader.name() == "SelectedType") {
if (reader.name().toString() == "SelectedType") {
reader.readNext();
m_selectedType = reader.text().toString();
reader.readNext();
} else if (reader.name() == "AttachmentName") {
} else if (reader.name().toString() == "AttachmentName") {
reader.readNext();
m_attachmentName = reader.text().toString();
reader.readNext();
} else if (reader.name() == "SaveAttachmentToTempFile") {
} else if (reader.name().toString() == "SaveAttachmentToTempFile") {
m_saveAttachmentToTempFile = readBool(reader);
} else if (reader.name() == "FileName") {
} else if (reader.name().toString() == "FileName") {
reader.readNext();
m_fileName = reader.text().toString();
reader.readNext();
Expand Down Expand Up @@ -293,7 +293,8 @@ QByteArray KeeAgentSettings::toXml() const
QXmlStreamWriter writer(&ba);

// real KeeAgent can only read UTF-16
writer.setCodec(QTextCodec::codecForName("UTF-16"));
// TODO: Set to UTF-16
//writer.setCodec(QTextCodec::codecForName("UTF-16"));
writer.setAutoFormatting(true);
writer.setAutoFormattingIndent(2);

Expand Down
5 changes: 3 additions & 2 deletions src/sshagent/OpenSSHKey.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2017 Toni Spets <[email protected]>
* Copyright (C) 2017 KeePassXC Team <[email protected]>
* Copyright (C) 2023 KeePassXC Team <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -26,6 +26,7 @@

#include <QRegularExpression>
#include <QStringList>
#include <QStringView>

#include <botan/pwdhash.h>

Expand Down Expand Up @@ -180,7 +181,7 @@ const QString OpenSSHKey::privateKey()

auto base64Key = QString::fromUtf8(sshKey.toBase64());
for (int i = 0; i < base64Key.size(); i += 70) {
out += base64Key.midRef(i, 70);
out += QStringView{base64Key}.mid(i, 70);
out += "\n";
}

Expand Down
10 changes: 5 additions & 5 deletions tests/TestCli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -685,9 +685,9 @@ void TestCli::testClip()
// Password with timeout
setInput("a");
// clang-format off
QFuture<void> future = QtConcurrent::run(&clipCmd,
static_cast<int(Clip::*)(const QStringList&)>(&DatabaseCommand::execute),
QStringList{"clip", m_dbFile->fileName(), "/Sample Entry", "1"});
auto future = QtConcurrent::run(static_cast<int(Clip::*)(const QStringList&)>(&DatabaseCommand::execute),
&clipCmd,
QStringList{"clip", m_dbFile->fileName(), "/Sample Entry", "1"});
// clang-format on

QTRY_COMPARE(clipboard->text(), QString("Password"));
Expand All @@ -697,8 +697,8 @@ void TestCli::testClip()

// TOTP with timeout
setInput("a");
future = QtConcurrent::run(&clipCmd,
static_cast<int (Clip::*)(const QStringList&)>(&DatabaseCommand::execute),
future = QtConcurrent::run(static_cast<int (Clip::*)(const QStringList&)>(&DatabaseCommand::execute),
&clipCmd,
QStringList{"clip", m_dbFile->fileName(), "/Sample Entry", "1", "-t"});

QTRY_VERIFY(isTotp(clipboard->text()));
Expand Down
4 changes: 2 additions & 2 deletions tests/TestTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,11 @@ void TestTools::testConvertToRegex_data()
<< "^(?:" + Tools::escapeRegex(input) + ")$";

// Exact match does not escape the pattern
QTest::newRow("Exact Match") << input << static_cast<int>(Tools::RegexConvertOpts::EXACT_MATCH)
QTest::newRow("Exact Match 1") << input << static_cast<int>(Tools::RegexConvertOpts::EXACT_MATCH)
<< QString(R"(^(?:te|st*t?[5]^(test);',.)$)");

// Exact match with improper regex
QTest::newRow("Exact Match") << ")av(" << static_cast<int>(Tools::RegexConvertOpts::EXACT_MATCH)
QTest::newRow("Exact Match 2") << ")av(" << static_cast<int>(Tools::RegexConvertOpts::EXACT_MATCH)
<< QString(R"(^(?:)av()$)");

QTest::newRow("Exact Match & Wildcard")
Expand Down

0 comments on commit 5948fcd

Please sign in to comment.