Skip to content

Commit 2331f93

Browse files
committed
rotate: Fix additional newline before version comment field
1 parent 01305cf commit 2331f93

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

cmd/rotate.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cmd
22

33
import (
4+
"bytes"
45
"crypto/ed25519"
56
"crypto/rand"
67
"encoding/pem"
@@ -107,7 +108,10 @@ func generateKey(fn string) error {
107108
return fmt.Errorf("could not create SSH public key: %w", err)
108109
}
109110
ver := filepath.Base(fn)
110-
if err := os.WriteFile(fn+".pub", []byte(fmt.Sprintf("%s %s\n", ssh.MarshalAuthorizedKey(sshPub), ver)), 0o444); err != nil {
111+
key := ssh.MarshalAuthorizedKey(sshPub)
112+
key = bytes.TrimSuffix(key, []byte("\n"))
113+
key = append(key, []byte(fmt.Sprintf(" %s\n", ver))...)
114+
if err := os.WriteFile(fn+".pub", key, 0o444); err != nil {
111115
return fmt.Errorf("could not write public key file %q: %w", fn+".pub", err)
112116
}
113117
return nil

0 commit comments

Comments
 (0)