21#ifndef G_AUTH_SECRET_H
22#define G_AUTH_SECRET_H
46 G_EXCEPTION( Error ,
tx(
"invalid authorisation secret") )
47 G_EXCEPTION( BadId ,
tx(
"invalid authorisation id") )
48 using Value = std::pair<std::string_view,std::string_view> ;
50 Secret( Value
id , Value
secret , std::string_view masking_hash_function = {} ,
51 std::string_view context = {} ) ;
57 std::string_view masking_hash_function ) ;
64 std::string
id()
const ;
67 std::string
secret()
const ;
82 std::string
info(
const std::string &
id = {} )
const ;
86 static bool isDotted( std::string_view ) ;
90 static std::string
decode( Value ) ;
94 enum class Encoding { xtext , base64 , raw , dotted } ;
96 static std::string undotted( std::string_view ) ;
97 static bool validEncodingType( Value ) ;
98 static bool validEncoding( Value ) ;
99 static Encoding encoding( Value ) ;
103 std::string m_secret ;
104 std::string m_hash_function ;
105 std::string m_context ;
Encapsulates a userid/shared-secret/hash-function tuple from the secrets file.
std::string secret() const
Returns the secret shared key. Throws if not valid().
bool masked() const
Returns true if a non-empty hash function was passed to the ctor.
static Secret none()
Factory function that returns a secret that is not valid().
std::string maskHashFunction() const
Returns the masking function name as passed to the ctor, such as "md5", or the empty string if not ma...
bool valid() const
Returns true if the secret is valid.
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.
std::string info(const std::string &id={}) const
Returns information for logging, excluding anything sensitive.
static std::string decode(Value)
Decodes a value.
std::string id() const
Returns the associated identity. Throws if not valid().
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 stri...
SASL authentication classes.
constexpr const char * tx(const char *p) noexcept
A briefer alternative to G::gettext_noop().