57 uint32_t period_ = 30;
59 Algorithm algorithm_ = Algorithm::kSha1;
81 uint32_t
period()
const {
return period_; }
84 void set_period(uint32_t period) { period_ = period == 0 ? 1 : period; }
87 uint32_t
digits()
const {
return digits_; }
90 void set_digits(uint32_t digits) { digits_ = digits < 1 ? 1 : (digits > 10 ? 10 : digits); }
109 static std::optional<TotpConfig>
Parse(
const std::string& seed_field,
110 const std::string& settings_field = {});
A single KeePass entry (a username/password record).
Definition entry.hh:55
Parsed TOTP parameters from an entry's custom fields.
Definition totp.hh:50
static std::optional< TotpConfig > FromEntry(const Entry &entry)
Extracts and parses the TOTP fields of an entry.
void set_period(uint32_t period)
Sets the time step in seconds (clamped to at least one second).
Definition totp.hh:84
TotpConfig()=default
Creates an empty (invalid) configuration.
TotpConfig(secure_string secret, uint32_t period=30, uint32_t digits=6, Algorithm algorithm=Algorithm::kSha1)
void set_secret(const secure_string &secret)
Replaces the Base32 shared secret.
Definition totp.hh:78
void set_digits(uint32_t digits)
Sets the number of output digits (supported range 1-10).
Definition totp.hh:90
const secure_string & secret() const
Returns the Base32 shared secret.
Definition totp.hh:75
void set_algorithm(Algorithm algorithm)
Sets the HMAC algorithm.
Definition totp.hh:96
Algorithm algorithm() const
Returns the HMAC algorithm.
Definition totp.hh:93
static std::optional< TotpConfig > Parse(const std::string &seed_field, const std::string &settings_field={})
Parses a TOTP seed/URI plus optional settings string.
uint32_t period() const
Returns the time step in seconds.
Definition totp.hh:81
Algorithm
Hash algorithms used by the HMAC-based TOTP construction.
Definition totp.hh:53
uint32_t digits() const
Returns the number of output digits.
Definition totp.hh:87
bool empty() const
Returns whether a secret is present.
Definition totp.hh:99
TOTP code generation (RFC 6238).
Definition totp.hh:119
static std::string Generate(const Entry &entry, std::time_t time=0)
Generates a code for the TOTP fields of an entry.
static std::string Generate(const TotpConfig &config, std::time_t time=0)
Generates the current TOTP code.
static uint32_t SecondsRemaining(const TotpConfig &config, std::time_t time=0)
Returns the number of seconds until the current time step expires.
String that is stored in wiped and best-effort locked memory.
Definition secure.hh:262
bool empty() const noexcept
Returns whether the string is empty.
Definition secure.hh:325
Visibility/export macro for the shared library.
#define LIBKEEPASS_API
Marks a class, function or variable as part of the public ABI.
Definition export.hh:43
Secure memory handling: zeroization, locked allocations and sensitive value containers.