mirror of
https://github.com/pgpainless/pgpainless.git
synced 2025-09-10 18:59:39 +02:00
Rework ASCII armor API
This commit is contained in:
parent
02d72c2691
commit
1b6601cc19
7 changed files with 65 additions and 19 deletions
|
@ -7,7 +7,6 @@ package org.pgpainless.sop
|
|||
import java.io.InputStream
|
||||
import java.io.OutputStream
|
||||
import org.pgpainless.PGPainless
|
||||
import org.pgpainless.util.ArmorUtils
|
||||
import org.pgpainless.util.ArmoredOutputStreamFactory
|
||||
import sop.Ready
|
||||
import sop.operation.ExtractCert
|
||||
|
@ -26,10 +25,8 @@ class ExtractCertImpl(private val api: PGPainless) : ExtractCert {
|
|||
if (certs.size == 1) {
|
||||
val cert = certs[0]
|
||||
// This way we have a nice armor header with fingerprint and user-ids
|
||||
val armorOut =
|
||||
ArmorUtils.toAsciiArmoredStream(cert.pgpKeyRing, outputStream)
|
||||
armorOut.write(cert.encoded)
|
||||
armorOut.close()
|
||||
val armored = cert.toAsciiArmoredString()
|
||||
outputStream.write(armored.toByteArray())
|
||||
} else {
|
||||
// for multiple certs, add no info headers to the ASCII armor
|
||||
val armorOut = ArmoredOutputStreamFactory.get(outputStream)
|
||||
|
|
|
@ -18,7 +18,6 @@ import org.pgpainless.key.generation.type.KeyType
|
|||
import org.pgpainless.key.generation.type.eddsa_legacy.EdDSALegacyCurve
|
||||
import org.pgpainless.key.generation.type.rsa.RsaLength
|
||||
import org.pgpainless.key.generation.type.xdh_legacy.XDHLegacySpec
|
||||
import org.pgpainless.util.ArmorUtils
|
||||
import org.pgpainless.util.Passphrase
|
||||
import sop.Profile
|
||||
import sop.Ready
|
||||
|
@ -50,9 +49,8 @@ class GenerateKeyImpl(private val api: PGPainless) : GenerateKey {
|
|||
return object : Ready() {
|
||||
override fun writeTo(outputStream: OutputStream) {
|
||||
if (armor) {
|
||||
val armorOut = ArmorUtils.toAsciiArmoredStream(key.pgpKeyRing, outputStream)
|
||||
key.pgpKeyRing.encode(armorOut)
|
||||
armorOut.close()
|
||||
val armored = key.toAsciiArmoredString()
|
||||
outputStream.write(armored.toByteArray())
|
||||
} else {
|
||||
key.pgpKeyRing.encode(outputStream)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue