|
| static auto | parse (const QString &config) -> std::optional< Settings > |
| | Parse an OTP configuration string.
|
| static auto | isValid (const QString &config) -> bool |
| | Convenience validity test, for UI feedback.
|
| static auto | generate (const Settings &settings, quint64 unixTime) -> QString |
| | Generate the code for a given point in time.
|
| static auto | generateNow (const Settings &settings) -> QString |
| | Generate the code for the current wall-clock time.
|
| static auto | counter (const Settings &settings, quint64 unixTime) -> quint64 |
| | Time-step counter for a point in time.
|
| static auto | secondsRemaining (const Settings &settings, quint64 unixTime) -> uint |
| | Seconds until the code for unixTime expires.
|
| static auto | toUri (const Settings &settings) -> QString |
| | Serialise settings as a canonical otpauth URI.
|
| static auto | normalize (const QString &config, const QString &label={}, const QString &issuer={}) -> QString |
| | Normalise a user-entered value to a canonical otpauth URI.
|
| static auto | currentUnixTime () -> quint64 |
| | Current wall-clock time.
|
RFC 6238 time-based one-time password generation.
Ported and trimmed from KeePassXC (src/core/Totp.cpp). QtPass stores TOTP configuration as an otpauth://totp/... URI — canonically in the OTP template field, and also accepted as a bare line in the entry body, which is the convention the pass-otp extension uses. Only that dialect plus a bare base32 secret is parsed; KeePassXC's KeeOtp and legacy [step];[digits] formats exist purely to read .kdbx entry attributes and have no meaning in a password store.
Totp::parse() validates everything it returns, so Settings is valid by construction and Totp::generate() cannot fail. HMAC comes from QtCore (QMessageAuthenticationCode), so no crypto dependency is added.
Definition at line 36 of file totp.h.
| auto Totp::parse |
( |
const QString & | config | ) |
-> std::optional< Settings > |
|
staticnodiscard |
Parse an OTP configuration string.
Accepts an otpauth://totp/<label>?secret=... URI, reading the secret, digits, period, algorithm, encoder and issuer parameters, or a bare base32 secret. otpauth://hotp/... is rejected: a counter-based HOTP value cannot be derived from a clock, and returning a plausible-looking TOTP code for it would be silently wrong.
digits is clamped to MIN_DIGITS..MAX_DIGITS and period to 1..MAX_STEP.
- Parameters
-
| config | URI or bare base32 secret; surrounding whitespace is ignored. |
- Returns
- Validated settings, or std::nullopt when the secret is missing or is not decodable base32, or the configuration (its surrounding whitespace included) is longer than MAX_CONFIG_LENGTH.
Definition at line 106 of file totp.cpp.
| auto Totp::toUri |
( |
const Settings & | settings | ) |
-> QString |
|
staticnodiscard |
Serialise settings as a canonical otpauth URI.
Always emits secret, digits and period; emits issuer when it is set, algorithm only when it differs from the RFC 6238 default, and encoder=steam for Encoder::Steam.
Percent-encoding can make the URI longer than the configuration it was parsed from: for one near MAX_CONFIG_LENGTH, parse() refuses it, and normalize() returns nothing rather than such a URI.
- Parameters
-
| settings | Validated settings. |
- Returns
- An otpauth://totp/... URI.
Definition at line 263 of file totp.cpp.