Package ganeti :: Package utils :: Module hash
[hide private]
[frames] | no frames]

Module hash

source code

Utility functions for hashing.

Functions [hide private]
 
Sha1Hmac(key, text, salt=None)
Calculates the HMAC-SHA1 digest of a text.
source code
bool
VerifySha1Hmac(key, text, digest, salt=None)
Verifies the HMAC-SHA1 digest of a text.
source code
str
_FingerprintFile(filename)
Compute the fingerprint of a file.
source code
dict
FingerprintFiles(files)
Compute fingerprints for a list of files.
source code

Imports: os, hmac, compat


Function Details [hide private]

Sha1Hmac(key, text, salt=None)

source code 

Calculates the HMAC-SHA1 digest of a text.

HMAC is defined in RFC2104.

Parameters:
  • key (string) - Secret key
  • text (string)

VerifySha1Hmac(key, text, digest, salt=None)

source code 

Verifies the HMAC-SHA1 digest of a text.

HMAC is defined in RFC2104.

Parameters:
  • key (string) - Secret key
  • digest (string) - Expected digest
  • text (string)
Returns: bool
Whether HMAC-SHA1 digest matches

_FingerprintFile(filename)

source code 

Compute the fingerprint of a file.

If the file does not exist, a None will be returned instead.

Parameters:
  • filename (str) - the filename to checksum
Returns: str
the hex digest of the sha checksum of the contents of the file

FingerprintFiles(files)

source code 

Compute fingerprints for a list of files.

Parameters:
  • files (list) - the list of filename to fingerprint
Returns: dict
a dictionary filename: fingerprint, holding only existing files