From 1a6ce0989a35a914784ac30975f0c1fbb05d49a8 Mon Sep 17 00:00:00 2001
From: Kevin Lyda <kevin@ie.suberic.net>
Date: Wed, 25 Jan 2017 09:11:38 +0000
Subject: [PATCH] Clean up public file writing.

Public key and cert writing now moved into client.
---
 client/client.go    | 8 ++++++++
 cmd/cashier/main.go | 7 +++----
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/client/client.go b/client/client.go
index 382c53dc..78e37029 100644
--- a/client/client.go
+++ b/client/client.go
@@ -16,6 +16,14 @@ import (
 	"golang.org/x/crypto/ssh/agent"
 )
 
+// InstallPublicFiles installs the public part of the cert and key.
+func InstallPublicFiles(c Config, cert *ssh.Certificate, pub PublicKey) error {
+	ioutil.WriteFile(client.ExpandTilde(c.PublicKey),
+		ssh.MarshalAuthorizedKey(pub), 0644)
+	ioutil.WriteFile(client.ExpandTilde(c.PublicCert),
+		[]byte(cert.Type()+" "+base64.StdEncoding.EncodeToString(cert.Marshal())), 0644)
+}
+
 // InstallCert adds the private key and signed certificate to the ssh agent.
 func InstallCert(a agent.Agent, cert *ssh.Certificate, key Key) error {
 	t := time.Unix(int64(cert.ValidBefore), 0)
diff --git a/cmd/cashier/main.go b/cmd/cashier/main.go
index 5e3484d9..2e819531 100644
--- a/cmd/cashier/main.go
+++ b/cmd/cashier/main.go
@@ -63,9 +63,8 @@ func main() {
 	if err := client.InstallCert(a, cert, priv); err != nil {
 		log.Fatalln(err)
 	}
-	ioutil.WriteFile(client.ExpandTilde(c.PublicKey),
-		ssh.MarshalAuthorizedKey(pub), 0644)
-	ioutil.WriteFile(client.ExpandTilde(c.PublicCert),
-		[]byte(cert.Type()+" "+base64.StdEncoding.EncodeToString(cert.Marshal())), 0644)
+	if err := client.InstallPublicFilis(c, cert, pub); err != nil {
+		log.Fatalln(err)
+	}
 	fmt.Println("Credentials added.")
 }
-- 
GitLab