|
|
@@ -8,6 +8,9 @@ import (
|
|
8
|
8
|
"github.com/9seconds/mtg/mtproto"
|
|
9
|
9
|
)
|
|
10
|
10
|
|
|
|
11
|
+// MTProtoIntermediateSecure is an extension of MTProtoIntermediate
|
|
|
12
|
+// mode which supports random paddings (socalled 'secure mode' or
|
|
|
13
|
+// 'dd-secrets').
|
|
11
|
14
|
type MTProtoIntermediateSecure struct {
|
|
12
|
15
|
MTProtoIntermediate
|
|
13
|
16
|
}
|
|
|
@@ -41,7 +44,7 @@ func (m *MTProtoIntermediateSecure) Write(p []byte) (int, error) {
|
|
41
|
44
|
paddingLength := rand.Intn(4)
|
|
42
|
45
|
buf.Grow(4 + len(p) + paddingLength)
|
|
43
|
46
|
|
|
44
|
|
- binary.Write(buf, binary.LittleEndian, uint32(len(p)+paddingLength))
|
|
|
47
|
+ binary.Write(buf, binary.LittleEndian, uint32(len(p)+paddingLength)) // nolint: errcheck
|
|
45
|
48
|
buf.Write(p)
|
|
46
|
49
|
buf.Write(make([]byte, paddingLength))
|
|
47
|
50
|
|
|
|
@@ -58,6 +61,8 @@ func (m *MTProtoIntermediateSecure) Write(p []byte) (int, error) {
|
|
58
|
61
|
return len(p), err
|
|
59
|
62
|
}
|
|
60
|
63
|
|
|
|
64
|
+// NewMTProtoIntermediateSecure create new instance of
|
|
|
65
|
+// MTProtoIntermediateSecure instance.
|
|
61
|
66
|
func NewMTProtoIntermediateSecure(conn StreamReadWriteCloser, opts *mtproto.ConnectionOpts) PacketReadWriteCloser {
|
|
62
|
67
|
return &MTProtoIntermediateSecure{
|
|
63
|
68
|
MTProtoIntermediate: MTProtoIntermediate{
|