bool PasswordFile::getHMACuser( const std::string& hash, const std::string& key, PwdFileUser& user ) const { FILE* file; char line[ PWD_FILE_LINE_SIZE ]; unsigned char binKey[ MAX_HMAC_KEY_SIZE ]; int keySize; crypto::HMAC_SHA256 userHash( hash ); if (( keySize = base64_decode( key.data(), key.size(), binKey, MAX_HMAC_KEY_SIZE )) < 0 ) { std::string msg = "Cannot convert '" + key + "' to a HMAC binary key"; throw std::runtime_error( msg ); } if ( !boost::filesystem::exists( m_filename ) && !m_create ) { std::string msg = "password file '"; msg += m_filename + "' does not exist"; throw std::runtime_error( msg ); } if (( file = fopen( m_filename.c_str(), "r" )) == NULL ) { int err = errno; std::string msg = "password file '"; msg += m_filename + "' could not be opened: " + strerror( err ); throw std::runtime_error( msg ); } while ( !feof( file ) ) { char* ret = fgets( line, PWD_FILE_LINE_SIZE, file ); if ( ret == NULL ) { if ( feof( file )) { fclose( file ); return false; } else { int err = errno; fclose( file ); std::string msg = "error reading from password file '"; msg += m_filename + "': " + strerror( err ); throw std::runtime_error( msg ); } } std::string uname = pwdLineUser( line ); if ( uname.empty()) continue; if ( !m_caseSensitive ) boost::algorithm::to_lower( uname ); crypto::HMAC_SHA256 hsh( binKey, keySize, uname ); if ( hsh == userHash ) { fclose( file ); bool found = parsePwdLine( line, user ); assert( found == true ); return true; } } return false; }
void Entity::addComponent( Component* comp ) { //auto pos = &typeid(*comp); auto pos = hsh(typeid(*comp).name()); if(components->has(pos)) { throw "This type of component already exists in the entity"; } else { (*components).put( pos, comp ); } comp->parent = this; }