mirror of
https://codeberg.org/PGPainless/sop-java.git
synced 2024-11-26 00:52:07 +01:00
Add implementation of merge-certs command
This commit is contained in:
parent
a2315f9847
commit
ddf4ba19f9
6 changed files with 116 additions and 0 deletions
|
@ -28,6 +28,7 @@ import sop.exception.SOPGPException
|
||||||
RevokeKeyCmd::class,
|
RevokeKeyCmd::class,
|
||||||
ExtractCertCmd::class,
|
ExtractCertCmd::class,
|
||||||
UpdateKeyCmd::class,
|
UpdateKeyCmd::class,
|
||||||
|
MergeCertsCmd::class,
|
||||||
// Messaging subcommands
|
// Messaging subcommands
|
||||||
SignCmd::class,
|
SignCmd::class,
|
||||||
VerifyCmd::class,
|
VerifyCmd::class,
|
||||||
|
|
|
@ -0,0 +1,48 @@
|
||||||
|
// SPDX-FileCopyrightText: 2024 Paul Schaub <vanitasvitae@fsfe.org>
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
package sop.cli.picocli.commands
|
||||||
|
|
||||||
|
import picocli.CommandLine
|
||||||
|
import picocli.CommandLine.Command
|
||||||
|
import sop.cli.picocli.SopCLI
|
||||||
|
import sop.exception.SOPGPException
|
||||||
|
import java.io.IOException
|
||||||
|
|
||||||
|
@Command(
|
||||||
|
name = "merge-certs",
|
||||||
|
resourceBundle = "msg_merge-certs",
|
||||||
|
exitCodeOnInvalidInput = SOPGPException.UnsupportedOption.EXIT_CODE)
|
||||||
|
class MergeCertsCmd : AbstractSopCmd() {
|
||||||
|
|
||||||
|
@CommandLine.Option(names = ["--no-armor"], negatable = true)
|
||||||
|
var armor = false
|
||||||
|
|
||||||
|
@CommandLine.Parameters(paramLabel = "CERTS")
|
||||||
|
var updates: List<String> = listOf()
|
||||||
|
|
||||||
|
override fun run() {
|
||||||
|
val mergeCerts = throwIfUnsupportedSubcommand(SopCLI.getSop().mergeCerts(), "merge-certs")
|
||||||
|
|
||||||
|
if (!armor) {
|
||||||
|
mergeCerts.noArmor()
|
||||||
|
}
|
||||||
|
|
||||||
|
for (certFileName in updates) {
|
||||||
|
try {
|
||||||
|
getInput(certFileName).use { mergeCerts.updates(it) }
|
||||||
|
} catch (e: IOException) {
|
||||||
|
throw RuntimeException(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
val ready = mergeCerts.baseCertificates(System.`in`)
|
||||||
|
ready.writeTo(System.out)
|
||||||
|
} catch (e: IOException) {
|
||||||
|
throw RuntimeException(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
# SPDX-FileCopyrightText: 2024 Paul Schaub <vanitasvitae@fsfe.org>
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
usage.headerHeading=Merge OpenPGP certificates%n
|
||||||
|
usage.description=BLABLA
|
||||||
|
no-armor=ASCII armor the output
|
||||||
|
CERTS[0..*]=OpenPGP certificates from which updates shall be merged into the base certificates from standard input
|
||||||
|
|
||||||
|
stacktrace=Print stacktrace
|
||||||
|
# Generic TODO: Remove when bumping picocli to 4.7.0
|
||||||
|
usage.parameterListHeading=%nParameters:%n
|
||||||
|
usage.synopsisHeading=Usage:\u0020
|
||||||
|
usage.commandListHeading = %nCommands:%n
|
||||||
|
usage.optionListHeading = %nOptions:%n
|
||||||
|
usage.footerHeading=Powered by picocli%n
|
|
@ -0,0 +1,19 @@
|
||||||
|
# SPDX-FileCopyrightText: 2024 Paul Schaub <vanitasvitae@fsfe.org>
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
usage.headerHeading=OpenPGP Zertifikate zusammenführen%n%n
|
||||||
|
usage.header=Führe OpenPGP Zertifikate aus der Standardeingabe mit ensprechenden Elementen aus CERTS zusammen und gebe das Ergebnis auf der Standardausgabe aus
|
||||||
|
usage.description=Es werden nur Zertifikate auf die Standardausgabe geschrieben, welche Teil der Standardeingabe waren
|
||||||
|
no-armor=Schütze Ausgabe mit ASCII Armor
|
||||||
|
CERTS[0..*]=OpenPGP Zertifikate aus denen neue Elemente in die Basiszertifikate aus der Standardeingabe übernommen werden sollen
|
||||||
|
|
||||||
|
usage.parameterList.0=STANDARDIN
|
||||||
|
usage.parameterList.1=STANDARDOUT
|
||||||
|
|
||||||
|
# Generic TODO: Remove when bumping picocli to 4.7.0
|
||||||
|
usage.parameterListHeading=%nParameter:%n
|
||||||
|
usage.synopsisHeading=Aufruf:\u0020
|
||||||
|
usage.descriptionHeading=%nHinweise:%n
|
||||||
|
usage.commandListHeading=%nBefehle:%n
|
||||||
|
usage.optionListHeading = %nOptionen:%n
|
||||||
|
usage.footerHeading=Powered by Picocli%n
|
|
@ -64,4 +64,9 @@ interface SOP : SOPV {
|
||||||
* Keep a secret key up-to-date.
|
* Keep a secret key up-to-date.
|
||||||
*/
|
*/
|
||||||
fun updateKey(): UpdateKey
|
fun updateKey(): UpdateKey
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Merge OpenPGP certificates.
|
||||||
|
*/
|
||||||
|
fun mergeCerts(): MergeCerts
|
||||||
}
|
}
|
||||||
|
|
28
sop-java/src/main/kotlin/sop/operation/MergeCerts.kt
Normal file
28
sop-java/src/main/kotlin/sop/operation/MergeCerts.kt
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
// SPDX-FileCopyrightText: 2024 Paul Schaub <vanitasvitae@fsfe.org>
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
package sop.operation
|
||||||
|
|
||||||
|
import sop.Ready
|
||||||
|
import sop.exception.SOPGPException
|
||||||
|
import java.io.IOException
|
||||||
|
import java.io.InputStream
|
||||||
|
|
||||||
|
interface MergeCerts {
|
||||||
|
|
||||||
|
@Throws(SOPGPException.UnsupportedOption::class)
|
||||||
|
fun noArmor(): MergeCerts
|
||||||
|
|
||||||
|
@Throws(SOPGPException.BadData::class, IOException::class)
|
||||||
|
fun updates(updateCerts: InputStream): MergeCerts
|
||||||
|
|
||||||
|
@Throws(SOPGPException.BadData::class, IOException::class)
|
||||||
|
fun updates(updateCerts: ByteArray): MergeCerts = updates(updateCerts.inputStream())
|
||||||
|
|
||||||
|
@Throws(SOPGPException.BadData::class, IOException::class)
|
||||||
|
fun baseCertificates(certs: InputStream): Ready
|
||||||
|
|
||||||
|
@Throws(SOPGPException.BadData::class, IOException::class)
|
||||||
|
fun baseCertificates(certs: ByteArray): Ready = baseCertificates(certs.inputStream())
|
||||||
|
}
|
Loading…
Reference in a new issue