mirror of
https://github.com/pgpainless/pgpainless.git
synced 2025-09-10 18:59:39 +02:00
Wip: Remove allowNested, add FileUtil
This commit is contained in:
parent
772f69788b
commit
4e83281213
9 changed files with 129 additions and 132 deletions
|
@ -18,9 +18,6 @@ package org.pgpainless.sop;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.PushbackInputStream;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.bouncycastle.bcpg.ArmoredOutputStream;
|
||||
import org.bouncycastle.util.io.Streams;
|
||||
|
@ -32,37 +29,19 @@ import sop.operation.Armor;
|
|||
|
||||
public class ArmorImpl implements Armor {
|
||||
|
||||
public static final byte[] ARMOR_START = "-----BEGIN PGP".getBytes(Charset.forName("UTF8"));
|
||||
|
||||
boolean allowNested = false;
|
||||
|
||||
@Override
|
||||
public Armor label(ArmorLabel label) throws SOPGPException.UnsupportedOption {
|
||||
throw new SOPGPException.UnsupportedOption("Setting custom Armor labels not supported.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Armor allowNested() throws SOPGPException.UnsupportedOption {
|
||||
allowNested = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Ready data(InputStream data) throws SOPGPException.BadData {
|
||||
return new Ready() {
|
||||
@Override
|
||||
public void writeTo(OutputStream outputStream) throws IOException {
|
||||
PushbackInputStream pbIn = new PushbackInputStream(data, ARMOR_START.length);
|
||||
byte[] buffer = new byte[ARMOR_START.length];
|
||||
int read = pbIn.read(buffer);
|
||||
pbIn.unread(buffer, 0, read);
|
||||
if (!allowNested && Arrays.equals(ARMOR_START, buffer)) {
|
||||
Streams.pipeAll(pbIn, System.out);
|
||||
} else {
|
||||
ArmoredOutputStream armor = ArmoredOutputStreamFactory.get(System.out);
|
||||
Streams.pipeAll(pbIn, armor);
|
||||
armor.close();
|
||||
}
|
||||
ArmoredOutputStream armor = ArmoredOutputStreamFactory.get(System.out);
|
||||
Streams.pipeAll(data, armor);
|
||||
armor.close();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -45,8 +45,7 @@ public class SignImpl implements Sign {
|
|||
|
||||
private boolean armor = true;
|
||||
private SignAs mode = SignAs.Binary;
|
||||
private List<PGPSecretKeyRing> keys = new ArrayList<>();
|
||||
private SigningOptions signingOptions = new SigningOptions();
|
||||
private final SigningOptions signingOptions = new SigningOptions();
|
||||
|
||||
@Override
|
||||
public Sign noArmor() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue