8#ifndef SRC_FILECONTENT_H_
9#define SRC_FILECONTENT_H_
66 NamedValues(std::initializer_list<NamedValue> values);
73 auto takeValue(
const QString &name) -> QString;
149 static auto parse(
const QString &fileContent,
150 const QStringList &templateFields,
bool allFields,
151 const std::function<
bool(
const QString &)> &alsoField = {})
201 [[nodiscard]] static auto
isOtpFieldName(const QString &name) ->
bool;
212 const QStringList &secrets)
224 [[nodiscard]] static auto
isOtpUriValue(const QString &value) ->
bool;
242 [[nodiscard]] auto
getOtpUri() const -> QString;
Represents the parsed contents of a password file.
static auto boundedForDisplay(const QString &text) -> QString
text cut to kMaxDisplayLines lines, as getRemainingDataForDisplay() is: for showing an entry as it is...
FileContent(QString password, NamedValues namedValues, QString remainingData, QString remainingDataDisplay, QString otpUri, qsizetype remainingLines)
Assemble a parsed entry; only parse() calls this.
qsizetype remainingLines
Number of lines in remainingData.
QString remainingData
Body lines that are not fields, joined with newlines; complete.
auto getRemainingLineCount() const -> qsizetype
How many lines getRemainingData() holds.
QString password
The first line of the entry, verbatim.
static auto isOtpFieldName(const QString &name) -> bool
Whether a field name designates the one-time password field.
QString otpUri
Raw OTP configuration (URI or bare base32), or empty.
static constexpr int kMaxDisplayLines
Most lines of remaining text getRemainingDataForDisplay() gives.
auto getRemainingData() const -> QString
auto getNamedValues() const -> NamedValues
static constexpr int kMaxNamedFields
Most named fields parse() takes from one entry.
static auto parse(const QString &fileContent, const QStringList &templateFields, bool allFields, const std::function< bool(const QString &)> &alsoField={}) -> FileContent
parse parses the given fileContent in a FileContent object. The password is accessible through getPas...
static auto isSecretFieldName(const QString &name, const QStringList &secrets) -> bool
Whether a field name names a secret: one of secrets occurs in it as whole words, compared case-insens...
NamedValues namedValues
Fields in order of appearance, template fields first.
auto getRemainingDataForDisplay() const -> QString
Like getRemainingData but without data that should not be displayed (like a TOTP secret).
auto getPassword() const -> QString
auto getOtpUri() const -> QString
The entry's raw one-time password configuration, if it has one.
QString remainingDataDisplay
auto getPasswordForDisplay() const -> QString
Like getPassword but empty when the password line is itself an otpauth URI.
static auto isOtpUriValue(const QString &value) -> bool
Whether a field value is an otpauth URI, and therefore a secret.
The NamedValues class is mostly a list of NamedValue but also has a method to take a specific NamedVa...
auto takeValue(const QString &name) -> QString
Remove and return the value for the named field.
auto takeNamedValue(const QString &name) -> NamedValue
Remove and return the named field, its original line included.
NamedValues()
Construct an empty list.
bool operator==(const NamedValue &a, const NamedValue &b)
Two fields are equal when name and value match; originalLine is formatting, not content,...
A name/value pair parsed from a password file field.
QString name
Field name (the part before the colon in "name: value").
QString originalLine
The field's verbatim source line, colon and spacing intact.
QString value
Field value (the part after the colon in "name: value").