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"). A word ends where a letter does not follow, so digits and _ separate too ("PIN2", "api_key"); a plural "s" may follow ("tokens"); and camelCase words count ("apiKey", "clientSecret", "APIKey").
|
| static auto | isOtpUriValue (const QString &value) -> bool |
| | Whether a field value is an otpauth URI, and therefore a secret.
|
| static auto | carriesOtpUri (const QString &text) -> bool |
| | Whether text holds an otpauth URI anywhere: after a list dash, in quotes, behind other text or a second colon, or split at its colon as otpauth: // (as 1.8 to 2.0-rc2 saved it). What keeps a line off the screen and the clipboard goes by this; what is read as the OTP configuration goes by isOtpUriValue().
|
| static auto | isOtpLine (const QString &line) -> bool |
| | Whether line carries a TOTP shared secret: a bare otpauth:// line, an OTP:/TOTP: field, or any line with an otpauth URI in it (carriesOtpUri()).
|
| static auto | isOtpPasswordLine (const QString &line) -> bool |
| | Whether an entry's first line holds a TOTP shared secret rather than a password.
|
| static auto | passwordLine (QStringView text) -> QString |
| | The password of an entry: its first line, without the carriage return of a CRLF line end.
|
|
| | 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 525 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 533 of file filecontent.cpp.
◆ carriesOtpUri()
| auto FileContent::carriesOtpUri |
( |
const QString & | text | ) |
-> bool |
|
staticnodiscard |
Whether text holds an otpauth URI anywhere: after a list dash, in quotes, behind other text or a second colon, or split at its colon as otpauth: // (as 1.8 to 2.0-rc2 saved it). What keeps a line off the screen and the clipboard goes by this; what is read as the OTP configuration goes by isOtpUriValue().
- Parameters
-
| text | A line or a field value. |
- Returns
- true when "otpauth:" followed by "//" (blanks between allowed) occurs in it, compared case-insensitively.
Definition at line 464 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 511 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 523 of file filecontent.cpp.
◆ getPassword()
| auto FileContent::getPassword |
( |
| ) |
const -> QString |
|
nodiscard |
The password: the first line, without the "\r" of a CRLF line end (passwordLine()).
- Returns
- the password from the parsed file.
Definition at line 505 of file filecontent.cpp.
◆ getPasswordForDisplay()
| auto FileContent::getPasswordForDisplay |
( |
| ) |
const -> QString |
|
nodiscard |
Like getPassword but empty when the password line holds a TOTP shared secret (isOtpPasswordLine()).
pass otp insert writes the URI as the entry's only line, so it lands in the password position, and an OTP:/TOTP: field holding a seed written there by hand is the same secret. It is 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 OTP line.
Definition at line 507 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 515 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 519 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 382 of file filecontent.cpp.
◆ isOtpLine()
| auto FileContent::isOtpLine |
( |
const QString & | line | ) |
-> bool |
|
staticnodiscard |
Whether line carries a TOTP shared secret: a bare otpauth:// line, an OTP:/TOTP: field, or any line with an otpauth URI in it (carriesOtpUri()).
The rule for the lines below the password: such a line is never shown or copied, only the code it yields is. The first line goes by isOtpPasswordLine().
- Parameters
-
| line | One line of the entry. |
- Returns
- true when the line holds a shared secret.
Definition at line 493 of file filecontent.cpp.
◆ isOtpPasswordLine()
| auto FileContent::isOtpPasswordLine |
( |
const QString & | line | ) |
-> bool |
|
staticnodiscard |
Whether an entry's first line holds a TOTP shared secret rather than a password.
Stricter than isOtpLine(), because the first line is the password in the pass format: a line with an otpauth URI in it (carriesOtpUri()), or an OTP:/TOTP: field whose value is written as a base32 seed (base32 characters only, at least 16, and usable by Totp). A password that merely starts with "otp:" or "totp:" (totp:Secr3t!) stays the password; a long one of letters and the digits 2 to 7 only reads as a seed and cannot be told apart.
- Parameters
-
| line | The entry's first line. |
- Returns
- true when the line is an OTP secret and not the password.
Definition at line 501 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 459 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"). A word ends where a letter does not follow, so digits and _ separate too ("PIN2", "api_key"); a plural "s" may follow ("tokens"); and camelCase words count ("apiKey", "clientSecret", "APIKey").
- Parameters
-
- Returns
- true when one of them occurs in
name.
Definition at line 388 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 312 of file filecontent.cpp.
◆ passwordLine()
| auto FileContent::passwordLine |
( |
QStringView | text | ) |
-> QString |
|
staticnodiscard |
The password of an entry: its first line, without the carriage return of a CRLF line end.
The one rule for every path that takes the password from decrypted text (parse(), the Ctrl+C copy), so they agree with the password row: a "\r" before the line feed is the line end, not part of the secret.
- Parameters
-
| text | Decrypted entry text, or just its first line. |
- Returns
- Its first line, a trailing "\r" dropped.
Definition at line 484 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 322 of file filecontent.h.
◆ otpUri
| QString FileContent::otpUri |
|
private |
Raw OTP configuration (URI or bare base32), or empty.
Definition at line 328 of file filecontent.h.
◆ password
| QString FileContent::password |
|
private |
◆ remainingData
| QString FileContent::remainingData |
|
private |
Body lines that are not fields, joined with newlines; complete.
Definition at line 324 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 324 of file filecontent.h.
◆ remainingLines
| qsizetype FileContent::remainingLines = 0 |
|
private |
The documentation for this class was generated from the following files: