Page Menu
Home
GnuPG
Search
Configure Global Search
Log In
Files
F34633972
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Size
6 KB
Subscribers
None
View Options
diff --git a/src/passentry.cpp b/src/passentry.cpp
index a86b57e..5c9fc06 100644
--- a/src/passentry.cpp
+++ b/src/passentry.cpp
@@ -1,114 +1,129 @@
// SPDX-FileCopyrightText: 2014-2023 Anne Jan Brouwer <brouwer@annejan.com>
// SPDX-FileCopyrightText: 2017 Jason A. Donenfeld <Jason@zx2c4.com>
// SPDX-FileCopyrightText: 2020 Charlie Waters <cawiii@me.com>
// SPDX-FileCopyrightText: 2023 g10 Code GmbH
// SPDX-FileContributor: Sune Stolborg Vuorela <sune@vuorela.dk>
// SPDX-FileContributor: Carl Schwan <carl@carlschwan.eu>
// SPDX-License-Identifier: GPL-3.0-or-later
#include "passentry.h"
#include "config.h"
namespace
{
bool isLineHidden(const QString &line)
{
return line.startsWith(QStringLiteral("otpauth://"), Qt::CaseInsensitive);
}
}
PassEntry::PassEntry()
{
}
bool PassEntry::isNull() const
{
return m_password.isEmpty() && m_remainingData.isEmpty();
}
PassEntry::PassEntry(const QString &name, const QString &content)
: PassEntry(name, content, Config::templateEnabled() ? Config::passTemplate() : QStringList(), Config::templateEnabled() && Config::templateAllFields())
{
}
// TODO port to QStringView once we don't need to support Qt5 anymore
PassEntry::PassEntry(const QString &name, const QString &content, const QStringList &templateFields, bool allFields)
: m_name(name)
{
if (content.isEmpty()) {
return;
}
auto lines = content.split(QLatin1Char('\n'));
m_password = lines.takeFirst();
QStringList remainingData;
QStringList remainingDataForDisplay;
for (const QString &line : std::as_const(lines)) {
if (line.contains(QLatin1Char(':'))) {
int colon = line.indexOf(QLatin1Char(':'));
const QString name = line.left(colon);
const QString value = line.right(line.length() - colon - 1);
if ((allFields && !value.startsWith(QStringLiteral("//"))) // if value startswith // colon is probably from a url
|| templateFields.contains(name)) {
m_namedValues.append({name.trimmed(), value.trimmed()});
continue;
}
}
remainingData.append(line);
if (!isLineHidden(line)) {
remainingDataForDisplay.append(line);
}
}
m_remainingData = remainingData.join(u'\n');
m_remainingDataForDisplay = remainingDataForDisplay.join(u'\n');
}
QString PassEntry::name() const
{
return m_name;
}
QString PassEntry::password() const
{
return m_password;
}
PassEntry::NamedValues PassEntry::namedValues() const
{
return m_namedValues;
}
QString PassEntry::remainingData() const
{
return m_remainingData;
}
QString PassEntry::remainingDataForDisplay() const
{
return m_remainingDataForDisplay;
}
PassEntry::NamedValues::NamedValues()
: QList()
{
}
PassEntry::NamedValues::NamedValues(std::initializer_list<NamedValue> values)
: QList(values)
{
}
QString PassEntry::NamedValues::takeValue(const QString &name)
{
for (int i = 0; i < length(); ++i) {
if (at(i).name == name) {
return takeAt(i).value;
}
}
return QString();
}
bool operator==(const PassEntry::NamedValue &a, const PassEntry::NamedValue &b)
{
return a.name == b.name && a.value == b.value;
}
+
+QDebug operator<<(QDebug debug, const PassEntry::NamedValue &entry)
+{
+ QDebugStateSaver saver(debug);
+ debug.nospace() << '(' << entry.name << ", " << entry.value << ')';
+ return debug;
+}
+
+QDebug operator<<(QDebug debug, const PassEntry &entry)
+{
+ QDebugStateSaver saver(debug);
+ debug.nospace() << "Password Entry(name=" << entry.name() << ", password=" << entry.password() << ", values=" << entry.namedValues() << ", "
+ << entry.remainingData() << ')';
+ return debug;
+}
diff --git a/src/passentry.h b/src/passentry.h
index dadd6b6..9b209be 100644
--- a/src/passentry.h
+++ b/src/passentry.h
@@ -1,70 +1,73 @@
// SPDX-FileCopyrightText: 2024 g10 Code GmbH
// SPDX-FileContributor: Carl Schwan <carl@carlschwan.eu>
// SPDX-License-Identifier: GPL-3.0-or-later
#pragma once
#include <QList>
#include <QString>
/// This class represent a decrypted pass entry.
class PassEntry
{
public:
PassEntry();
explicit PassEntry(const QString &name, const QString &content);
/// \param templateFields the fields in the template. Fields in the
/// template will always be in namedValues() at the beginning of the
/// list in the same order.
///
/// \param allFields whether all fields should be considered as named
/// values. If set to false only templateFields are returned in
/// namedValues().
explicit PassEntry(const QString &name, const QString &content, const QStringList &templateFields, bool allFields);
struct NamedValue {
QString name;
QString value;
};
/// \brief The NamedValues class is mostly a list of NamedValue but also
/// has a method to take a specific NamedValue pair out of the list.
class NamedValues : public QList<NamedValue>
{
public:
NamedValues();
NamedValues(std::initializer_list<NamedValue> values);
QString takeValue(const QString &name);
};
bool isNull() const;
/// \return the name from the file name
QString name() const;
/// \return the password from the parsed file.
QString password() const;
/// \return the named values in the file in the order of appearence, with
/// template values first.
NamedValues namedValues() const;
/// \return the data that is not the password and not in namedValues.
QString remainingData() const;
/// Same as remainingData but without data that should not be displayed
/// (like a TOTP secret).
QString remainingDataForDisplay() const;
private:
QString m_name;
QString m_password;
QString m_remainingData;
QString m_remainingDataForDisplay;
NamedValues m_namedValues;
};
bool operator==(const PassEntry::NamedValue &a, const PassEntry::NamedValue &b);
+
+QDebug operator<<(QDebug debug, const PassEntry::NamedValue &entry);
+QDebug operator<<(QDebug d, const PassEntry &model);
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Tue, Jan 20, 11:32 PM (8 h, 16 m)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
02/1d/c3082d48e6b1b6ec189211cb7dde
Attached To
rGPGPASS GnuPG Password Manager
Event Timeline
Log In to Comment