Represents the parsed contents of a password file.
More...
#include <filecontent.h>
|
| static auto | boundedForDisplay (const QString &text) -> QString |
| | text cut to kMaxDisplayLines lines, as getRemainingDataForDisplay() is: for showing an entry as it is (displayAsIs).
|
| 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 getPassword. The named value pairs (name: value) are parsed and depending on the templateFields and allFields parameters accessible through getNamedValues, getRemainingData or getRemainingDataForDisplay.
|
| static auto | isOtpFieldName (const QString &name) -> bool |
| | Whether a field name designates the one-time password field.
|
| 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-insensitively ("key" matches "API key" and "Recovery key", not "keyboard layout").
|
| static auto | isOtpUriValue (const QString &value) -> bool |
| | Whether a field value is an otpauth URI, and therefore a secret.
|
|
| | FileContent (QString password, NamedValues namedValues, QString remainingData, QString remainingDataDisplay, QString otpUri, qsizetype remainingLines) |
| | Assemble a parsed entry; only parse() calls this.
|
Represents the parsed contents of a password file.
Splits the file into a password line, named key/value fields, and remaining data. Use FileContent::parse to construct an instance.
Definition at line 92 of file filecontent.h.
◆ FileContent()
| FileContent::FileContent |
( |
QString | password, |
|
|
NamedValues | namedValues, |
|
|
QString | remainingData, |
|
|
QString | remainingDataDisplay, |
|
|
QString | otpUri, |
|
|
qsizetype | remainingLines ) |
|
private |
Assemble a parsed entry; only parse() calls this.
- Parameters
-
| password | The first line. |
| namedValues | The fields promoted out of the body. |
| remainingData | The body lines that did not become fields. |
| remainingDataDisplay | remainingData without secret-bearing lines, cut at kMaxDisplayLines. |
| otpUri | The OTP configuration found, or empty. |
| remainingLines | Line count of remainingData. |
Definition at line 289 of file filecontent.cpp.
◆ boundedForDisplay()
| auto FileContent::boundedForDisplay |
( |
const QString & | text | ) |
-> QString |
|
staticnodiscard |
text cut to kMaxDisplayLines lines, as getRemainingDataForDisplay() is: for showing an entry as it is (displayAsIs).
- Parameters
-
- Returns
text when it is short enough, else its first kMaxDisplayLines lines and one saying how many more there are.
Definition at line 297 of file filecontent.cpp.
◆ getNamedValues()
| auto FileContent::getNamedValues |
( |
| ) |
const -> NamedValues |
|
nodiscard |
- Returns
- the named values in the file in the order of appearance, with template values first.
Definition at line 275 of file filecontent.cpp.
◆ getOtpUri()
| auto FileContent::getOtpUri |
( |
| ) |
const -> QString |
|
nodiscard |
The entry's raw one-time password configuration, if it has one.
Looked up in this order:
- the value of the first field whose name satisfies isOtpFieldName();
- the first bare otpauth:// line in the body, which is how the pass-otp extension stores it;
- the value of the first OTP: line that was not promoted to a named value, which is what happens when the template does not list OTP.
The string is returned verbatim and is not validated here: it may be an otpauth:// URI or a bare base32 secret. Totp::parse() does the validation.
- Returns
- The OTP configuration string, or an empty string when the entry has none.
Definition at line 287 of file filecontent.cpp.
◆ getPassword()
| auto FileContent::getPassword |
( |
| ) |
const -> QString |
|
nodiscard |
◆ getPasswordForDisplay()
| auto FileContent::getPasswordForDisplay |
( |
| ) |
const -> QString |
|
nodiscard |
Like getPassword but empty when the password line is itself an otpauth URI.
pass otp insert writes the URI as the entry's only line, so it lands in the password position. It is a shared secret, not a password: it must never be rendered or placed on the clipboard. getPassword() still returns it so the edit dialog round-trips the file unchanged.
- Returns
- The password, or an empty string when it is an otpauth URI.
Definition at line 271 of file filecontent.cpp.
◆ getRemainingData()
| auto FileContent::getRemainingData |
( |
| ) |
const -> QString |
|
nodiscard |
- Returns
- the data that is not the password and not in getNamedValues.
Definition at line 279 of file filecontent.cpp.
◆ getRemainingDataForDisplay()
| auto FileContent::getRemainingDataForDisplay |
( |
| ) |
const -> QString |
|
nodiscard |
Like getRemainingData but without data that should not be displayed (like a TOTP secret).
- Returns
- Remaining data string safe for display.
Definition at line 283 of file filecontent.cpp.
◆ getRemainingLineCount()
| auto FileContent::getRemainingLineCount |
( |
| ) |
const -> qsizetype |
|
nodiscard |
◆ isOtpFieldName()
| auto FileContent::isOtpFieldName |
( |
const QString & | name | ) |
-> bool |
|
staticnodiscard |
Whether a field name designates the one-time password field.
- Parameters
-
| name | Field name as written in the file; surrounding whitespace is ignored. |
- Returns
- true for "OTP" or "TOTP", compared case-insensitively.
Definition at line 217 of file filecontent.cpp.
◆ isOtpUriValue()
| auto FileContent::isOtpUriValue |
( |
const QString & | value | ) |
-> bool |
|
staticnodiscard |
Whether a field value is an otpauth URI, and therefore a secret.
A URI is a shared secret whatever the field is called, so both the display-suppression and the OTP lookup key off the value as well as the name; suppressing only OTP:/TOTP: leaked 2fa: and friends.
- Parameters
-
| value | Field value; surrounding whitespace is ignored. |
- Returns
- true when it starts with "otpauth://", compared case-insensitively.
Definition at line 264 of file filecontent.cpp.
◆ isSecretFieldName()
| auto FileContent::isSecretFieldName |
( |
const QString & | name, |
|
|
const QStringList & | secrets ) -> bool |
|
staticnodiscard |
Whether a field name names a secret: one of secrets occurs in it as whole words, compared case-insensitively ("key" matches "API key" and "Recovery key", not "keyboard layout").
- Parameters
-
- Returns
- true when one of them occurs in
name.
Definition at line 223 of file filecontent.cpp.
◆ parse()
| auto FileContent::parse |
( |
const QString & | fileContent, |
|
|
const QStringList & | templateFields, |
|
|
bool | allFields, |
|
|
const std::function< bool(const QString &)> & | alsoField = {} ) -> FileContent |
|
static |
parse parses the given fileContent in a FileContent object. The password is accessible through getPassword. The named value pairs (name: value) are parsed and depending on the templateFields and allFields parameters accessible through getNamedValues, getRemainingData or getRemainingDataForDisplay.
- Parameters
-
| fileContent | the file content to parse. |
| templateFields | the fields in the template. Fields in the template will always be in getNamedValues() at the beginning of the list in the same order. |
| allFields | whether all fields should be considered as named values. If set to false only templateFields are returned in getNamedValues(). |
| alsoField | a field besides those, by its trimmed name: a secret the panel hides, which must not be left in the remaining text in plain view. Empty: none. |
- Returns
- A FileContent instance with password, named values, and remaining data populated from the parsed input.
Definition at line 132 of file filecontent.cpp.
◆ kMaxDisplayLines
| int FileContent::kMaxDisplayLines = 10000 |
|
staticconstexpr |
Most lines of remaining text getRemainingDataForDisplay() gives.
The text browser makes a block, with its layout, per line. Past this many the display text ends with one line saying how many more there are; getRemainingData() keeps them all, so saving loses nothing. The edit dialog uses the same number for the whole entry (password and fields included) and does not load one with more lines.
Definition at line 114 of file filecontent.h.
◆ kMaxNamedFields
| int FileContent::kMaxNamedFields = 1000 |
|
staticconstexpr |
Most named fields parse() takes from one entry.
Every field becomes a row of widgets in the display panel. An entry is compressed before it is encrypted, so a small one in a shared store could decompress into millions of "a: b" lines within the plaintext limit; lines past this many fields stay in the remaining text. They are still looked at for an OTP configuration, as fields would be.
Definition at line 103 of file filecontent.h.
◆ namedValues
Fields in order of appearance, template fields first.
Definition at line 262 of file filecontent.h.
◆ otpUri
| QString FileContent::otpUri |
|
private |
Raw OTP configuration (URI or bare base32), or empty.
Definition at line 268 of file filecontent.h.
◆ password
| QString FileContent::password |
|
private |
The first line of the entry, verbatim.
Definition at line 260 of file filecontent.h.
◆ remainingData
| QString FileContent::remainingData |
|
private |
Body lines that are not fields, joined with newlines; complete.
Definition at line 264 of file filecontent.h.
◆ remainingDataDisplay
| QString FileContent::remainingDataDisplay |
|
private |
remainingData for the panel: OTP-bearing lines and hidden secrets left out, at most kMaxDisplayLines lines plus a "more" line.
Definition at line 264 of file filecontent.h.
◆ remainingLines
| qsizetype FileContent::remainingLines = 0 |
|
private |
The documentation for this class was generated from the following files: