pymensago/hash.py
def hashbuffer(data: bytes, algorithm: str) -> RetVal:
	'''Calculates a hash value for the memory buffer passed to it

	Parameters:
	  * data: an array of bytes
	  * algorithm: the hash algorithm to be used. This can be one of the following:
			- BLAKE2B-256 (default)
			- BLAKE3-256
			- SHA-256
			- SHA3-256
	
	Returns:
	  * hash: (CryptoString) the computed hash of the buffer
	'''
	if not data:
		return RetVal(ErrBadValue, 'bad path')
	
	hasher = None
	if algorithm == 'BLAKE2B-256':
		hasher = hashlib.blake2b(digest_size=32)
	elif algorithm == 'BLAKE3-256':
		hasher = blake3.blake3() # pylint: disable=c-extension-no-member
	elif algorithm == 'SHA-256':
		hasher = hashlib.sha256()
	elif algorithm == 'SHA3-256':
		hasher = hashlib.sha3_256()
	else:
		return RetVal('ErrUnsupported', 'unsupported algorithm')
	
	hasher.update(data)

	return RetVal().set_value('hash', 
		CryptoString(f"{algorithm}:{base64.b85encode(hasher.digest()).decode()}"))
Calculates a hash value for the memory buffer passed to it

	Parameters:
	  * data: an array of bytes
	  * algorithm: the hash algorithm to be used. This can be one of the following:
			- BLAKE2B-256 (default)
			- BLAKE3-256
			- SHA-256
			- SHA3-256
	
	Returns:
	  * hash: (CryptoString) the computed hash of the buffer
	
Calculates a hash value for the memory buffer passed to it
Calculates a hash value for the memory buffer passed to it
def hashbuffer(data: bytes, algorithm: str) -> RetVal:
	if not data:
		return RetVal(ErrBadValue, 'bad path')
	hasher = None
	if algorithm == 'BLAKE2B-256':
		hasher = hashlib.blake2b(digest_size=32)
	elif algorithm == 'BLAKE3-256':
		hasher = blake3.blake3() 
	elif algorithm == 'SHA-256':
		hasher = hashlib.sha256()
	elif algorithm == 'SHA3-256':
		hasher = hashlib.sha3_256()
	else:
		return RetVal('ErrUnsupported', 'unsupported algorithm')
	hasher.update(data)
	return RetVal().set_value('hash', 
		CryptoString(f"{algorithm}:{base64.b85encode(hasher.digest()).decode()}"))
def hashbuffer ( data : bytes , algorithm : str ) -> RetVal : if not data : return RetVal ( ErrBadValue , 'bad path' ) hasher = None if algorithm == 'BLAKE2B-256' : hasher = hashlib . blake2b ( digest_size = 32 ) elif algorithm == 'BLAKE3-256' : hasher = blake3 . blake3 ( ) elif algorithm == 'SHA-256' : hasher = hashlib . sha256 ( ) elif algorithm == 'SHA3-256' : hasher = hashlib . sha3_256 ( ) else : return RetVal ( 'ErrUnsupported' , 'unsupported algorithm' ) hasher . update ( data ) return RetVal ( ) . set_value ( 'hash' , CryptoString ( f"{algorithm}:{base64.b85encode(hasher.digest()).decode()}" ) )
Calculates a hash value for the memory buffer passed to it
Calculates a hash value for the memory buffer passed to it
'''Calculates a hash value for the memory buffer passed to it

	Parameters:
	  * data: an array of bytes
	  * algorithm: the hash algorithm to be used. This can be one of the following:
			- BLAKE2B-256 (default)
			- BLAKE3-256
			- SHA-256
			- SHA3-256
	
	Returns:
	  * hash: (CryptoString) the computed hash of the buffer
	''' # pylint: disable=c-extension-no-member
(CryptoString) the computed hash of the buffer
( CryptoString ) the computed hash of the buffer
data
bytes
algorithm
str
* data
an array of bytes
an array of bytes
* algorithm
the hash algorithm to be used.
the hash algorithm to be used .