-
-
Notifications
You must be signed in to change notification settings - Fork 134
/
tl_secure_value_gen.go
674 lines (624 loc) · 16.2 KB
/
tl_secure_value_gen.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
// Code generated by gotdgen, DO NOT EDIT.
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"
)
// No-op definition for keeping imports.
var (
_ = bin.Buffer{}
_ = context.Background()
_ = fmt.Stringer(nil)
_ = strings.Builder{}
_ = errors.Is
_ = multierr.AppendInto
_ = sort.Ints
_ = tdp.Format
_ = tgerr.Error{}
_ = tdjson.Encoder{}
)
// SecureValue represents TL type `secureValue#187fa0ca`.
// Secure value
//
// See https://core.telegram.org/constructor/secureValue for reference.
type SecureValue struct {
// Flags, see TL conditional fields¹
//
// Links:
// 1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
Flags bin.Fields
// Secure passport¹ value type
//
// Links:
// 1) https://core.telegram.org/passport
Type SecureValueTypeClass
// Encrypted Telegram Passport¹ element data
//
// Links:
// 1) https://core.telegram.org/passport
//
// Use SetData and GetData helpers.
Data SecureData
// Encrypted passport¹ file with the front side of the document
//
// Links:
// 1) https://core.telegram.org/passport
//
// Use SetFrontSide and GetFrontSide helpers.
FrontSide SecureFileClass
// Encrypted passport¹ file with the reverse side of the document
//
// Links:
// 1) https://core.telegram.org/passport
//
// Use SetReverseSide and GetReverseSide helpers.
ReverseSide SecureFileClass
// Encrypted passport¹ file with a selfie of the user holding the document
//
// Links:
// 1) https://core.telegram.org/passport
//
// Use SetSelfie and GetSelfie helpers.
Selfie SecureFileClass
// Array of encrypted passport¹ files with translated versions of the provided documents
//
// Links:
// 1) https://core.telegram.org/passport
//
// Use SetTranslation and GetTranslation helpers.
Translation []SecureFileClass
// Array of encrypted passport¹ files with photos the of the documents
//
// Links:
// 1) https://core.telegram.org/passport
//
// Use SetFiles and GetFiles helpers.
Files []SecureFileClass
// Plaintext verified passport¹ data
//
// Links:
// 1) https://core.telegram.org/passport
//
// Use SetPlainData and GetPlainData helpers.
PlainData SecurePlainDataClass
// Data hash
Hash []byte
}
// SecureValueTypeID is TL type id of SecureValue.
const SecureValueTypeID = 0x187fa0ca
// Ensuring interfaces in compile-time for SecureValue.
var (
_ bin.Encoder = &SecureValue{}
_ bin.Decoder = &SecureValue{}
_ bin.BareEncoder = &SecureValue{}
_ bin.BareDecoder = &SecureValue{}
)
func (s *SecureValue) Zero() bool {
if s == nil {
return true
}
if !(s.Flags.Zero()) {
return false
}
if !(s.Type == nil) {
return false
}
if !(s.Data.Zero()) {
return false
}
if !(s.FrontSide == nil) {
return false
}
if !(s.ReverseSide == nil) {
return false
}
if !(s.Selfie == nil) {
return false
}
if !(s.Translation == nil) {
return false
}
if !(s.Files == nil) {
return false
}
if !(s.PlainData == nil) {
return false
}
if !(s.Hash == nil) {
return false
}
return true
}
// String implements fmt.Stringer.
func (s *SecureValue) String() string {
if s == nil {
return "SecureValue(nil)"
}
type Alias SecureValue
return fmt.Sprintf("SecureValue%+v", Alias(*s))
}
// FillFrom fills SecureValue from given interface.
func (s *SecureValue) FillFrom(from interface {
GetType() (value SecureValueTypeClass)
GetData() (value SecureData, ok bool)
GetFrontSide() (value SecureFileClass, ok bool)
GetReverseSide() (value SecureFileClass, ok bool)
GetSelfie() (value SecureFileClass, ok bool)
GetTranslation() (value []SecureFileClass, ok bool)
GetFiles() (value []SecureFileClass, ok bool)
GetPlainData() (value SecurePlainDataClass, ok bool)
GetHash() (value []byte)
}) {
s.Type = from.GetType()
if val, ok := from.GetData(); ok {
s.Data = val
}
if val, ok := from.GetFrontSide(); ok {
s.FrontSide = val
}
if val, ok := from.GetReverseSide(); ok {
s.ReverseSide = val
}
if val, ok := from.GetSelfie(); ok {
s.Selfie = val
}
if val, ok := from.GetTranslation(); ok {
s.Translation = val
}
if val, ok := from.GetFiles(); ok {
s.Files = val
}
if val, ok := from.GetPlainData(); ok {
s.PlainData = val
}
s.Hash = from.GetHash()
}
// TypeID returns type id in TL schema.
//
// See https://core.telegram.org/mtproto/TL-tl#remarks.
func (*SecureValue) TypeID() uint32 {
return SecureValueTypeID
}
// TypeName returns name of type in TL schema.
func (*SecureValue) TypeName() string {
return "secureValue"
}
// TypeInfo returns info about TL type.
func (s *SecureValue) TypeInfo() tdp.Type {
typ := tdp.Type{
Name: "secureValue",
ID: SecureValueTypeID,
}
if s == nil {
typ.Null = true
return typ
}
typ.Fields = []tdp.Field{
{
Name: "Type",
SchemaName: "type",
},
{
Name: "Data",
SchemaName: "data",
Null: !s.Flags.Has(0),
},
{
Name: "FrontSide",
SchemaName: "front_side",
Null: !s.Flags.Has(1),
},
{
Name: "ReverseSide",
SchemaName: "reverse_side",
Null: !s.Flags.Has(2),
},
{
Name: "Selfie",
SchemaName: "selfie",
Null: !s.Flags.Has(3),
},
{
Name: "Translation",
SchemaName: "translation",
Null: !s.Flags.Has(6),
},
{
Name: "Files",
SchemaName: "files",
Null: !s.Flags.Has(4),
},
{
Name: "PlainData",
SchemaName: "plain_data",
Null: !s.Flags.Has(5),
},
{
Name: "Hash",
SchemaName: "hash",
},
}
return typ
}
// SetFlags sets flags for non-zero fields.
func (s *SecureValue) SetFlags() {
if !(s.Data.Zero()) {
s.Flags.Set(0)
}
if !(s.FrontSide == nil) {
s.Flags.Set(1)
}
if !(s.ReverseSide == nil) {
s.Flags.Set(2)
}
if !(s.Selfie == nil) {
s.Flags.Set(3)
}
if !(s.Translation == nil) {
s.Flags.Set(6)
}
if !(s.Files == nil) {
s.Flags.Set(4)
}
if !(s.PlainData == nil) {
s.Flags.Set(5)
}
}
// Encode implements bin.Encoder.
func (s *SecureValue) Encode(b *bin.Buffer) error {
if s == nil {
return fmt.Errorf("can't encode secureValue#187fa0ca as nil")
}
b.PutID(SecureValueTypeID)
return s.EncodeBare(b)
}
// EncodeBare implements bin.BareEncoder.
func (s *SecureValue) EncodeBare(b *bin.Buffer) error {
if s == nil {
return fmt.Errorf("can't encode secureValue#187fa0ca as nil")
}
s.SetFlags()
if err := s.Flags.Encode(b); err != nil {
return fmt.Errorf("unable to encode secureValue#187fa0ca: field flags: %w", err)
}
if s.Type == nil {
return fmt.Errorf("unable to encode secureValue#187fa0ca: field type is nil")
}
if err := s.Type.Encode(b); err != nil {
return fmt.Errorf("unable to encode secureValue#187fa0ca: field type: %w", err)
}
if s.Flags.Has(0) {
if err := s.Data.Encode(b); err != nil {
return fmt.Errorf("unable to encode secureValue#187fa0ca: field data: %w", err)
}
}
if s.Flags.Has(1) {
if s.FrontSide == nil {
return fmt.Errorf("unable to encode secureValue#187fa0ca: field front_side is nil")
}
if err := s.FrontSide.Encode(b); err != nil {
return fmt.Errorf("unable to encode secureValue#187fa0ca: field front_side: %w", err)
}
}
if s.Flags.Has(2) {
if s.ReverseSide == nil {
return fmt.Errorf("unable to encode secureValue#187fa0ca: field reverse_side is nil")
}
if err := s.ReverseSide.Encode(b); err != nil {
return fmt.Errorf("unable to encode secureValue#187fa0ca: field reverse_side: %w", err)
}
}
if s.Flags.Has(3) {
if s.Selfie == nil {
return fmt.Errorf("unable to encode secureValue#187fa0ca: field selfie is nil")
}
if err := s.Selfie.Encode(b); err != nil {
return fmt.Errorf("unable to encode secureValue#187fa0ca: field selfie: %w", err)
}
}
if s.Flags.Has(6) {
b.PutVectorHeader(len(s.Translation))
for idx, v := range s.Translation {
if v == nil {
return fmt.Errorf("unable to encode secureValue#187fa0ca: field translation element with index %d is nil", idx)
}
if err := v.Encode(b); err != nil {
return fmt.Errorf("unable to encode secureValue#187fa0ca: field translation element with index %d: %w", idx, err)
}
}
}
if s.Flags.Has(4) {
b.PutVectorHeader(len(s.Files))
for idx, v := range s.Files {
if v == nil {
return fmt.Errorf("unable to encode secureValue#187fa0ca: field files element with index %d is nil", idx)
}
if err := v.Encode(b); err != nil {
return fmt.Errorf("unable to encode secureValue#187fa0ca: field files element with index %d: %w", idx, err)
}
}
}
if s.Flags.Has(5) {
if s.PlainData == nil {
return fmt.Errorf("unable to encode secureValue#187fa0ca: field plain_data is nil")
}
if err := s.PlainData.Encode(b); err != nil {
return fmt.Errorf("unable to encode secureValue#187fa0ca: field plain_data: %w", err)
}
}
b.PutBytes(s.Hash)
return nil
}
// Decode implements bin.Decoder.
func (s *SecureValue) Decode(b *bin.Buffer) error {
if s == nil {
return fmt.Errorf("can't decode secureValue#187fa0ca to nil")
}
if err := b.ConsumeID(SecureValueTypeID); err != nil {
return fmt.Errorf("unable to decode secureValue#187fa0ca: %w", err)
}
return s.DecodeBare(b)
}
// DecodeBare implements bin.BareDecoder.
func (s *SecureValue) DecodeBare(b *bin.Buffer) error {
if s == nil {
return fmt.Errorf("can't decode secureValue#187fa0ca to nil")
}
{
if err := s.Flags.Decode(b); err != nil {
return fmt.Errorf("unable to decode secureValue#187fa0ca: field flags: %w", err)
}
}
{
value, err := DecodeSecureValueType(b)
if err != nil {
return fmt.Errorf("unable to decode secureValue#187fa0ca: field type: %w", err)
}
s.Type = value
}
if s.Flags.Has(0) {
if err := s.Data.Decode(b); err != nil {
return fmt.Errorf("unable to decode secureValue#187fa0ca: field data: %w", err)
}
}
if s.Flags.Has(1) {
value, err := DecodeSecureFile(b)
if err != nil {
return fmt.Errorf("unable to decode secureValue#187fa0ca: field front_side: %w", err)
}
s.FrontSide = value
}
if s.Flags.Has(2) {
value, err := DecodeSecureFile(b)
if err != nil {
return fmt.Errorf("unable to decode secureValue#187fa0ca: field reverse_side: %w", err)
}
s.ReverseSide = value
}
if s.Flags.Has(3) {
value, err := DecodeSecureFile(b)
if err != nil {
return fmt.Errorf("unable to decode secureValue#187fa0ca: field selfie: %w", err)
}
s.Selfie = value
}
if s.Flags.Has(6) {
headerLen, err := b.VectorHeader()
if err != nil {
return fmt.Errorf("unable to decode secureValue#187fa0ca: field translation: %w", err)
}
if headerLen > 0 {
s.Translation = make([]SecureFileClass, 0, headerLen%bin.PreallocateLimit)
}
for idx := 0; idx < headerLen; idx++ {
value, err := DecodeSecureFile(b)
if err != nil {
return fmt.Errorf("unable to decode secureValue#187fa0ca: field translation: %w", err)
}
s.Translation = append(s.Translation, value)
}
}
if s.Flags.Has(4) {
headerLen, err := b.VectorHeader()
if err != nil {
return fmt.Errorf("unable to decode secureValue#187fa0ca: field files: %w", err)
}
if headerLen > 0 {
s.Files = make([]SecureFileClass, 0, headerLen%bin.PreallocateLimit)
}
for idx := 0; idx < headerLen; idx++ {
value, err := DecodeSecureFile(b)
if err != nil {
return fmt.Errorf("unable to decode secureValue#187fa0ca: field files: %w", err)
}
s.Files = append(s.Files, value)
}
}
if s.Flags.Has(5) {
value, err := DecodeSecurePlainData(b)
if err != nil {
return fmt.Errorf("unable to decode secureValue#187fa0ca: field plain_data: %w", err)
}
s.PlainData = value
}
{
value, err := b.Bytes()
if err != nil {
return fmt.Errorf("unable to decode secureValue#187fa0ca: field hash: %w", err)
}
s.Hash = value
}
return nil
}
// GetType returns value of Type field.
func (s *SecureValue) GetType() (value SecureValueTypeClass) {
if s == nil {
return
}
return s.Type
}
// SetData sets value of Data conditional field.
func (s *SecureValue) SetData(value SecureData) {
s.Flags.Set(0)
s.Data = value
}
// GetData returns value of Data conditional field and
// boolean which is true if field was set.
func (s *SecureValue) GetData() (value SecureData, ok bool) {
if s == nil {
return
}
if !s.Flags.Has(0) {
return value, false
}
return s.Data, true
}
// SetFrontSide sets value of FrontSide conditional field.
func (s *SecureValue) SetFrontSide(value SecureFileClass) {
s.Flags.Set(1)
s.FrontSide = value
}
// GetFrontSide returns value of FrontSide conditional field and
// boolean which is true if field was set.
func (s *SecureValue) GetFrontSide() (value SecureFileClass, ok bool) {
if s == nil {
return
}
if !s.Flags.Has(1) {
return value, false
}
return s.FrontSide, true
}
// SetReverseSide sets value of ReverseSide conditional field.
func (s *SecureValue) SetReverseSide(value SecureFileClass) {
s.Flags.Set(2)
s.ReverseSide = value
}
// GetReverseSide returns value of ReverseSide conditional field and
// boolean which is true if field was set.
func (s *SecureValue) GetReverseSide() (value SecureFileClass, ok bool) {
if s == nil {
return
}
if !s.Flags.Has(2) {
return value, false
}
return s.ReverseSide, true
}
// SetSelfie sets value of Selfie conditional field.
func (s *SecureValue) SetSelfie(value SecureFileClass) {
s.Flags.Set(3)
s.Selfie = value
}
// GetSelfie returns value of Selfie conditional field and
// boolean which is true if field was set.
func (s *SecureValue) GetSelfie() (value SecureFileClass, ok bool) {
if s == nil {
return
}
if !s.Flags.Has(3) {
return value, false
}
return s.Selfie, true
}
// SetTranslation sets value of Translation conditional field.
func (s *SecureValue) SetTranslation(value []SecureFileClass) {
s.Flags.Set(6)
s.Translation = value
}
// GetTranslation returns value of Translation conditional field and
// boolean which is true if field was set.
func (s *SecureValue) GetTranslation() (value []SecureFileClass, ok bool) {
if s == nil {
return
}
if !s.Flags.Has(6) {
return value, false
}
return s.Translation, true
}
// SetFiles sets value of Files conditional field.
func (s *SecureValue) SetFiles(value []SecureFileClass) {
s.Flags.Set(4)
s.Files = value
}
// GetFiles returns value of Files conditional field and
// boolean which is true if field was set.
func (s *SecureValue) GetFiles() (value []SecureFileClass, ok bool) {
if s == nil {
return
}
if !s.Flags.Has(4) {
return value, false
}
return s.Files, true
}
// SetPlainData sets value of PlainData conditional field.
func (s *SecureValue) SetPlainData(value SecurePlainDataClass) {
s.Flags.Set(5)
s.PlainData = value
}
// GetPlainData returns value of PlainData conditional field and
// boolean which is true if field was set.
func (s *SecureValue) GetPlainData() (value SecurePlainDataClass, ok bool) {
if s == nil {
return
}
if !s.Flags.Has(5) {
return value, false
}
return s.PlainData, true
}
// GetHash returns value of Hash field.
func (s *SecureValue) GetHash() (value []byte) {
if s == nil {
return
}
return s.Hash
}
// GetFrontSideAsNotEmpty returns mapped value of FrontSide conditional field and
// boolean which is true if field was set.
func (s *SecureValue) GetFrontSideAsNotEmpty() (*SecureFile, bool) {
if value, ok := s.GetFrontSide(); ok {
return value.AsNotEmpty()
}
return nil, false
}
// GetReverseSideAsNotEmpty returns mapped value of ReverseSide conditional field and
// boolean which is true if field was set.
func (s *SecureValue) GetReverseSideAsNotEmpty() (*SecureFile, bool) {
if value, ok := s.GetReverseSide(); ok {
return value.AsNotEmpty()
}
return nil, false
}
// GetSelfieAsNotEmpty returns mapped value of Selfie conditional field and
// boolean which is true if field was set.
func (s *SecureValue) GetSelfieAsNotEmpty() (*SecureFile, bool) {
if value, ok := s.GetSelfie(); ok {
return value.AsNotEmpty()
}
return nil, false
}
// MapTranslation returns field Translation wrapped in SecureFileClassArray helper.
func (s *SecureValue) MapTranslation() (value SecureFileClassArray, ok bool) {
if !s.Flags.Has(6) {
return value, false
}
return SecureFileClassArray(s.Translation), true
}
// MapFiles returns field Files wrapped in SecureFileClassArray helper.
func (s *SecureValue) MapFiles() (value SecureFileClassArray, ok bool) {
if !s.Flags.Has(4) {
return value, false
}
return SecureFileClassArray(s.Files), true
}