-
Notifications
You must be signed in to change notification settings - Fork 14
/
message_type.go
74 lines (62 loc) · 1.79 KB
/
message_type.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
package otr3
import "bytes"
type messageTypeGuess int
const (
msgGuessNotOTR messageTypeGuess = iota
msgGuessTaggedPlaintext
msgGuessQuery
msgGuessDHCommit
msgGuessDHKey
msgGuessRevealSig
msgGuessSignature
msgGuessV1KeyExch
msgGuessData
msgGuessError
msgGuessFragment
msgGuessUnknown
)
func guessMessageType(msg []byte) messageTypeGuess {
if bytes.HasPrefix(msg, []byte("?OTR")) {
switch {
case bytes.HasPrefix(msg, []byte("?OTR:AAMC")):
return msgGuessDHCommit
case bytes.HasPrefix(msg, []byte("?OTR:AAIC")):
return msgGuessDHCommit
case bytes.HasPrefix(msg, []byte("?OTR:AAMK")):
return msgGuessDHKey
case bytes.HasPrefix(msg, []byte("?OTR:AAIK")):
return msgGuessDHKey
case bytes.HasPrefix(msg, []byte("?OTR:AAMR")):
return msgGuessRevealSig
case bytes.HasPrefix(msg, []byte("?OTR:AAIR")):
return msgGuessRevealSig
case bytes.HasPrefix(msg, []byte("?OTR:AAMS")):
return msgGuessSignature
case bytes.HasPrefix(msg, []byte("?OTR:AAIS")):
return msgGuessSignature
case bytes.HasPrefix(msg, []byte("?OTR:AAED")):
return msgGuessData
case bytes.HasPrefix(msg, []byte("?OTR:AAID")):
return msgGuessData
case bytes.HasPrefix(msg, []byte("?OTR:AAMD")):
return msgGuessData
case bytes.HasPrefix(msg, []byte("?OTR?")):
return msgGuessQuery
case bytes.HasPrefix(msg, []byte("?OTRv")):
return msgGuessQuery
case bytes.HasPrefix(msg, []byte("?OTR:AAEK")):
return msgGuessV1KeyExch
case bytes.HasPrefix(msg, []byte("?OTR Error:")):
return msgGuessError
case bytes.HasPrefix(msg, []byte("?OTR|")):
return msgGuessFragment
case bytes.HasPrefix(msg, []byte("?OTR,")):
return msgGuessFragment
}
return msgGuessUnknown
}
if bytes.Contains(msg, whitespaceTagHeader) {
return msgGuessTaggedPlaintext
}
return msgGuessNotOTR
}