1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2025-12-10 06:11:08 +01:00

Use ArmoredOutputStreamFactory to hide version string in ascii armor

Partially fixes #82
This commit is contained in:
Paul Schaub 2021-02-19 19:50:36 +01:00
parent ea89289852
commit c75a192513
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
9 changed files with 51 additions and 10 deletions

View file

@ -51,6 +51,7 @@ import org.pgpainless.decryption_verification.DetachedSignature;
import org.pgpainless.decryption_verification.OpenPgpMetadata;
import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.key.OpenPgpV4Fingerprint;
import org.pgpainless.util.ArmoredOutputStreamFactory;
import org.pgpainless.util.Passphrase;
/**
@ -146,7 +147,7 @@ public final class EncryptionStream extends OutputStream {
}
LOGGER.log(LEVEL, "Wrap encryption output in ASCII armor");
armorOutputStream = new ArmoredOutputStream(outermostStream);
armorOutputStream = ArmoredOutputStreamFactory.get(outermostStream);
outermostStream = armorOutputStream;
}

View file

@ -41,7 +41,7 @@ public class ArmorUtils {
public static String toAsciiArmoredString(InputStream inputStream) throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
ArmoredOutputStream armor = new ArmoredOutputStream(out);
ArmoredOutputStream armor = ArmoredOutputStreamFactory.get(out);
Streams.pipeAll(inputStream, armor);
armor.close();

View file

@ -0,0 +1,34 @@
/*
* 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 org.pgpainless.util;
import java.io.OutputStream;
import org.bouncycastle.bcpg.ArmoredOutputStream;
/**
* Factory to create configured {@link ArmoredOutputStream ArmoredOutputStreams}.
*/
public class ArmoredOutputStreamFactory {
public static final String VERSION = "PGPainless";
public static ArmoredOutputStream get(OutputStream outputStream) {
ArmoredOutputStream armoredOutputStream = new ArmoredOutputStream(outputStream);
armoredOutputStream.setHeader(ArmoredOutputStream.VERSION_HDR, VERSION);
return armoredOutputStream;
}
}