def build_cipher(key, iv, alg="aes_128_cbc"):
    typ, bits, cmode = alg.split("_")

    if not iv:
        iv = Random.new().read(AES.block_size)
    else:
        assert len(iv) == AES.block_size

    if bits not in ["128", "192", "256"]:
        raise AESError("Unsupported key length")
    try:
        assert len(key) == int(bits) >> 3
    except AssertionError:
        raise AESError("Wrong Key length")

    try:
        return AES.new(tobytes(key), POSTFIX_MODE[cmode], tobytes(iv)), iv
    except KeyError:
        raise AESError("Unsupported chaining mode")
Test grammar of DataRef
dataset/ETHPy150Open rohe/pyoidc/src/oic/utils/aes.py/build_cipher--crossover with--dataset/ETHPy150Open wrobstory/vincent/tests/test_vega.py/TestDataRef.test_grammar_typechecking