def create_checksum_object_from_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:
      Populated PyXB Checksum object.

    """
    checksum_str = calculate_checksum_on_bytes(b, algorithm)
    checksum_pyxb = d1_common.types.dataoneTypes.checksum(checksum_str)
    checksum_pyxb.algorithm = algorithm
    return checksum_pyxb