Highly-opinionated (ex-bullshit-free) MTPROTO proxy for Telegram. If you use v1.0 or upgrade broke you proxy, please read the chapter Version 2
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

rpc_nonce_response.go 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package rpc
  2. import (
  3. "bytes"
  4. "github.com/juju/errors"
  5. )
  6. const rpcNonceResponseLength = rpcNonceRequestLength
  7. type RPCNonceResponse struct {
  8. RPCNonceRequest
  9. RPCType [rpcNonceTagLength]byte
  10. Crypto [rpcNonceCryptoAESLength]byte
  11. }
  12. func (r *RPCNonceResponse) Bytes() []byte {
  13. buf := &bytes.Buffer{}
  14. buf.Grow(rpcNonceResponseLength)
  15. buf.Write(r.RPCType[:])
  16. buf.Write(r.KeySelector[:])
  17. buf.Write(r.Crypto[:])
  18. buf.Write(r.CryptoTS[:])
  19. buf.Write(r.Nonce[:])
  20. return buf.Bytes()
  21. }
  22. func (r *RPCNonceResponse) Valid(req *RPCNonceRequest) error {
  23. if r.RPCType != rpcNonceTag {
  24. return errors.New("Unexpected RPC type")
  25. }
  26. if r.Crypto != rpcNonceCryptoAESTag {
  27. return errors.New("Unexpected crypto type")
  28. }
  29. if r.KeySelector != req.KeySelector {
  30. return errors.New("Unexpected key selector")
  31. }
  32. return nil
  33. }
  34. func NewRPCNonceResponse(data []byte) (*RPCNonceResponse, error) {
  35. if len(data) != rpcNonceResponseLength {
  36. return nil, errors.New("Unexpected message length")
  37. }
  38. resp := RPCNonceResponse{}
  39. copy(resp.RPCType[:], data[:4])
  40. copy(resp.KeySelector[:], data[4:8])
  41. copy(resp.Crypto[:], data[8:12])
  42. copy(resp.CryptoTS[:], data[12:16])
  43. copy(resp.Nonce[:], data[16:])
  44. return &resp, nil
  45. }