tdesktop

package
v0.51.0-alpha.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 7, 2021 License: MIT Imports: 21 Imported by: 16

Documentation

Overview

Package tdesktop contains Telegram Desktop session decoder.

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrKeyInfoDecrypt = errors.New("key data decrypt")

ErrKeyInfoDecrypt is returned when key data decrypt fails. It can happen if passed passcode is wrong.

Functions

This section is empty.

Types

type Account

type Account struct {
	// IDx is an internal Telegram Desktop account ID.
	IDx uint32
	// Authorization contains Telegram user and MTProto sessions.
	Authorization MTPAuthorization
}

Account is a Telegram user account representation in Telegram Desktop storage.

func Read

func Read(root string, passcode []byte) ([]Account, error)

Read reads accounts info from given Telegram Desktop tdata root. Shorthand for:

ReadFS(os.DirFS(root), passcode)
Example
package main

import (
	"fmt"
	"os"
	"path/filepath"

	"github.com/gotd/td/session/tdesktop"
)

func main() {
	home, err := os.UserHomeDir()
	if err != nil {
		panic(err)
	}

	root := filepath.Join(home, "Downloads", "Telegram", "tdata")
	accounts, err := tdesktop.Read(root, nil)
	if err != nil {
		panic(err)
	}

	for _, account := range accounts {
		a := account.Authorization
		fmt.Println(a.UserID, a.MainDC)
	}
}
Output:

func ReadFS

func ReadFS(root fs.FS, passcode []byte) ([]Account, error)

ReadFS reads Telegram Desktop accounts info from given FS root.

type MTPAuthorization

type MTPAuthorization struct {
	// UserID is a Telegram user ID.
	UserID int64
	// MainDC is a main DC ID of this user.
	MainDC int
	// Key is a map of keys per DC ID.
	Keys map[int]crypto.Key // DC ID -> Key
}

MTPAuthorization is a Telegram Desktop storage structure which stores MTProto session info.

type WrongMagicError

type WrongMagicError struct {
	Magic [4]byte
}

WrongMagicError is returned when tdesktop data file has wrong magic header.

func (*WrongMagicError) Error

func (w *WrongMagicError) Error() string

Error implements error.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL