From f3128143fa915f7961629873ced5c2d8cfb5b012 Mon Sep 17 00:00:00 2001 From: Stephen Fox Date: Mon, 4 Feb 2019 14:27:59 -0500 Subject: [PATCH] Simplified building of authorized_keys public key. --- helper/ssh/key_pair.go | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/helper/ssh/key_pair.go b/helper/ssh/key_pair.go index cd7a2f4a8..600f258e4 100644 --- a/helper/ssh/key_pair.go +++ b/helper/ssh/key_pair.go @@ -270,28 +270,23 @@ func (o defaultKeyPair) PrivateKeyPemBlock() []byte { func (o defaultKeyPair) PublicKeyAuthorizedKeysLine(nl NewLineOption) []byte { result := gossh.MarshalAuthorizedKey(o.publicKey) + // Remove the mandatory unix new line. + // Awful, but the go ssh library automatically appends + // a unix new line. + result = bytes.TrimSuffix(result, UnixNewLine.Bytes()) + if len(strings.TrimSpace(o.name)) > 0 { - // Awful, but the go ssh library automatically appends - // a unix new line. - result = bytes.TrimSuffix(result, UnixNewLine.Bytes()) result = append(result, ' ') result = append(result, o.name...) } switch nl { - case NoNewLine: - result = bytes.TrimSuffix(result, UnixNewLine.Bytes()) case WindowsNewLine: - result = bytes.TrimSuffix(result, UnixNewLine.Bytes()) result = append(result, nl.Bytes()...) case UnixNewLine: - fallthrough - default: // This is how all the other "SSH key pair" code works in // the different builders. - if !bytes.HasSuffix(result, UnixNewLine.Bytes()) { - result = append(result, UnixNewLine.Bytes()...) - } + result = append(result, UnixNewLine.Bytes()...) } return result