7a04f298d2
- update to latest telegram layer - remove some references to fields in tg.Entities that don't exist in the schema - originally added here: https://github.com/beeper/td/commit/820929062a2ba0104397bc01235ab58a9cff780e - referenced here - https://github.com/mautrix/telegramgo/commit/124f0967ed195b5a380c9bd02e170ada9710dde3 - https://github.com/mautrix/telegramgo/commit/4205047aab2e0639217148b5d125bfaab668bd8e
42 lines
1.0 KiB
Go
42 lines
1.0 KiB
Go
package crypto
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"go.mau.fi/mautrix-telegram/pkg/gotd/bin"
|
|
"go.mau.fi/mautrix-telegram/pkg/gotd/testutil"
|
|
)
|
|
|
|
func TestEncrypt(t *testing.T) {
|
|
c := NewClientCipher(testutil.ZeroRand{})
|
|
|
|
var authKey Key
|
|
for i := 0; i < 256; i++ {
|
|
authKey[i] = byte(i)
|
|
}
|
|
|
|
// Testing vector from grammers.
|
|
msg, err := c.encryptMessage(
|
|
authKey.WithID(),
|
|
&bin.Buffer{Buf: []byte("Hello, world! This data should remain secure!")},
|
|
)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
b := &bin.Buffer{}
|
|
if err := msg.Encode(b); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
expected := []byte{
|
|
50, 209, 88, 110, 164, 87, 223, 200, 168, 23, 41, 212, 109, 181, 64, 25, 162, 191, 215,
|
|
247, 68, 249, 185, 108, 79, 113, 108, 253, 196, 71, 125, 178, 162, 193, 95, 109, 219,
|
|
133, 35, 95, 185, 85, 47, 29, 132, 7, 198, 170, 234, 0, 204, 132, 76, 90, 27, 246, 172,
|
|
68, 183, 155, 94, 220, 42, 35, 134, 139, 61, 96, 115, 165, 144, 153, 44, 15, 41, 117,
|
|
36, 61, 86, 62, 161, 128, 210, 24, 238, 117, 124, 154,
|
|
}
|
|
require.Equal(t, expected, b.Buf)
|
|
}
|