32 G_ASSERT( !
valid() ) ;
38 G_ASSERT( !
valid() ) ;
42 const std::string &
id ,
const std::string & context ) :
47 std::string reason =
check( secret , type ,
id ) ;
49 throw Error( reason ) ;
55 else if( type ==
"md5" && isDotted(secret) )
57 m_key = undotted( secret ) ;
68 std::string
GAuth::Secret::check(
const std::string & secret ,
const std::string & type ,
const std::string &
id )
71 return "empty shared key" ;
73 return "invalid encoding type" ;
77 return "invalid plain secret" ;
79 return "invalid encoding of md5 secret" ;
81 return "invalid base64 encoding of secret" ;
82 return std::string() ;
97 return !m_key.empty() ;
102 if( !valid() )
throw Error() ;
108 return !m_mask_type.empty() ;
113 if( !valid() )
throw Error() ;
119 if( !valid() )
throw Error() ;
125 std::ostringstream ss ;
126 ss << (valid()?(masked()?maskType():std::string(
"plaintext")):std::string(
"missing")) <<
" secret" ;
127 std::string id_ = ( id_in.empty() && valid() ) ? m_id : id_in ;
136 bool GAuth::Secret::isDotted(
const std::string & s )
140 s.find_first_not_of(
"0123456789.") == std::string::npos &&
144 std::string GAuth::Secret::undotted(
const std::string & s )
148 for(
size_t i = 0U ; i < 8U ; i++ )
150 G::Md5::big_t n = 0U ;
151 for( std::string::iterator p = decimals[i].begin() ; p != decimals[i].end() ; ++p )
156 for(
int j = 0 ; j < 4 ; j++ )
158 unsigned char uc = ( n & 0xffU ) ;
160 result.push_back( static_cast<char>(uc) ) ;
static bool valid(const std::string &)
Returns true if the string can be decoded without any strict errors.
static std::string printable(const std::string &in, char escape= '\\')
Returns a printable represention of the given input string.
static std::string decode(const std::string &)
Decodes the given string.
std::vector< std::string > StringArray
A std::vector of std::strings.
static std::string decode(const std::string &, bool strict=false)
Decodes the given string.
std::string key() const
Returns the key. Throws if not valid().
bool valid() const
Returns true if the secret is valid.
static std::string check(const std::string &, const std::string &, const std::string &)
Does a non-throwing check of the constructor parameters, returning an error or the empty string...
std::string info(const std::string &id=std::string()) const
Returns information for logging, excluding anything sensitive.
static std::string lower(const std::string &s)
Returns a copy of 's' in which all Latin-1 uppercase characters have been replaced by lowercase chara...
static bool valid(const std::string &)
Returns true if a valid encoding.
std::string id() const
Returns the associated identity. Throws if not valid().
virtual bool valid() const =0
Returns true if a valid source of information.
Secret(const std::string &, const std::string &, const std::string &, const std::string &=std::string())
Constructor used by the SecretsFile class.
static Secret none()
Factory function that returns a secret that is not valid() and has an empty id(). ...
static bool isPrintableAscii(const std::string &s)
Returns true if every character is a 7-bit, non-control character (ie.
bool masked() const
Returns true if key() is masked.
std::string maskType() const
Returns the masking function name, such as "MD5", or the empty string if not masked().
static void splitIntoFields(const std::string &in, StringArray &out, const std::string &separators, char escape= '\0', bool remove_escapes=true)
Splits the string into fields.
Encapsulates a shared secret from the secrets file plus the associated userid.