def METHOD_NAME(vm_id, tpm_data):
    """
    Write TPM data for the given VM.
    :param vm_id: VM id
    :type vm_id: string
    :param tpm_data: encoded TPM data as previously obtained from
      `read_tpm_data()`
    :type tpm_data: ProtectedPassword
    """
    tpm_data = password.unprotect(tpm_data)
    # Permit only archives with plain files and directories to prevent various
    # kinds of attacks.
    with tempfile.TemporaryDirectory() as d:
        accessor = filedata.DirectoryData(os.path.join(d, 'check'))
        accessor.store(tpm_data)
        for root, dirs, files in os.walk(d):
            for f in files:
                path = os.path.join(root, f)
                if not os.path.isfile(path):
                    logging.error("Special file in TPM data: %s", path)
                    raise exception.ExternalDataFailed(
                        reason="Cannot write TPM data with non-regular files",
                        path=path
                    )
    # OK, write the data to the target location
    accessor = filedata.DirectoryData(filedata.tpm_path(vm_id))
    accessor.store(tpm_data)