Fix idempotent ASCII armor operations

This commit is contained in:
Paul Schaub 2025-07-25 14:27:16 +02:00
parent 43fdac4ac5
commit 1e6782166f
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
2 changed files with 8 additions and 5 deletions

View file

@ -1,6 +1,8 @@
package org.pgpainless.bouncycastle.sop.operation; package org.pgpainless.bouncycastle.sop.operation;
import org.bouncycastle.bcpg.ArmoredInputStream;
import org.bouncycastle.bcpg.ArmoredOutputStream; import org.bouncycastle.bcpg.ArmoredOutputStream;
import org.bouncycastle.openpgp.PGPUtil;
import org.bouncycastle.openpgp.api.OpenPGPApi; import org.bouncycastle.openpgp.api.OpenPGPApi;
import org.bouncycastle.util.io.Streams; import org.bouncycastle.util.io.Streams;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -26,10 +28,11 @@ public class BCArmor
return new Ready() { return new Ready() {
@Override @Override
public void writeTo(@NotNull OutputStream outputStream) throws IOException { public void writeTo(@NotNull OutputStream outputStream) throws IOException {
InputStream decodeIn = PGPUtil.getDecoderStream(inputStream);
ArmoredOutputStream aOut = ArmoredOutputStream.builder() ArmoredOutputStream aOut = ArmoredOutputStream.builder()
.clearHeaders() .clearHeaders()
.build(outputStream); .build(outputStream);
Streams.pipeAll(inputStream, aOut); Streams.pipeAll(decodeIn, aOut);
aOut.close(); aOut.close();
} }
}; };

View file

@ -1,6 +1,6 @@
package org.pgpainless.bouncycastle.sop.operation; package org.pgpainless.bouncycastle.sop.operation;
import org.bouncycastle.bcpg.ArmoredInputStream; import org.bouncycastle.openpgp.PGPUtil;
import org.bouncycastle.openpgp.api.OpenPGPApi; import org.bouncycastle.openpgp.api.OpenPGPApi;
import org.bouncycastle.util.io.Streams; import org.bouncycastle.util.io.Streams;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -26,9 +26,9 @@ public class BCDearmor
return new Ready() { return new Ready() {
@Override @Override
public void writeTo(@NotNull OutputStream outputStream) throws IOException { public void writeTo(@NotNull OutputStream outputStream) throws IOException {
ArmoredInputStream aIn = new ArmoredInputStream(inputStream); InputStream decodeIn = PGPUtil.getDecoderStream(inputStream);
Streams.pipeAll(aIn, outputStream); Streams.pipeAll(decodeIn, outputStream);
aIn.close(); decodeIn.close();
} }
}; };
} }