forked from shazow/ssh-chat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
identity.go
51 lines (42 loc) · 1.01 KB
/
identity.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
41
42
43
44
45
46
47
48
49
50
51
package sshchat
import (
"fmt"
"net"
"github.com/shazow/ssh-chat/chat"
"github.com/shazow/ssh-chat/chat/message"
"github.com/shazow/ssh-chat/sshd"
)
// Identity is a container for everything that identifies a client.
type Identity struct {
sshd.Connection
id string
}
// NewIdentity returns a new identity object from an sshd.Connection.
func NewIdentity(conn sshd.Connection) *Identity {
return &Identity{
Connection: conn,
id: chat.SanitizeName(conn.Name()),
}
}
func (i Identity) Id() string {
return i.id
}
func (i *Identity) SetId(id string) {
i.id = id
}
func (i *Identity) SetName(name string) {
i.SetId(name)
}
func (i Identity) Name() string {
return i.id
}
func (i Identity) Whois() string {
ip, _, _ := net.SplitHostPort(i.RemoteAddr().String())
fingerprint := "(no public key)"
if i.PublicKey() != nil {
fingerprint = sshd.Fingerprint(i.PublicKey())
}
return fmt.Sprintf("name: %s"+message.Newline+
" > ip: %s"+message.Newline+
" > fingerprint: %s", i.Name(), ip, fingerprint)
}