1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2025-01-09 19:57:57 +01:00

De-duplicate KeyPrinter class

This commit is contained in:
Paul Schaub 2020-11-18 12:20:59 +01:00
parent 4dd2b2f71a
commit 9f95e7925b

View file

@ -18,6 +18,7 @@ package org.pgpainless.util;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import org.bouncycastle.bcpg.ArmoredOutputStream; import org.bouncycastle.bcpg.ArmoredOutputStream;
import org.bouncycastle.openpgp.PGPPublicKeyRing; import org.bouncycastle.openpgp.PGPPublicKeyRing;
@ -27,20 +28,22 @@ import org.bouncycastle.util.io.Streams;
public class KeyPrinter { public class KeyPrinter {
public static String toAsciiArmoredString(PGPSecretKeyRing secretKeys) throws IOException { public static String toAsciiArmoredString(PGPSecretKeyRing secretKeys) throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream(); return toAsciiArmoredString(secretKeys.getEncoded());
ArmoredOutputStream armor = new ArmoredOutputStream(out);
Streams.pipeAll(new ByteArrayInputStream(secretKeys.getEncoded()), armor);
armor.close();
return out.toString();
} }
public static String toAsciiArmoredString(PGPPublicKeyRing publicKeys) throws IOException { public static String toAsciiArmoredString(PGPPublicKeyRing publicKeys) throws IOException {
return toAsciiArmoredString(publicKeys.getEncoded());
}
public static String toAsciiArmoredString(byte[] bytes) throws IOException {
return toAsciiArmoredString(new ByteArrayInputStream(bytes));
}
public static String toAsciiArmoredString(InputStream inputStream) throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayOutputStream out = new ByteArrayOutputStream();
ArmoredOutputStream armor = new ArmoredOutputStream(out); ArmoredOutputStream armor = new ArmoredOutputStream(out);
Streams.pipeAll(new ByteArrayInputStream(publicKeys.getEncoded()), armor); Streams.pipeAll(inputStream, armor);
armor.close(); armor.close();
return out.toString(); return out.toString();