-
Notifications
You must be signed in to change notification settings - Fork 64
/
user.go
36 lines (31 loc) 路 956 Bytes
/
user.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package proto
import (
"crypto/sha1" // nolint: gosec
"fmt"
"time"
)
// User represents a Charm user account.
type User struct {
ID int `json:"id"`
CharmID string `json:"charm_id"`
PublicKey *PublicKey `json:"public_key,omitempty"`
Name string `json:"name"`
Email string `json:"email"`
Bio string `json:"bio"`
CreatedAt *time.Time `json:"created_at"`
}
// PublicKey represents to public SSH key for a Charm user.
type PublicKey struct {
ID int `json:"id"`
UserID int `json:"user_id,omitempty"`
Key string `json:"key"`
CreatedAt *time.Time `json:"created_at"`
}
// Sha returns the SHA for the public key in hex format.
func (pk *PublicKey) Sha() string {
return PublicKeySha(pk.Key)
}
// PublicKeySha returns the SHA for a public key in hex format.
func PublicKeySha(key string) string {
return fmt.Sprintf("%x", sha1.Sum([]byte(key))) // nolint: gosec
}