#
#   Copyright (C) 2023 SUSE LLC
#
#   This program is free software; you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation; either version 2 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program; if not, write to the Free Software
#   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
#   Written by Gary Lin <glin@suse.com>

. $SHAREDIR/commands/tpm-disable

alias cmd_requires_luks_device=true
alias cmd_perform=cmd_tpm_wipe

function cmd_tpm_wipe {

    local luks_devices="$1"

    if ! tpm_disable "${luks_devices}"; then
	return 1
    fi

    for luks_dev in ${luks_devices}; do
	if ! bootloader_wipe "${luks_dev}"; then
	display_errorbox "Failed to wipe out key slots ${luks_dev}"
	return 1
    fi
    done

    return 0
}
