1package backend
2
3import (
4 "bytes"
5
6 "golang.org/x/crypto/ssh"
7)
8
9// Backend is an interface that handles repositories management and any
10// non-Git related operations.
11type Backend interface {
12 ServerBackend
13 RepositoryStore
14 RepositoryMetadata
15 RepositoryAccess
16}
17
18// ParseAuthorizedKey parses an authorized key string into a public key.
19func ParseAuthorizedKey(ak string) (ssh.PublicKey, string, error) {
20 pk, c, _, _, err := ssh.ParseAuthorizedKey([]byte(ak))
21 return pk, c, err
22}
23
24// MarshalAuthorizedKey marshals a public key into an authorized key string.
25//
26// This is the inverse of ParseAuthorizedKey.
27// This function is a copy of ssh.MarshalAuthorizedKey, but without the trailing newline.
28// It returns an empty string if pk is nil.
29func MarshalAuthorizedKey(pk ssh.PublicKey) string {
30 if pk == nil {
31 return ""
32 }
33 return string(bytes.TrimSuffix(ssh.MarshalAuthorizedKey(pk), []byte("\n")))
34}