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 SettingsBackend
13 RepositoryStore
14 RepositoryMetadata
15 RepositoryAccess
16 UserStore
17 UserAccess
18}
19
20// ParseAuthorizedKey parses an authorized key string into a public key.
21func ParseAuthorizedKey(ak string) (ssh.PublicKey, string, error) {
22 pk, c, _, _, err := ssh.ParseAuthorizedKey([]byte(ak))
23 return pk, c, err
24}
25
26// MarshalAuthorizedKey marshals a public key into an authorized key string.
27//
28// This is the inverse of ParseAuthorizedKey.
29// This function is a copy of ssh.MarshalAuthorizedKey, but without the trailing newline.
30// It returns an empty string if pk is nil.
31func MarshalAuthorizedKey(pk ssh.PublicKey) string {
32 if pk == nil {
33 return ""
34 }
35 return string(bytes.TrimSuffix(ssh.MarshalAuthorizedKey(pk), []byte("\n")))
36}