diff options
author | Niall Sheridan <nsheridan@gmail.com> | 2016-06-19 23:44:25 +0100 |
---|---|---|
committer | Niall Sheridan <nsheridan@gmail.com> | 2016-07-03 18:01:24 +0100 |
commit | dee5a19d36554a8f9a365efd65d13b134889bf63 (patch) | |
tree | 41103a2d3665d604fe22dcd16d110ed56c466f6d /server/certutil | |
parent | 6e7dfa0df6b102219817e26095f2ba636cd9288c (diff) |
first pass at a certificate store
Diffstat (limited to 'server/certutil')
-rw-r--r-- | server/certutil/util.go | 10 | ||||
-rw-r--r-- | server/certutil/util_test.go | 15 |
2 files changed, 25 insertions, 0 deletions
diff --git a/server/certutil/util.go b/server/certutil/util.go new file mode 100644 index 0000000..eb1900b --- /dev/null +++ b/server/certutil/util.go @@ -0,0 +1,10 @@ +package certutil + +import "golang.org/x/crypto/ssh" + +// GetPublicKey marshals a ssh certificate to a string. +func GetPublicKey(cert *ssh.Certificate) string { + marshaled := ssh.MarshalAuthorizedKey(cert) + // Strip trailing newline + return string(marshaled[:len(marshaled)-1]) +} diff --git a/server/certutil/util_test.go b/server/certutil/util_test.go new file mode 100644 index 0000000..abb8f10 --- /dev/null +++ b/server/certutil/util_test.go @@ -0,0 +1,15 @@ +package certutil + +import ( + "testing" + + "github.com/nsheridan/cashier/testdata" + "golang.org/x/crypto/ssh" +) + +func TestGetPublicKey(t *testing.T) { + c, _, _, _, _ := ssh.ParseAuthorizedKey(testdata.Cert) + if GetPublicKey(c.(*ssh.Certificate)) != string(testdata.Cert) { + t.Fail() + } +} |