move gotd fork into repo. (#111)
- 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
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
package crypto
|
||||
|
||||
import (
|
||||
"io"
|
||||
|
||||
"go.mau.fi/mautrix-telegram/pkg/gotd/bin"
|
||||
)
|
||||
|
||||
// RandInt64n returns random int64 from randSource in [0; n).
|
||||
func RandInt64n(randSource io.Reader, n int64) (int64, error) {
|
||||
v, err := RandInt64(randSource)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if v < 0 {
|
||||
v *= -1
|
||||
}
|
||||
return v % n, nil
|
||||
}
|
||||
|
||||
// RandInt64 returns random int64 from randSource.
|
||||
func RandInt64(randSource io.Reader) (int64, error) {
|
||||
var buf [bin.Word * 2]byte
|
||||
if _, err := io.ReadFull(randSource, buf[:]); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
b := &bin.Buffer{Buf: buf[:]}
|
||||
return b.Long()
|
||||
}
|
||||
|
||||
// RandInt128 generates and returns new random 128-bit integer.
|
||||
//
|
||||
// Use crypto/rand.Reader as randSource in production.
|
||||
func RandInt128(randSource io.Reader) (bin.Int128, error) {
|
||||
var buf [bin.Word * 4]byte
|
||||
if _, err := io.ReadFull(randSource, buf[:]); err != nil {
|
||||
return bin.Int128{}, err
|
||||
}
|
||||
b := &bin.Buffer{Buf: buf[:]}
|
||||
return b.Int128()
|
||||
}
|
||||
|
||||
// RandInt256 generates and returns new random 256-bit integer.
|
||||
//
|
||||
// Use crypto/rand.Reader as randSource in production.
|
||||
func RandInt256(randSource io.Reader) (bin.Int256, error) {
|
||||
var buf [bin.Word * 8]byte
|
||||
if _, err := io.ReadFull(randSource, buf[:]); err != nil {
|
||||
return bin.Int256{}, err
|
||||
}
|
||||
b := &bin.Buffer{Buf: buf[:]}
|
||||
return b.Int256()
|
||||
}
|
||||
Reference in New Issue
Block a user