forked from chanify/chanify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser.go
40 lines (34 loc) · 831 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
37
38
39
40
package model
import "github.com/chanify/chanify/crypto"
// User information
type User struct {
UID string
PublicKey []byte
SecretKey []byte
Flags uint
}
// IsServerless for user configuration
func (u *User) IsServerless() bool {
return (u.Flags&0x01 == 0)
}
// SetServerless for user configuration
func (u *User) SetServerless(s bool) {
if s {
u.Flags &= ^uint(0x01)
} else {
u.Flags |= uint(0x01)
}
}
// GetPublicKeyString return the user public key
func (u *User) GetPublicKeyString() string {
return crypto.Base64Encode.EncodeToString(u.PublicKey)
}
// PublicKeyEncrypt return encrypted public key
func (u *User) PublicKeyEncrypt(data []byte) []byte {
pk, err := crypto.LoadPublicKey(u.PublicKey)
if err != nil {
return []byte{}
}
out, _ := pk.Encrypt(data) // nolint: errcheck
return out
}