diff --git a/config/config.go b/config/config.go index 36d42d3..aaab626 100644 --- a/config/config.go +++ b/config/config.go @@ -67,12 +67,15 @@ func (c *Config) UseMiddleProxy() bool { return len(c.AdTag) > 0 } -func (c *Config) SecretString() string { +// BotSecretString returns secret string which should work with MTProxybot. +func (c *Config) BotSecretString() string { return hex.EncodeToString(c.Secret) } -func (c *Config) BotSecretString() string { - secret := c.SecretString() +// SecretString returns a secret in a form entered on the start of the +// application. +func (c *Config) SecretString() string { + secret := c.BotSecretString() if c.SecureMode { return "dd" + secret } diff --git a/wrappers/mtproto_intermediate_secure.go b/wrappers/mtproto_intermediate_secure.go index 954c3d0..ccffc90 100644 --- a/wrappers/mtproto_intermediate_secure.go +++ b/wrappers/mtproto_intermediate_secure.go @@ -8,6 +8,9 @@ import ( "github.com/9seconds/mtg/mtproto" ) +// MTProtoIntermediateSecure is an extension of MTProtoIntermediate +// mode which supports random paddings (socalled 'secure mode' or +// 'dd-secrets'). type MTProtoIntermediateSecure struct { MTProtoIntermediate } @@ -41,7 +44,7 @@ func (m *MTProtoIntermediateSecure) Write(p []byte) (int, error) { paddingLength := rand.Intn(4) buf.Grow(4 + len(p) + paddingLength) - binary.Write(buf, binary.LittleEndian, uint32(len(p)+paddingLength)) + binary.Write(buf, binary.LittleEndian, uint32(len(p)+paddingLength)) // nolint: errcheck buf.Write(p) buf.Write(make([]byte, paddingLength)) @@ -58,6 +61,8 @@ func (m *MTProtoIntermediateSecure) Write(p []byte) (int, error) { return len(p), err } +// NewMTProtoIntermediateSecure create new instance of +// MTProtoIntermediateSecure instance. func NewMTProtoIntermediateSecure(conn StreamReadWriteCloser, opts *mtproto.ConnectionOpts) PacketReadWriteCloser { return &MTProtoIntermediateSecure{ MTProtoIntermediate: MTProtoIntermediate{