21#ifndef G_AUTH_SECRETS_FILE_H
22#define G_AUTH_SECRETS_FILE_H
50 G_EXCEPTION( Error ,
tx(
"invalid secrets file") ) ;
51 G_EXCEPTION( OpenError ,
tx(
"cannot read secrets file") ) ;
53 static void check(
const std::string &
path ,
bool with_warnings ) ;
88 std::pair<std::string,std::string>
serverTrust(
const std::string & address_range )
const ;
93 std::string
path()
const ;
97 using MapOfSecrets = std::map<std::string,Secret> ;
98 using MapOfInt = std::map<std::string,unsigned int> ;
99 using SetOfStrings = std::set<std::string> ;
100 using Diagnostic = std::tuple<bool,unsigned long,std::string> ;
101 using Diagnostics = std::vector<Diagnostic> ;
102 using TrustMap = std::map<std::string,std::pair<std::string,int>> ;
106 SetOfStrings m_types ;
107 MapOfInt m_selectors ;
108 TrustMap m_trust_map ;
109 Diagnostics m_diagnostics ;
110 std::size_t m_errors {0U} ;
115 void reread()
const ;
118 static Contents readContents(
const G::Path & ) ;
119 static Contents readContents( std::istream & ) ;
120 static void processLine( Contents & ,
123 static void showDiagnostics(
const Contents & c ,
const G::Path & ,
const std::string & debug_name ,
bool with_warnings ) ;
128 static std::string serverKey(
const std::string & ,
const std::string & ) ;
132 static std::string lineContext(
unsigned int ) ;
137 std::string m_debug_name ;
139 Contents m_contents ;
Encapsulates a userid/shared-secret/hash-function tuple from the secrets file.
A class to read authentication secrets from file, used by GAuth::Secrets.
Secret clientSecret(G::string_view type, G::string_view selector={}) const
Returns the client id and secret for the given type.
bool containsClientSelector(G::string_view selector) const
Returns true if the given client account selector is valid.
bool containsServerSecret(G::string_view type, G::string_view id={}) const
Returns true if a server secret of the given type is available for the particular user or for any use...
static void check(const std::string &path, bool with_warnings)
Checks the given file.
bool valid() const
Returns true if the file path was supplied in the ctor.
Secret serverSecret(G::string_view type, G::string_view id) const
Returns the server secret for the given id and type.
std::string path() const
Returns the file path, as supplied to the ctor.
SecretsFile(const G::Path &path, bool auto_reread, const std::string &debug_name)
Constructor to read "client" and "server" records from the named file.
std::pair< std::string, std::string > serverTrust(const std::string &address_range) const
Returns a non-empty trustee name if the server trusts remote clients in the given address range,...
bool containsClientSecret(G::string_view selector) const
Returns true if a client secret is available with the given account selector.
A Path object represents a file system path.
Represents a unix-epoch time with microsecond resolution.
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().