All Downloads are FREE. Search and download functionalities are using the official Maven repository.

sop.cli.picocli.commands.RevokeKeyCmd.kt Maven / Gradle / Ivy

There is a newer version: 10.0.3
Show newest version
// SPDX-FileCopyrightText: 2023 Paul Schaub 
//
// SPDX-License-Identifier: Apache-2.0

package sop.cli.picocli.commands

import java.io.IOException
import picocli.CommandLine.Command
import picocli.CommandLine.Option
import sop.cli.picocli.SopCLI
import sop.exception.SOPGPException
import sop.exception.SOPGPException.KeyIsProtected

@Command(
    name = "revoke-key",
    resourceBundle = "msg_revoke-key",
    exitCodeOnInvalidInput = SOPGPException.UnsupportedOption.EXIT_CODE)
class RevokeKeyCmd : AbstractSopCmd() {

    @Option(names = ["--no-armor"], negatable = true) var armor = true

    @Option(names = ["--with-key-password"], paramLabel = "PASSWORD")
    var withKeyPassword: String? = null

    override fun run() {
        val revokeKey = throwIfUnsupportedSubcommand(SopCLI.getSop().revokeKey(), "revoke-key")

        if (!armor) {
            revokeKey.noArmor()
        }

        withKeyPassword?.let {
            try {
                val password = stringFromInputStream(getInput(it))
                revokeKey.withKeyPassword(password)
            } catch (e: SOPGPException.UnsupportedOption) {
                val errorMsg =
                    getMsg("sop.error.feature_support.option_not_supported", "--with-key-password")
                throw SOPGPException.UnsupportedOption(errorMsg, e)
            } catch (e: IOException) {
                throw RuntimeException(e)
            }
        }

        val ready =
            try {
                revokeKey.keys(System.`in`)
            } catch (e: KeyIsProtected) {
                val errorMsg = getMsg("sop.error.runtime.cannot_unlock_key", "STANDARD_IN")
                throw KeyIsProtected(errorMsg, e)
            }
        try {
            ready.writeTo(System.out)
        } catch (e: IOException) {
            throw RuntimeException(e)
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy