import hashlib


def calculate_hashes_from_pre_hashes(prehash_string_list, hashalg="sha256"):
    """Hash all strings in the list with the given algorithm. Returned in the appropriate NI format.
    """
    hashValueList = []
    for pre_hash_string in prehash_string_list:
        if hashalg == 'sha256':
            hash_string = 'ni:///sha-256;' + \
                          hashlib.sha256(pre_hash_string.encode('utf-8')).hexdigest() + '?ver=CBV2.0'
        elif hashalg == 'sha3-256':
            hash_string = 'ni:///sha3-256;' + \
                          hashlib.sha3_256(pre_hash_string.encode('utf-8')).hexdigest() + '?ver=CBV2.0'
        elif hashalg == 'sha384':
            hash_string = 'ni:///sha-384;' + \
                          hashlib.sha384(pre_hash_string.encode('utf-8')).hexdigest() + '?ver=CBV2.0'
        elif hashalg == 'sha512':
            hash_string = 'ni:///sha-512;' + \
                          hashlib.sha512(pre_hash_string.encode('utf-8')).hexdigest() + '?ver=CBV2.0'
        else:
            raise ValueError("Unsupported Hashing Algorithm: " + hashalg)

        hashValueList.append(hash_string)

    return hashValueList