/
msg.go
105 lines (89 loc) · 2.13 KB
/
msg.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package ufo
type (
//Sig is a base64 encoded PKCS1v15 signature
Sig string
//FingerPrint is a SHA256 hash of PEM encoded public key */
FingerPrint string
)
//SignedFingerPrint is used to verify
//the authenticity of a user.
type SignedFingerPrint struct {
FingerPrint //Public key of user they claim to be
SignedChallenge Sig //Signature of sha256 encoded UUID challenge
}
//Group represents a group chat, identified by UUID
type Group struct {
UUID string //UUID of group
Members []FingerPrint //Public keys of the members in that group
}
//Msg is a single message from or to a client
type Msg struct {
From FingerPrint //Sender's public key
Content string //Content of message
}
//RegisterIn is the JSON object
//for user registration.
type RegisterIn struct {
Public string //Pem enoded public key
Sig Sig //Signature of the contents of Public
}
//ChallengeIn is the JSON object
//for users to request a challenge
type ChallengeIn struct {
FingerPrint //User's public key fingerprint
}
//ChallengeOut is the JSON object
//for challenge reuqest responses.
type ChallengeOut struct {
UUID string //Plain text UUID that user must sign
}
//ReadIn is the JSON object
//for users to request their messages.
type ReadIn struct {
SignedFingerPrint
GroupID string
}
//ReadOut is the JSON object
//response for read requests.
type ReadOut struct {
Msgs []Msg
Err error
}
//WriteIn is the JSON object
//for write requests.
type WriteIn struct {
SignedFingerPrint
GroupID string
Content string
}
//ListIn is the JSON object
//for users to list what groups
//they are in.
type ListIn struct {
SignedFingerPrint
}
//ListOut is the JSON object
//response for list requests.
type ListOut struct {
GroupUUIDs []string
}
//GroupIn is the JSON object
//for conversation create
//requests
type GroupIn struct {
Group
SignedFingerPrint
}
//GroupOut is the JSON object
//response for conversation
//create requests.
type GroupOut struct {
Error, UUID string
}
//Reciept is a mark in to the message
//array for a conversation such that we
//only send new "unread" messages
type Reciept struct {
User FingerPrint
Room string
}