# eric7.WebBrowser.SafeBrowsing.SafeBrowsingCache

Module implementing a cache for Google Safe Browsing.

### Global Attributes

None

### Classes

SafeBrowsingCache | Class implementing a cache for Google Safe Browsing.

### Functions

None

## SafeBrowsingCache

Class implementing a cache for Google Safe Browsing.

### Derived from

QObject

### Class Attributes

create_full_hash_cue_idx
create_full_hash_expires_idx
create_full_hash_value_idx
create_full_hashes_stmt
create_hash_prefix_stmt
create_threat_list_stmt
drop_full_hash_cue_idx
drop_full_hash_expires_idx
drop_full_hash_value_idx
drop_full_hashes_stmt
drop_hash_prefix_stmt
drop_threat_list_stmt
maxProcessEventsTime

### Class Methods

None

### Methods

SafeBrowsingCache | Constructor
__openCacheDb | Private method to open the cache database.
addThreatList | Public method to add a threat list to the cache.
cleanupFullHashes | Public method to clean up full hash entries expired more than the given time.
close | Public method to close the database.
deleteHashPrefixList | Public method to delete hash prefixes for a given threat list.
deleteThreatList | Public method to delete a threat list from the cache.
getHashPrefixValuesToRemove | Public method to get the hash prefix values to be removed from the cache.
getThreatLists | Public method to get the available threat lists.
hashPrefixListChecksum | Public method to calculate the SHA256 checksum for an alphabetically sorted concatenated list of hash prefixes.
lookupFullHashes | Public method to get a list of threat lists and expiration flag for the given hashes if a hash is blacklisted.
lookupHashPrefix | Public method to look up hash prefixes in the local cache.
populateHashPrefixList | Public method to populate the hash prefixes for a threat list.
prepareCacheDb | Public method to prepare the cache database.
removeHashPrefixIndices | Public method to remove hash prefixes from the cache.
storeFullHash | Public method to store full hash data in the cache database.
updateHashPrefixExpiration | Public method to update the hash prefix expiration time.
updateThreatListClientState | Public method to update the client state of a threat list.

### Static Methods

None

#### SafeBrowsingCache (Constructor)

SafeBrowsingCache(dbPath, parent=None)

Constructor

dbPath (str)
  path to store the cache DB into
parent (QObject)
  reference to the parent object

#### SafeBrowsingCache.__openCacheDb

__openCacheDb()

Private method to open the cache database.

Return:
  flag indicating the open state

Return Type:
  bool

#### SafeBrowsingCache.addThreatList

addThreatList(threatList)

Public method to add a threat list to the cache.

threatList (ThreatList)
  threat list to be added

#### SafeBrowsingCache.cleanupFullHashes

cleanupFullHashes(keepExpiredFor=43200)

Public method to clean up full hash entries expired more than the given time.

keepExpiredFor (int or float)
  time period in seconds of entries to be expired

#### SafeBrowsingCache.close

close()

Public method to close the database.

#### SafeBrowsingCache.deleteHashPrefixList

deleteHashPrefixList(threatList)

Public method to delete hash prefixes for a given threat list.

threatList (ThreatList)
  threat list info object

#### SafeBrowsingCache.deleteThreatList

deleteThreatList(threatList)

Public method to delete a threat list from the cache.

threatList (ThreatList)
  threat list to be deleted

#### SafeBrowsingCache.getHashPrefixValuesToRemove

getHashPrefixValuesToRemove(threatList, indexes)

Public method to get the hash prefix values to be removed from the cache.

threatList (ThreatList)
  threat list to remove prefixes from
indexes (list of int)
  list of indexes of prefixes to be removed

Return:
  list of hash prefixes to be removed

Return Type:
  list of bytes

#### SafeBrowsingCache.getThreatLists

getThreatLists()

Public method to get the available threat lists.

Return:
  list of available threat lists

Return Type:
  list of tuples of (ThreatList, str)

#### SafeBrowsingCache.hashPrefixListChecksum

hashPrefixListChecksum(threatList)

Public method to calculate the SHA256 checksum for an alphabetically sorted concatenated list of hash prefixes.

threatList (ThreatList)
  threat list to calculate checksum for

Return:
  SHA256 checksum

Return Type:
  bytes

#### SafeBrowsingCache.lookupFullHashes

lookupFullHashes(hashValues)

Public method to get a list of threat lists and expiration flag for the given hashes if a hash is blacklisted.

hashValues (list of bytes)
  list of hash values to look up

Return:
  list of tuples containing the threat list info and the expiration flag

Return Type:
  list of tuple of (ThreatList, bool)

#### SafeBrowsingCache.lookupHashPrefix

lookupHashPrefix(prefixes)

Public method to look up hash prefixes in the local cache.

prefixes (list of bytes)
  list of hash prefixes to look up

Return:
  list of tuples containing the threat list, full hash and negative cache expiration flag

Return Type:
  list of tuple of (ThreatList, bytes, bool)

#### SafeBrowsingCache.populateHashPrefixList

populateHashPrefixList(threatList, prefixes)

Public method to populate the hash prefixes for a threat list.

threatList (ThreatList)
  threat list of the hash prefixes
prefixes (HashPrefixList)
  list of hash prefixes to be inserted

#### SafeBrowsingCache.prepareCacheDb

prepareCacheDb()

Public method to prepare the cache database.

#### SafeBrowsingCache.removeHashPrefixIndices

removeHashPrefixIndices(threatList, indexes)

Public method to remove hash prefixes from the cache.

threatList (ThreatList)
  threat list to delete hash prefixes of
indexes (list of int)
  list of indexes of prefixes to be removed

#### SafeBrowsingCache.storeFullHash

storeFullHash(threatList, hashValue, cacheDuration, malwareThreatType)

Public method to store full hash data in the cache database.

threatList (ThreatList)
  threat list info object
hashValue (bytes)
  hash to be stored
cacheDuration (int or float)
  duration the data should remain in the cache
malwareThreatType (str)
  threat type of the malware

#### SafeBrowsingCache.updateHashPrefixExpiration

updateHashPrefixExpiration(threatList, hashPrefix, negativeCacheDuration)

Public method to update the hash prefix expiration time.

threatList (ThreatList)
  threat list info object
hashPrefix (bytes)
  hash prefix
negativeCacheDuration (int or float)
  time in seconds the entry should remain in the cache

#### SafeBrowsingCache.updateThreatListClientState

updateThreatListClientState(threatList, clientState)

Public method to update the client state of a threat list.

threatList (ThreatList)
  threat list to update the client state for
clientState (str)
  new client state

Up