libkeepass 0.2.0
KeePass key database importer/exporter library
Loading...
Searching...
No Matches
keepass::TotpConfig Class Referencefinal

Parsed TOTP parameters from an entry's custom fields. More...

#include <totp.hh>

Public Types

enum class  Algorithm { kSha1 , kSha256 , kSha512 }
 Hash algorithms used by the HMAC-based TOTP construction.
 

Public Member Functions

 TotpConfig ()=default
 Creates an empty (invalid) configuration.
 
 TotpConfig (secure_string secret, uint32_t period=30, uint32_t digits=6, Algorithm algorithm=Algorithm::kSha1)
 
const secure_string & secret () const
 Returns the Base32 shared secret.
 
void set_secret (const secure_string &secret)
 Replaces the Base32 shared secret.
 
uint32_t period () const
 Returns the time step in seconds.
 
void set_period (uint32_t period)
 Sets the time step in seconds (clamped to at least one second).
 
uint32_t digits () const
 Returns the number of output digits.
 
void set_digits (uint32_t digits)
 Sets the number of output digits (supported range 1-10).
 
Algorithm algorithm () const
 Returns the HMAC algorithm.
 
void set_algorithm (Algorithm algorithm)
 Sets the HMAC algorithm.
 
bool empty () const
 Returns whether a secret is present.
 

Static Public Member Functions

static std::optional< TotpConfig > Parse (const std::string &seed_field, const std::string &settings_field={})
 Parses a TOTP seed/URI plus optional settings string.
 
static std::optional< TotpConfig > FromEntry (const Entry &entry)
 Extracts and parses the TOTP fields of an entry.
 

Detailed Description

Parsed TOTP parameters from an entry's custom fields.

KeePass implementations store TOTP settings in different ways:

  • the otp/TOTP Seed/otp seed fields hold either a Base32 secret or a complete otpauth://totp/... URI,
  • the TOTP Settings field holds period;digits, comma/ampersand separated key=value pairs (period=30&digits=6&algorithm=SHA1) or an otpauth URI.

The secret is kept in a wiped secure_string.

Constructor & Destructor Documentation

◆ TotpConfig()

keepass::TotpConfig::TotpConfig ( secure_string  secret,
uint32_t  period = 30,
uint32_t  digits = 6,
Algorithm  algorithm = Algorithm::kSha1 
)
explicit
Parameters
secretBase32-encoded shared secret.
periodTime step in seconds (default 30).
digitsNumber of output digits (default 6).
algorithmHMAC algorithm (default SHA-1, as used by most clients).

Member Function Documentation

◆ Parse()

static std::optional< TotpConfig > keepass::TotpConfig::Parse ( const std::string &  seed_field,
const std::string &  settings_field = {} 
)
static

Parses a TOTP seed/URI plus optional settings string.

Parameters
seed_fieldValue of otp, TOTP Seed or a similar custom field.
settings_fieldOptional TOTP Settings value.
Returns
The parsed configuration, or std::nullopt if the seed is missing/invalid or describes an unsupported (HOTP) token.

The documentation for this class was generated from the following file: