9seconds 7 лет назад
Родитель
Сommit
253c705ed6
2 измененных файлов: 12 добавлений и 4 удалений
  1. 6
    3
      config/config.go
  2. 6
    1
      wrappers/mtproto_intermediate_secure.go

+ 6
- 3
config/config.go Просмотреть файл

67
 	return len(c.AdTag) > 0
67
 	return len(c.AdTag) > 0
68
 }
68
 }
69
 
69
 
70
-func (c *Config) SecretString() string {
70
+// BotSecretString returns secret string which should work with MTProxybot.
71
+func (c *Config) BotSecretString() string {
71
 	return hex.EncodeToString(c.Secret)
72
 	return hex.EncodeToString(c.Secret)
72
 }
73
 }
73
 
74
 
74
-func (c *Config) BotSecretString() string {
75
-	secret := c.SecretString()
75
+// SecretString returns a secret in a form entered on the start of the
76
+// application.
77
+func (c *Config) SecretString() string {
78
+	secret := c.BotSecretString()
76
 	if c.SecureMode {
79
 	if c.SecureMode {
77
 		return "dd" + secret
80
 		return "dd" + secret
78
 	}
81
 	}

+ 6
- 1
wrappers/mtproto_intermediate_secure.go Просмотреть файл

8
 	"github.com/9seconds/mtg/mtproto"
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
 type MTProtoIntermediateSecure struct {
14
 type MTProtoIntermediateSecure struct {
12
 	MTProtoIntermediate
15
 	MTProtoIntermediate
13
 }
16
 }
41
 	paddingLength := rand.Intn(4)
44
 	paddingLength := rand.Intn(4)
42
 	buf.Grow(4 + len(p) + paddingLength)
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
 	buf.Write(p)
48
 	buf.Write(p)
46
 	buf.Write(make([]byte, paddingLength))
49
 	buf.Write(make([]byte, paddingLength))
47
 
50
 
58
 	return len(p), err
61
 	return len(p), err
59
 }
62
 }
60
 
63
 
64
+// NewMTProtoIntermediateSecure create new instance of
65
+// MTProtoIntermediateSecure instance.
61
 func NewMTProtoIntermediateSecure(conn StreamReadWriteCloser, opts *mtproto.ConnectionOpts) PacketReadWriteCloser {
66
 func NewMTProtoIntermediateSecure(conn StreamReadWriteCloser, opts *mtproto.ConnectionOpts) PacketReadWriteCloser {
62
 	return &MTProtoIntermediateSecure{
67
 	return &MTProtoIntermediateSecure{
63
 		MTProtoIntermediate: MTProtoIntermediate{
68
 		MTProtoIntermediate: MTProtoIntermediate{

Загрузка…
Отмена
Сохранить