package tdesktop
import (
"fmt"
"io/fs"
"os"
"path"
"github.com/go-faster/errors"
)
type Account struct {
IDx uint32
Authorization MTPAuthorization
Config MTPConfig
}
func Read (root string , passcode []byte ) ([]Account , error ) {
return ReadFS (os .DirFS (root ), passcode )
}
func ReadFS (root fs .FS , passcode []byte ) ([]Account , error ) {
keyDataFile , err := open (root , "key_data" )
if err != nil {
return nil , errors .Wrap (err , "open key_data" )
}
kd , err := readKeyData (keyDataFile , passcode )
if err != nil {
return nil , err
}
if len (kd .accountsIDx ) < 1 {
return nil , ErrNoAccounts
}
r := make ([]Account , 0 , len (kd .accountsIDx ))
for _ , account := range kd .accountsIDx {
var keyFile = fileKey ("data" )
if account > 0 {
keyFile = fileKey (fmt .Sprintf ("data#%d" , account +1 ))
}
mtpDataFile , err := open (root , keyFile )
if err != nil {
return nil , errors .Wrap (err , "open key_data" )
}
mtpData , err := readMTPData (mtpDataFile , kd .localKey )
if err != nil {
return nil , errors .Wrap (err , "read mtp" )
}
a := Account {
IDx : account ,
Authorization : mtpData ,
}
mtpConfigFile , err := open (root , path .Join (keyFile , "config" ))
if err == nil {
mtpConfig , err := readMTPConfig (mtpConfigFile , kd .localKey )
if err == nil {
a .Config = mtpConfig
}
}
r = append (r , a )
}
return r , nil
}
The pages are generated with Golds v0.6.7 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds .