2021-10-07 15:48:52 +02:00
|
|
|
// SPDX-FileCopyrightText: 2021 Paul Schaub <vanitasvitae@fsfe.org>
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
2021-07-15 16:55:13 +02:00
|
|
|
package org.pgpainless.sop;
|
|
|
|
|
2022-06-15 23:14:09 +02:00
|
|
|
import java.io.BufferedOutputStream;
|
2021-07-15 16:55:13 +02:00
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.InputStream;
|
|
|
|
import java.io.OutputStream;
|
|
|
|
|
|
|
|
import org.bouncycastle.openpgp.PGPUtil;
|
2021-07-31 20:40:31 +02:00
|
|
|
import org.bouncycastle.util.io.Streams;
|
2021-07-15 16:55:13 +02:00
|
|
|
import sop.Ready;
|
2022-06-10 17:43:51 +02:00
|
|
|
import sop.exception.SOPGPException;
|
2021-07-15 16:55:13 +02:00
|
|
|
import sop.operation.Dearmor;
|
|
|
|
|
2023-01-16 19:38:52 +01:00
|
|
|
/**
|
|
|
|
* Implementation of the <pre>dearmor</pre> operation using PGPainless.
|
|
|
|
*/
|
2021-07-15 16:55:13 +02:00
|
|
|
public class DearmorImpl implements Dearmor {
|
|
|
|
|
|
|
|
@Override
|
2022-09-29 13:02:22 +02:00
|
|
|
public Ready data(InputStream data) {
|
2022-06-10 17:43:51 +02:00
|
|
|
InputStream decoder;
|
|
|
|
try {
|
|
|
|
decoder = PGPUtil.getDecoderStream(data);
|
|
|
|
} catch (IOException e) {
|
|
|
|
throw new SOPGPException.BadData(e);
|
|
|
|
}
|
2021-07-15 16:55:13 +02:00
|
|
|
return new Ready() {
|
2021-09-02 18:01:06 +02:00
|
|
|
|
2021-07-15 16:55:13 +02:00
|
|
|
@Override
|
|
|
|
public void writeTo(OutputStream outputStream) throws IOException {
|
2022-06-15 23:14:09 +02:00
|
|
|
BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(outputStream);
|
|
|
|
Streams.pipeAll(decoder, bufferedOutputStream);
|
|
|
|
bufferedOutputStream.flush();
|
2021-07-15 16:55:13 +02:00
|
|
|
decoder.close();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|