1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-11-23 04:42:06 +01:00

SOP: Respect signature type

This commit is contained in:
Paul Schaub 2020-12-16 16:43:58 +01:00
parent 6f48a1a261
commit e07998f99d

View file

@ -10,6 +10,7 @@ import org.bouncycastle.openpgp.PGPSecretKeyRing;
import org.bouncycastle.openpgp.PGPSignature; import org.bouncycastle.openpgp.PGPSignature;
import org.bouncycastle.util.io.Streams; import org.bouncycastle.util.io.Streams;
import org.pgpainless.PGPainless; import org.pgpainless.PGPainless;
import org.pgpainless.encryption_signing.EncryptionBuilderInterface;
import org.pgpainless.encryption_signing.EncryptionStream; import org.pgpainless.encryption_signing.EncryptionStream;
import org.pgpainless.key.protection.UnprotectedKeysProtector; import org.pgpainless.key.protection.UnprotectedKeysProtector;
import org.pgpainless.sop.Print; import org.pgpainless.sop.Print;
@ -49,12 +50,14 @@ public class Sign implements Runnable {
} }
try { try {
ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayOutputStream out = new ByteArrayOutputStream();
EncryptionStream encryptionStream = PGPainless.createEncryptor() EncryptionBuilderInterface.DocumentType documentType = PGPainless.encryptAndOrSign()
.onOutputStream(out) .onOutputStream(out)
.doNotEncrypt() .doNotEncrypt()
.createDetachedSignature() .createDetachedSignature()
.signWith(new UnprotectedKeysProtector(), secretKeys) .signWith(new UnprotectedKeysProtector(), secretKeys);
.noArmor();
EncryptionBuilderInterface.Armor armor = type == Type.text ? documentType.signCanonicalText() : documentType.signBinaryDocument();
EncryptionStream encryptionStream = noArmor ? armor.noArmor() : armor.asciiArmor();
Streams.pipeAll(System.in, encryptionStream); Streams.pipeAll(System.in, encryptionStream);
encryptionStream.close(); encryptionStream.close();