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