diff options
author | Niall Sheridan <nsheridan@gmail.com> | 2017-01-05 23:28:26 +0000 |
---|---|---|
committer | Niall Sheridan <nsheridan@gmail.com> | 2017-01-05 23:28:26 +0000 |
commit | 9e9a7d50970f1424245d88169de82988fd57e112 (patch) | |
tree | 25aca2f5e18fe3ff454af34d5d75f8c5204d81fb /lib | |
parent | 8066efd45861e7c024fc1daabc6d002266a527e7 (diff) |
Move GetPublicKey to the shared `lib` package
Diffstat (limited to 'lib')
-rw-r--r-- | lib/proto.go (renamed from lib/const.go) | 6 | ||||
-rw-r--r-- | lib/util.go | 10 | ||||
-rw-r--r-- | lib/util_test.go | 16 |
3 files changed, 28 insertions, 4 deletions
diff --git a/lib/const.go b/lib/proto.go index 1ba2749..f3d7115 100644 --- a/lib/const.go +++ b/lib/proto.go @@ -9,9 +9,7 @@ type SignRequest struct { } // SignResponse is sent by the server. -// `Status' is "ok" or "error". -// `Response' contains a signed certificate or an error message. type SignResponse struct { - Status string `json:"status"` - Response string `json:"response"` + Status string `json:"status"` // Status will be "ok" or "error". + Response string `json:"response"` // Response will contain either the signed certificate or the error message. } diff --git a/lib/util.go b/lib/util.go new file mode 100644 index 0000000..b1c7b87 --- /dev/null +++ b/lib/util.go @@ -0,0 +1,10 @@ +package lib + +import "golang.org/x/crypto/ssh" + +// GetPublicKey marshals a ssh certificate to a string. +func GetPublicKey(pub ssh.PublicKey) string { + marshaled := ssh.MarshalAuthorizedKey(pub) + // Strip trailing newline + return string(marshaled[:len(marshaled)-1]) +} diff --git a/lib/util_test.go b/lib/util_test.go new file mode 100644 index 0000000..9e89297 --- /dev/null +++ b/lib/util_test.go @@ -0,0 +1,16 @@ +package lib + +import ( + "testing" + + "github.com/nsheridan/cashier/testdata" + "golang.org/x/crypto/ssh" +) + +func TestGetPublicKey(t *testing.T) { + t.Parallel() + c, _, _, _, _ := ssh.ParseAuthorizedKey(testdata.Cert) + if GetPublicKey(c.(*ssh.Certificate)) != string(testdata.Cert) { + t.Fail() + } +} |