21#ifndef G_AUTH_SECRET_H
22#define G_AUTH_SECRET_H
45 G_EXCEPTION( Error ,
tx(
"invalid authorisation secret") ) ;
46 G_EXCEPTION( BadId ,
tx(
"invalid authorisation id") ) ;
47 using Value = std::pair<G::string_view,G::string_view> ;
63 std::string
id()
const ;
66 std::string
secret()
const ;
81 std::string
info(
const std::string &
id = {} )
const ;
89 static std::string
decode( Value ) ;
93 enum class Encoding { xtext , base64 , raw , dotted } ;
96 static bool validEncodingType( Value ) ;
97 static bool validEncoding( Value ) ;
98 static Encoding encoding( Value ) ;
102 std::string m_secret ;
103 std::string m_hash_function ;
104 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.
std::string info(const std::string &id={}) const
Returns information for logging, excluding anything sensitive.
static std::string check(Value id, Value secret, G::string_view masking_hash_function)
Does a non-throwing check of the constructor parameters, returning an error message or the empty stri...
static bool isDotted(G::string_view)
Returns true if the given secret string looks like it is in the old dotted format rather than base64.
static std::string decode(Value)
Decodes a value.
std::string id() const
Returns the associated identity. Throws if not valid().
A class like c++17's std::string_view.
SASL authentication classes.
constexpr const char * tx(const char *p)
A briefer alternative to G::gettext_noop().