Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alist-org
GitHub Repository: alist-org/alist
Path: blob/main/internal/model/sshkey.go
1560 views
1
package model
2
3
import (
4
"golang.org/x/crypto/ssh"
5
"time"
6
)
7
8
type SSHPublicKey struct {
9
ID uint `json:"id" gorm:"primaryKey"`
10
UserId uint `json:"-"`
11
Title string `json:"title"`
12
Fingerprint string `json:"fingerprint"`
13
KeyStr string `gorm:"type:text" json:"-"`
14
AddedTime time.Time `json:"added_time"`
15
LastUsedTime time.Time `json:"last_used_time"`
16
}
17
18
func (k *SSHPublicKey) GetKey() (ssh.PublicKey, error) {
19
pubKey, _, _, _, err := ssh.ParseAuthorizedKey([]byte(k.KeyStr))
20
if err != nil {
21
return nil, err
22
}
23
return pubKey, nil
24
}
25
26
func (k *SSHPublicKey) UpdateLastUsedTime() {
27
k.LastUsedTime = time.Now()
28
}
29
30