package tg
import (
"context"
"errors"
"fmt"
"sort"
"strings"
"go.uber.org/multierr"
"github.com/gotd/td/bin"
"github.com/gotd/td/tdjson"
"github.com/gotd/td/tdp"
"github.com/gotd/td/tgerr"
)
var (
_ = bin .Buffer {}
_ = context .Background ()
_ = fmt .Stringer (nil )
_ = strings .Builder {}
_ = errors .Is
_ = multierr .AppendInto
_ = sort .Ints
_ = tdp .Format
_ = tgerr .Error {}
_ = tdjson .Encoder {}
)
type AccountPassword struct {
Flags bin .Fields
HasRecovery bool
HasSecureValues bool
HasPassword bool
CurrentAlgo PasswordKdfAlgoClass
SRPB []byte
SRPID int64
Hint string
EmailUnconfirmedPattern string
NewAlgo PasswordKdfAlgoClass
NewSecureAlgo SecurePasswordKdfAlgoClass
SecureRandom []byte
PendingResetDate int
LoginEmailPattern string
}
const AccountPasswordTypeID = 0x957b50fb
var (
_ bin .Encoder = &AccountPassword {}
_ bin .Decoder = &AccountPassword {}
_ bin .BareEncoder = &AccountPassword {}
_ bin .BareDecoder = &AccountPassword {}
)
func (p *AccountPassword ) Zero () bool {
if p == nil {
return true
}
if !(p .Flags .Zero ()) {
return false
}
if !(p .HasRecovery == false ) {
return false
}
if !(p .HasSecureValues == false ) {
return false
}
if !(p .HasPassword == false ) {
return false
}
if !(p .CurrentAlgo == nil ) {
return false
}
if !(p .SRPB == nil ) {
return false
}
if !(p .SRPID == 0 ) {
return false
}
if !(p .Hint == "" ) {
return false
}
if !(p .EmailUnconfirmedPattern == "" ) {
return false
}
if !(p .NewAlgo == nil ) {
return false
}
if !(p .NewSecureAlgo == nil ) {
return false
}
if !(p .SecureRandom == nil ) {
return false
}
if !(p .PendingResetDate == 0 ) {
return false
}
if !(p .LoginEmailPattern == "" ) {
return false
}
return true
}
func (p *AccountPassword ) String () string {
if p == nil {
return "AccountPassword(nil)"
}
type Alias AccountPassword
return fmt .Sprintf ("AccountPassword%+v" , Alias (*p ))
}
func (p *AccountPassword ) FillFrom (from interface {
GetHasRecovery () (value bool )
GetHasSecureValues () (value bool )
GetHasPassword () (value bool )
GetCurrentAlgo () (value PasswordKdfAlgoClass , ok bool )
GetSRPB () (value []byte , ok bool )
GetSRPID () (value int64 , ok bool )
GetHint () (value string , ok bool )
GetEmailUnconfirmedPattern () (value string , ok bool )
GetNewAlgo () (value PasswordKdfAlgoClass )
GetNewSecureAlgo () (value SecurePasswordKdfAlgoClass )
GetSecureRandom () (value []byte )
GetPendingResetDate () (value int , ok bool )
GetLoginEmailPattern () (value string , ok bool )
}) {
p .HasRecovery = from .GetHasRecovery ()
p .HasSecureValues = from .GetHasSecureValues ()
p .HasPassword = from .GetHasPassword ()
if val , ok := from .GetCurrentAlgo (); ok {
p .CurrentAlgo = val
}
if val , ok := from .GetSRPB (); ok {
p .SRPB = val
}
if val , ok := from .GetSRPID (); ok {
p .SRPID = val
}
if val , ok := from .GetHint (); ok {
p .Hint = val
}
if val , ok := from .GetEmailUnconfirmedPattern (); ok {
p .EmailUnconfirmedPattern = val
}
p .NewAlgo = from .GetNewAlgo ()
p .NewSecureAlgo = from .GetNewSecureAlgo ()
p .SecureRandom = from .GetSecureRandom ()
if val , ok := from .GetPendingResetDate (); ok {
p .PendingResetDate = val
}
if val , ok := from .GetLoginEmailPattern (); ok {
p .LoginEmailPattern = val
}
}
func (*AccountPassword ) TypeID () uint32 {
return AccountPasswordTypeID
}
func (*AccountPassword ) TypeName () string {
return "account.password"
}
func (p *AccountPassword ) TypeInfo () tdp .Type {
typ := tdp .Type {
Name : "account.password" ,
ID : AccountPasswordTypeID ,
}
if p == nil {
typ .Null = true
return typ
}
typ .Fields = []tdp .Field {
{
Name : "HasRecovery" ,
SchemaName : "has_recovery" ,
Null : !p .Flags .Has (0 ),
},
{
Name : "HasSecureValues" ,
SchemaName : "has_secure_values" ,
Null : !p .Flags .Has (1 ),
},
{
Name : "HasPassword" ,
SchemaName : "has_password" ,
Null : !p .Flags .Has (2 ),
},
{
Name : "CurrentAlgo" ,
SchemaName : "current_algo" ,
Null : !p .Flags .Has (2 ),
},
{
Name : "SRPB" ,
SchemaName : "srp_B" ,
Null : !p .Flags .Has (2 ),
},
{
Name : "SRPID" ,
SchemaName : "srp_id" ,
Null : !p .Flags .Has (2 ),
},
{
Name : "Hint" ,
SchemaName : "hint" ,
Null : !p .Flags .Has (3 ),
},
{
Name : "EmailUnconfirmedPattern" ,
SchemaName : "email_unconfirmed_pattern" ,
Null : !p .Flags .Has (4 ),
},
{
Name : "NewAlgo" ,
SchemaName : "new_algo" ,
},
{
Name : "NewSecureAlgo" ,
SchemaName : "new_secure_algo" ,
},
{
Name : "SecureRandom" ,
SchemaName : "secure_random" ,
},
{
Name : "PendingResetDate" ,
SchemaName : "pending_reset_date" ,
Null : !p .Flags .Has (5 ),
},
{
Name : "LoginEmailPattern" ,
SchemaName : "login_email_pattern" ,
Null : !p .Flags .Has (6 ),
},
}
return typ
}
func (p *AccountPassword ) SetFlags () {
if !(p .HasRecovery == false ) {
p .Flags .Set (0 )
}
if !(p .HasSecureValues == false ) {
p .Flags .Set (1 )
}
if !(p .HasPassword == false ) {
p .Flags .Set (2 )
}
if !(p .CurrentAlgo == nil ) {
p .Flags .Set (2 )
}
if !(p .SRPB == nil ) {
p .Flags .Set (2 )
}
if !(p .SRPID == 0 ) {
p .Flags .Set (2 )
}
if !(p .Hint == "" ) {
p .Flags .Set (3 )
}
if !(p .EmailUnconfirmedPattern == "" ) {
p .Flags .Set (4 )
}
if !(p .PendingResetDate == 0 ) {
p .Flags .Set (5 )
}
if !(p .LoginEmailPattern == "" ) {
p .Flags .Set (6 )
}
}
func (p *AccountPassword ) Encode (b *bin .Buffer ) error {
if p == nil {
return fmt .Errorf ("can't encode account.password#957b50fb as nil" )
}
b .PutID (AccountPasswordTypeID )
return p .EncodeBare (b )
}
func (p *AccountPassword ) EncodeBare (b *bin .Buffer ) error {
if p == nil {
return fmt .Errorf ("can't encode account.password#957b50fb as nil" )
}
p .SetFlags ()
if err := p .Flags .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode account.password#957b50fb: field flags: %w" , err )
}
if p .Flags .Has (2 ) {
if p .CurrentAlgo == nil {
return fmt .Errorf ("unable to encode account.password#957b50fb: field current_algo is nil" )
}
if err := p .CurrentAlgo .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode account.password#957b50fb: field current_algo: %w" , err )
}
}
if p .Flags .Has (2 ) {
b .PutBytes (p .SRPB )
}
if p .Flags .Has (2 ) {
b .PutLong (p .SRPID )
}
if p .Flags .Has (3 ) {
b .PutString (p .Hint )
}
if p .Flags .Has (4 ) {
b .PutString (p .EmailUnconfirmedPattern )
}
if p .NewAlgo == nil {
return fmt .Errorf ("unable to encode account.password#957b50fb: field new_algo is nil" )
}
if err := p .NewAlgo .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode account.password#957b50fb: field new_algo: %w" , err )
}
if p .NewSecureAlgo == nil {
return fmt .Errorf ("unable to encode account.password#957b50fb: field new_secure_algo is nil" )
}
if err := p .NewSecureAlgo .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode account.password#957b50fb: field new_secure_algo: %w" , err )
}
b .PutBytes (p .SecureRandom )
if p .Flags .Has (5 ) {
b .PutInt (p .PendingResetDate )
}
if p .Flags .Has (6 ) {
b .PutString (p .LoginEmailPattern )
}
return nil
}
func (p *AccountPassword ) Decode (b *bin .Buffer ) error {
if p == nil {
return fmt .Errorf ("can't decode account.password#957b50fb to nil" )
}
if err := b .ConsumeID (AccountPasswordTypeID ); err != nil {
return fmt .Errorf ("unable to decode account.password#957b50fb: %w" , err )
}
return p .DecodeBare (b )
}
func (p *AccountPassword ) DecodeBare (b *bin .Buffer ) error {
if p == nil {
return fmt .Errorf ("can't decode account.password#957b50fb to nil" )
}
{
if err := p .Flags .Decode (b ); err != nil {
return fmt .Errorf ("unable to decode account.password#957b50fb: field flags: %w" , err )
}
}
p .HasRecovery = p .Flags .Has (0 )
p .HasSecureValues = p .Flags .Has (1 )
p .HasPassword = p .Flags .Has (2 )
if p .Flags .Has (2 ) {
value , err := DecodePasswordKdfAlgo (b )
if err != nil {
return fmt .Errorf ("unable to decode account.password#957b50fb: field current_algo: %w" , err )
}
p .CurrentAlgo = value
}
if p .Flags .Has (2 ) {
value , err := b .Bytes ()
if err != nil {
return fmt .Errorf ("unable to decode account.password#957b50fb: field srp_B: %w" , err )
}
p .SRPB = value
}
if p .Flags .Has (2 ) {
value , err := b .Long ()
if err != nil {
return fmt .Errorf ("unable to decode account.password#957b50fb: field srp_id: %w" , err )
}
p .SRPID = value
}
if p .Flags .Has (3 ) {
value , err := b .String ()
if err != nil {
return fmt .Errorf ("unable to decode account.password#957b50fb: field hint: %w" , err )
}
p .Hint = value
}
if p .Flags .Has (4 ) {
value , err := b .String ()
if err != nil {
return fmt .Errorf ("unable to decode account.password#957b50fb: field email_unconfirmed_pattern: %w" , err )
}
p .EmailUnconfirmedPattern = value
}
{
value , err := DecodePasswordKdfAlgo (b )
if err != nil {
return fmt .Errorf ("unable to decode account.password#957b50fb: field new_algo: %w" , err )
}
p .NewAlgo = value
}
{
value , err := DecodeSecurePasswordKdfAlgo (b )
if err != nil {
return fmt .Errorf ("unable to decode account.password#957b50fb: field new_secure_algo: %w" , err )
}
p .NewSecureAlgo = value
}
{
value , err := b .Bytes ()
if err != nil {
return fmt .Errorf ("unable to decode account.password#957b50fb: field secure_random: %w" , err )
}
p .SecureRandom = value
}
if p .Flags .Has (5 ) {
value , err := b .Int ()
if err != nil {
return fmt .Errorf ("unable to decode account.password#957b50fb: field pending_reset_date: %w" , err )
}
p .PendingResetDate = value
}
if p .Flags .Has (6 ) {
value , err := b .String ()
if err != nil {
return fmt .Errorf ("unable to decode account.password#957b50fb: field login_email_pattern: %w" , err )
}
p .LoginEmailPattern = value
}
return nil
}
func (p *AccountPassword ) SetHasRecovery (value bool ) {
if value {
p .Flags .Set (0 )
p .HasRecovery = true
} else {
p .Flags .Unset (0 )
p .HasRecovery = false
}
}
func (p *AccountPassword ) GetHasRecovery () (value bool ) {
if p == nil {
return
}
return p .Flags .Has (0 )
}
func (p *AccountPassword ) SetHasSecureValues (value bool ) {
if value {
p .Flags .Set (1 )
p .HasSecureValues = true
} else {
p .Flags .Unset (1 )
p .HasSecureValues = false
}
}
func (p *AccountPassword ) GetHasSecureValues () (value bool ) {
if p == nil {
return
}
return p .Flags .Has (1 )
}
func (p *AccountPassword ) SetHasPassword (value bool ) {
if value {
p .Flags .Set (2 )
p .HasPassword = true
} else {
p .Flags .Unset (2 )
p .HasPassword = false
}
}
func (p *AccountPassword ) GetHasPassword () (value bool ) {
if p == nil {
return
}
return p .Flags .Has (2 )
}
func (p *AccountPassword ) SetCurrentAlgo (value PasswordKdfAlgoClass ) {
p .Flags .Set (2 )
p .CurrentAlgo = value
}
func (p *AccountPassword ) GetCurrentAlgo () (value PasswordKdfAlgoClass , ok bool ) {
if p == nil {
return
}
if !p .Flags .Has (2 ) {
return value , false
}
return p .CurrentAlgo , true
}
func (p *AccountPassword ) SetSRPB (value []byte ) {
p .Flags .Set (2 )
p .SRPB = value
}
func (p *AccountPassword ) GetSRPB () (value []byte , ok bool ) {
if p == nil {
return
}
if !p .Flags .Has (2 ) {
return value , false
}
return p .SRPB , true
}
func (p *AccountPassword ) SetSRPID (value int64 ) {
p .Flags .Set (2 )
p .SRPID = value
}
func (p *AccountPassword ) GetSRPID () (value int64 , ok bool ) {
if p == nil {
return
}
if !p .Flags .Has (2 ) {
return value , false
}
return p .SRPID , true
}
func (p *AccountPassword ) SetHint (value string ) {
p .Flags .Set (3 )
p .Hint = value
}
func (p *AccountPassword ) GetHint () (value string , ok bool ) {
if p == nil {
return
}
if !p .Flags .Has (3 ) {
return value , false
}
return p .Hint , true
}
func (p *AccountPassword ) SetEmailUnconfirmedPattern (value string ) {
p .Flags .Set (4 )
p .EmailUnconfirmedPattern = value
}
func (p *AccountPassword ) GetEmailUnconfirmedPattern () (value string , ok bool ) {
if p == nil {
return
}
if !p .Flags .Has (4 ) {
return value , false
}
return p .EmailUnconfirmedPattern , true
}
func (p *AccountPassword ) GetNewAlgo () (value PasswordKdfAlgoClass ) {
if p == nil {
return
}
return p .NewAlgo
}
func (p *AccountPassword ) GetNewSecureAlgo () (value SecurePasswordKdfAlgoClass ) {
if p == nil {
return
}
return p .NewSecureAlgo
}
func (p *AccountPassword ) GetSecureRandom () (value []byte ) {
if p == nil {
return
}
return p .SecureRandom
}
func (p *AccountPassword ) SetPendingResetDate (value int ) {
p .Flags .Set (5 )
p .PendingResetDate = value
}
func (p *AccountPassword ) GetPendingResetDate () (value int , ok bool ) {
if p == nil {
return
}
if !p .Flags .Has (5 ) {
return value , false
}
return p .PendingResetDate , true
}
func (p *AccountPassword ) SetLoginEmailPattern (value string ) {
p .Flags .Set (6 )
p .LoginEmailPattern = value
}
func (p *AccountPassword ) GetLoginEmailPattern () (value string , ok bool ) {
if p == nil {
return
}
if !p .Flags .Has (6 ) {
return value , false
}
return p .LoginEmailPattern , true
}
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 .