mirror of
https://github.com/pgpainless/pgpainless.git
synced 2025-09-10 18:59:39 +02:00
Refactor CleartextSignatureProcessor to allow reuse in DetachInbandSignatureAndMessage
This commit is contained in:
parent
40dfa6528a
commit
772f69788b
14 changed files with 498 additions and 203 deletions
|
@ -20,6 +20,7 @@ import sop.SOP;
|
|||
import sop.cli.picocli.commands.ArmorCmd;
|
||||
import sop.cli.picocli.commands.DearmorCmd;
|
||||
import sop.cli.picocli.commands.DecryptCmd;
|
||||
import sop.cli.picocli.commands.DetachInbandSignatureAndMessageCmd;
|
||||
import sop.cli.picocli.commands.EncryptCmd;
|
||||
import sop.cli.picocli.commands.ExtractCertCmd;
|
||||
import sop.cli.picocli.commands.GenerateKeyCmd;
|
||||
|
@ -34,6 +35,7 @@ import sop.cli.picocli.commands.VersionCmd;
|
|||
ArmorCmd.class,
|
||||
DearmorCmd.class,
|
||||
DecryptCmd.class,
|
||||
DetachInbandSignatureAndMessageCmd.class,
|
||||
EncryptCmd.class,
|
||||
ExtractCertCmd.class,
|
||||
GenerateKeyCmd.class,
|
||||
|
|
|
@ -1,11 +1,66 @@
|
|||
/*
|
||||
* Copyright 2021 Paul Schaub.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package sop.cli.picocli.commands;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import picocli.CommandLine;
|
||||
import sop.Signatures;
|
||||
import sop.cli.picocli.SopCLI;
|
||||
import sop.exception.SOPGPException;
|
||||
import sop.operation.DetachInbandSignatureAndMessage;
|
||||
|
||||
@CommandLine.Command(name = "detach-inband-signature-and-message",
|
||||
description = "Split a clearsigned message",
|
||||
exitCodeOnInvalidInput = SOPGPException.UnsupportedOption.EXIT_CODE)
|
||||
public class DetachInbandSignatureAndMessageCmd implements Runnable {
|
||||
|
||||
|
||||
@CommandLine.Option(
|
||||
names = {"--signatures-out"},
|
||||
description = "Destination to which a detached signatures block will be written",
|
||||
paramLabel = "SIGNATURES")
|
||||
File signaturesOut;
|
||||
|
||||
@CommandLine.Option(names = "--no-armor",
|
||||
description = "ASCII armor the output",
|
||||
negatable = true)
|
||||
boolean armor = true;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (signaturesOut == null) {
|
||||
throw new SOPGPException.MissingArg("--signatures-out is required.");
|
||||
}
|
||||
|
||||
DetachInbandSignatureAndMessage detach = SopCLI.getSop().detachInbandSignatureAndMessage();
|
||||
if (!armor) {
|
||||
detach.noArmor();
|
||||
}
|
||||
|
||||
try {
|
||||
Signatures signatures = detach
|
||||
.message(System.in).writeTo(System.out);
|
||||
if (!signaturesOut.createNewFile()) {
|
||||
throw new SOPGPException.OutputExists("Destination of --signatures-out already exists.");
|
||||
}
|
||||
signatures.writeTo(new FileOutputStream(signaturesOut));
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue