def METHOD_NAME(key: bytes, infile: BinaryIO, outfile: BinaryIO, tag: bytes):
    if len(key) != 128 / 8:
        raise ValueError("Unsupported key length: %d" % len(key))
    aesgcm = AESGCM(key)
    ciphertext = infile
    plaintext = outfile
    magicstring = ciphertext.read(len(MAGIC_STRING))
    if magicstring != MAGIC_STRING:
        raise ValueError("Data is not encrypted")
    iv = ciphertext.read(12)
    rawbytes = ciphertext.read()
    try:
        decrypted = aesgcm.METHOD_NAME(iv, rawbytes, tag)
    except InvalidTag:
        raise ValueError("Incorrect tag, iv, or corrupted ciphertext")
    plaintext.write(decrypted)