mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-11-22 20:32:05 +01:00
Improvements to SOP
This commit is contained in:
parent
3cd64b61ca
commit
83917f320f
5 changed files with 28 additions and 6 deletions
|
@ -17,10 +17,29 @@ package org.pgpainless.sop;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.bouncycastle.openpgp.PGPKeyRing;
|
||||
import org.bouncycastle.openpgp.PGPPublicKeyRing;
|
||||
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
||||
import org.pgpainless.util.ArmorUtils;
|
||||
|
||||
public class Print {
|
||||
|
||||
public static String toString(PGPSecretKeyRing keyRing, boolean armor) throws IOException {
|
||||
if (armor) {
|
||||
return ArmorUtils.toAsciiArmoredString(keyRing);
|
||||
} else {
|
||||
return new String(keyRing.getEncoded(), "UTF-8");
|
||||
}
|
||||
}
|
||||
|
||||
public static String toString(PGPPublicKeyRing keyRing, boolean armor) throws IOException {
|
||||
if (armor) {
|
||||
return ArmorUtils.toAsciiArmoredString(keyRing);
|
||||
} else {
|
||||
return new String(keyRing.getEncoded(), "UTF-8");
|
||||
}
|
||||
}
|
||||
|
||||
public static String toString(byte[] bytes, boolean armor) throws IOException {
|
||||
if (armor) {
|
||||
return ArmorUtils.toAsciiArmoredString(bytes);
|
||||
|
|
|
@ -51,7 +51,8 @@ public class Armor implements Runnable {
|
|||
@Override
|
||||
public void run() {
|
||||
|
||||
try (PushbackInputStream pbIn = new PushbackInputStream(System.in); ArmoredOutputStream armoredOutputStream = ArmoredOutputStreamFactory.get(System.out)) {
|
||||
try (PushbackInputStream pbIn = new PushbackInputStream(System.in);
|
||||
ArmoredOutputStream armoredOutputStream = ArmoredOutputStreamFactory.get(System.out)) {
|
||||
byte[] start = new byte[14];
|
||||
int read = pbIn.read(start);
|
||||
pbIn.unread(read);
|
||||
|
|
|
@ -105,9 +105,7 @@ public class Encrypt implements Runnable {
|
|||
for (int i = 0; i < signWith.length; i++) {
|
||||
try (FileInputStream fileIn = new FileInputStream(signWith[i])) {
|
||||
PGPSecretKeyRing secretKey = PGPainless.readKeyRing().secretKeyRing(fileIn);
|
||||
signOpt.addInlineSignature(protector, secretKey,
|
||||
type == Type.text || type == Type.mime ?
|
||||
DocumentSignatureType.CANONICAL_TEXT_DOCUMENT : DocumentSignatureType.BINARY_DOCUMENT);
|
||||
signOpt.addInlineSignature(protector, secretKey, parseType(type));
|
||||
} catch (IOException | PGPException e) {
|
||||
err_ln("Cannot read secret key from file " + signWith[i].getName());
|
||||
err_ln(e.getMessage());
|
||||
|
@ -131,4 +129,8 @@ public class Encrypt implements Runnable {
|
|||
System.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
private static DocumentSignatureType parseType(Type type) {
|
||||
return type == Type.binary ? DocumentSignatureType.BINARY_DOCUMENT : DocumentSignatureType.CANONICAL_TEXT_DOCUMENT;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ public class ExtractCert implements Runnable {
|
|||
PGPSecretKeyRing secretKeys = PGPainless.readKeyRing().secretKeyRing(System.in);
|
||||
PGPPublicKeyRing publicKeys = KeyRingUtils.publicKeyRingFrom(secretKeys);
|
||||
|
||||
print_ln(Print.toString(publicKeys.getEncoded(), armor));
|
||||
print_ln(Print.toString(publicKeys, armor));
|
||||
} catch (IOException | PGPException e) {
|
||||
err_ln("Error extracting certificate from keys;");
|
||||
err_ln(e.getMessage());
|
||||
|
|
|
@ -84,7 +84,7 @@ public class GenerateKey implements Runnable {
|
|||
.withoutPassphrase()
|
||||
.build();
|
||||
|
||||
print_ln(Print.toString(secretKeys.getEncoded(), armor));
|
||||
print_ln(Print.toString(secretKeys, armor));
|
||||
|
||||
} catch (InvalidAlgorithmParameterException | NoSuchAlgorithmException | PGPException | IOException e) {
|
||||
err_ln("Error creating OpenPGP key:");
|
||||
|
|
Loading…
Reference in a new issue