def calculate_checksum_on_bytes(
    b, algorithm=d1_common.const.DEFAULT_CHECKSUM_ALGORITHM
):
    """Calculate the checksum of ``bytes``.

    Warning: This method requires the entire object to be buffered in (virtual) memory,
    which should normally be avoided in production code.

    Args:
      b: bytes
        Raw bytes

      algorithm: str
        Checksum algorithm, ``MD5`` or ``SHA1`` / ``SHA-1``.

    Returns:
      str : Checksum as a hexadecimal string, with length decided by the algorithm.

    """
    checksum_calc = get_checksum_calculator_by_dataone_designator(algorithm)
    checksum_calc.update(b)
    return checksum_calc.hexdigest()