From dfedaea239a6b3a06a9b2e9c0618791b1125d91f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Mon, 13 Jul 2020 06:23:16 +0100 Subject: [PATCH] avoid partial writes with ascii armor Sill not perfect because it still prints the header --- pkgs/ssh-to-pgp/main.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pkgs/ssh-to-pgp/main.go b/pkgs/ssh-to-pgp/main.go index f046c8f..f8f926b 100644 --- a/pkgs/ssh-to-pgp/main.go +++ b/pkgs/ssh-to-pgp/main.go @@ -85,7 +85,6 @@ func convertKeys(args []string) error { if err != nil { return fmt.Errorf("failed to encode armor writer") } - defer writer.Close() } if opts.publicKey != "" { @@ -93,13 +92,16 @@ func convertKeys(args []string) error { if err != nil { return err } - gpgKey.Serialize(writer) + err = gpgKey.Serialize(writer) } else { gpgKey, err := sshkeys.SSHPrivateKeyToPGP(sshKey) if err != nil { return err } - gpgKey.SerializePrivate(writer, nil) + err = gpgKey.SerializePrivate(writer, nil) + } + if err == nil && opts.format == "armor" { + writer.Close() } return err }