google code style

pull/2356/head
Isaac Connor 2018-05-25 14:21:06 -04:00
parent 52de6ef7ea
commit dd8e4da9ba
1 changed files with 25 additions and 34 deletions

View File

@ -33,8 +33,7 @@ Authenticator::Authenticator( const std::string &username, const std::string &pa
{
#ifdef HAVE_GCRYPT_H
// Special initialisation for libgcrypt
if ( !gcry_check_version( GCRYPT_VERSION ) )
{
if ( !gcry_check_version(GCRYPT_VERSION) ) {
Fatal("Unable to initialise libgcrypt");
}
gcry_control( GCRYCTL_DISABLE_SECMEM, 0 );
@ -64,20 +63,17 @@ void Authenticator::authHandleHeader(std::string headerData)
size_t digest_match_len = strlen(digest_match);
// Check if basic auth
if (strncasecmp(headerData.c_str(),basic_match,strlen(basic_match)) == 0)
{
if ( strncasecmp(headerData.c_str(),basic_match,strlen(basic_match)) == 0 ) {
fAuthMethod = AUTH_BASIC;
Debug(2, "Set authMethod to Basic");
}
// Check if digest auth
else if (strncasecmp( headerData.c_str(),digest_match,digest_match_len ) == 0)
{
else if (strncasecmp( headerData.c_str(),digest_match,digest_match_len ) == 0) {
fAuthMethod = AUTH_DIGEST;
Debug( 2, "Set authMethod to Digest");
StringVector subparts = split(headerData.substr(digest_match_len, headerData.length() - digest_match_len), ",");
// subparts are key="value"
for ( size_t i = 0; i < subparts.size(); i++ )
{
for ( size_t i = 0; i < subparts.size(); i++ ) {
StringVector kvPair = split(trimSpaces(subparts[i]), "=");
std::string key = trimSpaces(kvPair[0]);
if ( key == "realm" ) {
@ -93,7 +89,8 @@ void Authenticator::authHandleHeader(std::string headerData)
continue;
}
}
Debug( 2, "Auth data completed. User: %s, realm: %s, nonce: %s, qop: %s", username().c_str(), fRealm.c_str(), fNonce.c_str(), fQop.c_str() );
Debug(2, "Auth data completed. User: %s, realm: %s, nonce: %s, qop: %s",
username().c_str(), fRealm.c_str(), fNonce.c_str(), fQop.c_str());
}
}
@ -103,12 +100,9 @@ std::string Authenticator::quote( const std::string &src ) {
std::string Authenticator::getAuthHeader(std::string method, std::string uri) {
std::string result = "Authorization: ";
if (fAuthMethod == AUTH_BASIC)
{
if (fAuthMethod == AUTH_BASIC) {
result += "Basic " + base64Encode( username() + ":" + password() );
}
else if (fAuthMethod == AUTH_DIGEST)
{
} else if (fAuthMethod == AUTH_DIGEST) {
result += std::string("Digest ") +
"username=\"" + quote(username()) + "\", realm=\"" + quote(realm()) + "\", " +
"nonce=\"" + quote(nonce()) + "\", uri=\"" + quote(uri) + "\"";
@ -153,8 +147,7 @@ std::string Authenticator::computeDigestResponse(std::string &method, std::strin
gnutls_datum_t md5dataha1 = { (unsigned char*)ha1Data.c_str(), ha1Data.length() };
gnutls_fingerprint( GNUTLS_DIG_MD5, &md5dataha1, md5buf, &md5len );
#endif
for ( unsigned int j = 0; j < md5len; j++ )
{
for ( unsigned int j = 0; j < md5len; j++ ) {
sprintf(&md5HexBuf[2*j], "%02x", md5buf[j] );
}
md5HexBuf[md5len*2]='\0';
@ -169,8 +162,7 @@ std::string Authenticator::computeDigestResponse(std::string &method, std::strin
gnutls_datum_t md5dataha2 = { (unsigned char*)ha2Data.c_str(), ha2Data.length() };
gnutls_fingerprint( GNUTLS_DIG_MD5, &md5dataha2, md5buf, &md5len );
#endif
for ( unsigned int j = 0; j < md5len; j++ )
{
for ( unsigned int j = 0; j < md5len; j++ ) {
sprintf( &md5HexBuf[2*j], "%02x", md5buf[j] );
}
md5HexBuf[md5len*2]='\0';
@ -191,8 +183,7 @@ std::string Authenticator::computeDigestResponse(std::string &method, std::strin
gnutls_datum_t md5datadigest = { (unsigned char*)digestData.c_str(), digestData.length() };
gnutls_fingerprint( GNUTLS_DIG_MD5, &md5datadigest, md5buf, &md5len );
#endif
for ( unsigned int j = 0; j < md5len; j++ )
{
for ( unsigned int j = 0; j < md5len; j++ ) {
sprintf( &md5HexBuf[2*j], "%02x", md5buf[j] );
}
md5HexBuf[md5len*2]='\0';
@ -200,7 +191,7 @@ std::string Authenticator::computeDigestResponse(std::string &method, std::strin
return md5HexBuf;
#else // HAVE_DECL_MD5
Error("You need to build with gnutls or openssl installed to use digest authentication");
return( 0 );
return 0;
#endif // HAVE_DECL_MD5
}