E-MailRelay
Public Types | Public Member Functions | Static Public Member Functions | List of all members
GAuth::Secret Class Reference

Encapsulates a userid/shared-secret/hash-function tuple from the secrets file. More...

#include <gsecret.h>

Public Types

using Value = std::pair< std::string_view, std::string_view >
 

Public Member Functions

 Secret (Value id, Value secret, std::string_view masking_hash_function={}, std::string_view context={})
 Constructor used by the SecretsFile class. More...
 
bool valid () const
 Returns true if the secret is valid. More...
 
std::string id () const
 Returns the associated identity. Throws if not valid(). More...
 
std::string secret () const
 Returns the secret shared key. Throws if not valid(). More...
 
bool masked () const
 Returns true if a non-empty hash function was passed to the ctor. More...
 
std::string maskHashFunction () const
 Returns the masking function name as passed to the ctor, such as "md5", or the empty string if not masked(). More...
 
std::string info (const std::string &id={}) const
 Returns information for logging, excluding anything sensitive. More...
 

Static Public Member Functions

static std::string check (Value id, Value secret, std::string_view masking_hash_function)
 Does a non-throwing check of the constructor parameters, returning an error message or the empty string. More...
 
static Secret none ()
 Factory function that returns a secret that is not valid(). More...
 
static bool isDotted (std::string_view)
 Returns true if the given secret string looks like it is in the old dotted format rather than base64. More...
 
static std::string decode (Value)
 Decodes a value. More...
 

Detailed Description

Encapsulates a userid/shared-secret/hash-function tuple from the secrets file.

The shared secret can be a plaintext password or it can be a masked password using the given hash function. A masked secret can only be verified by an hmac operation using that hash function. However, the implementation of the hash function must be capable of accepting an intermediate hash state, and this might only be the case for md5.

Definition at line 43 of file gsecret.h.

Member Typedef Documentation

◆ Value

using GAuth::Secret::Value = std::pair<std::string_view,std::string_view>

Definition at line 48 of file gsecret.h.

Constructor & Destructor Documentation

◆ Secret()

GAuth::Secret::Secret ( Value  id,
Value  secret,
std::string_view  masking_hash_function = {},
std::string_view  context = {} 
)

Constructor used by the SecretsFile class.

Throws on error, including if the encodings are invalid. Encodings should be empty (raw) or "xtext" or "base64" or "dotted".

Definition at line 31 of file gsecret.cpp.

Member Function Documentation

◆ check()

std::string GAuth::Secret::check ( Value  id,
Value  secret,
std::string_view  masking_hash_function 
)
static

Does a non-throwing check of the constructor parameters, returning an error message or the empty string.

Definition at line 49 of file gsecret.cpp.

◆ decode()

std::string GAuth::Secret::decode ( Value  value)
static

Decodes a value.

Definition at line 187 of file gsecret.cpp.

◆ id()

std::string GAuth::Secret::id ( ) const

Returns the associated identity. Throws if not valid().

Definition at line 96 of file gsecret.cpp.

◆ info()

std::string GAuth::Secret::info ( const std::string &  id = {}) const

Returns information for logging, excluding anything sensitive.

The secret may be in-valid().

Definition at line 108 of file gsecret.cpp.

◆ isDotted()

bool GAuth::Secret::isDotted ( std::string_view  s)
static

Returns true if the given secret string looks like it is in the old dotted format rather than base64.

Definition at line 124 of file gsecret.cpp.

◆ masked()

bool GAuth::Secret::masked ( ) const

Returns true if a non-empty hash function was passed to the ctor.

Definition at line 91 of file gsecret.cpp.

◆ maskHashFunction()

std::string GAuth::Secret::maskHashFunction ( ) const

Returns the masking function name as passed to the ctor, such as "md5", or the empty string if not masked().

Throws if not valid().

Definition at line 102 of file gsecret.cpp.

◆ none()

GAuth::Secret GAuth::Secret::none ( )
static

Factory function that returns a secret that is not valid().

Definition at line 75 of file gsecret.cpp.

◆ secret()

std::string GAuth::Secret::secret ( ) const

Returns the secret shared key. Throws if not valid().

Definition at line 85 of file gsecret.cpp.

◆ valid()

bool GAuth::Secret::valid ( ) const

Returns true if the secret is valid.

Definition at line 80 of file gsecret.cpp.


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