tgbot/types/passport/data/mod.rs
1use serde::{Deserialize, Serialize};
2
3use crate::types::Integer;
4
5#[cfg(test)]
6mod tests;
7
8/// Represents a file uploaded to Telegram Passport.
9///
10/// Currently all Telegram Passport files are in JPEG
11/// format when decrypted and don't exceed 10MB.
12#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
13pub struct PassportFile {
14 /// A unix timestamp when a file was uploaded.
15 pub file_date: Integer,
16 /// An identifier for a file, which can be used to download or reuse the file.
17 pub file_id: String,
18 /// A file size in bytes.
19 pub file_size: Integer,
20 /// A unique identifier for a file.
21 ///
22 /// It is supposed to be the same over time and for different bots.
23 /// Can't be used to download or reuse a file.
24 pub file_unique_id: String,
25}
26
27impl PassportFile {
28 /// Creates a new `PassportFile`.
29 ///
30 /// # Arguments
31 ///
32 /// * `file_date` - A unix time when a file was uploaded.
33 /// * `file_id` - An identifier for a file.
34 /// * `file_size` - A file size in bytes.
35 /// * `file_unique_id` - A unique identifier for a file.
36 pub fn new<A, B>(file_date: Integer, file_id: A, file_size: Integer, file_unique_id: B) -> Self
37 where
38 A: Into<String>,
39 B: Into<String>,
40 {
41 Self {
42 file_date,
43 file_id: file_id.into(),
44 file_size,
45 file_unique_id: file_unique_id.into(),
46 }
47 }
48}
49
50/// Represents a data required for decrypting and authenticating [`EncryptedPassportElement`].
51///
52/// See the [Telegram Passport Documentation][1] for a complete description
53/// of the data decryption and authentication processes.
54///
55/// [1]: https://core.telegram.org/passport#receiving-information
56#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
57pub struct EncryptedCredentials {
58 /// A base64-encoded encrypted JSON-serialized data
59 /// with unique user's payload,
60 /// data hashes and secrets required
61 /// for [`EncryptedPassportElement`] decryption and authentication.
62 pub data: String,
63 /// A base64-encoded data hash for data authentication.
64 pub hash: String,
65 /// A base64-encoded secret, encrypted
66 /// with the bot public RSA key,
67 /// required for data decryption.
68 pub secret: String,
69}
70
71impl EncryptedCredentials {
72 /// Creates a new `EncryptedCredentials`.
73 ///
74 /// # Arguments
75 ///
76 /// * `data` - A unique payload.
77 /// * `hash` - A hash for data authentication.
78 /// * `secret` - A secret for data decryption.
79 pub fn new<A, B, C>(data: A, hash: B, secret: C) -> Self
80 where
81 A: Into<String>,
82 B: Into<String>,
83 C: Into<String>,
84 {
85 Self {
86 data: data.into(),
87 hash: hash.into(),
88 secret: secret.into(),
89 }
90 }
91}
92
93/// Represents an address.
94#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
95pub struct EncryptedPassportElementAddress {
96 /// A base64-encoded encrypted
97 /// Telegram Passport element data provided by the user.
98 ///
99 /// Can be decrypted and verified using
100 /// the accompanying [`EncryptedCredentials`].
101 pub data: String,
102 /// A base64-encoded element hash for
103 /// using in [`crate::types::PassportElementError::unspecified`].
104 pub hash: String,
105}
106
107impl EncryptedPassportElementAddress {
108 /// Creates a new `EncryptedPassportElementAddress`
109 ///
110 /// # Arguments
111 ///
112 /// * `data` - A data provided by a user.
113 /// * `hash` - An element hash.
114 pub fn new<A, B>(data: A, hash: B) -> Self
115 where
116 A: Into<String>,
117 B: Into<String>,
118 {
119 Self {
120 data: data.into(),
121 hash: hash.into(),
122 }
123 }
124}
125
126/// Represents a bank statement.
127#[serde_with::skip_serializing_none]
128#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
129pub struct EncryptedPassportElementBankStatement {
130 /// An array of encrypted files with
131 /// documents provided by a user.
132 ///
133 /// Files can be decrypted and verified
134 /// using the accompanying [`EncryptedCredentials`].
135 pub files: Vec<PassportFile>,
136 /// A base64-encoded element hash for
137 /// using in [`crate::types::PassportElementError::unspecified`].
138 pub hash: String,
139 /// An array of encrypted files with translated
140 /// versions of documents provided by a user.
141 ///
142 /// Files can be decrypted and verified
143 /// using the accompanying [`EncryptedCredentials`].
144 pub translation: Option<Vec<PassportFile>>,
145}
146
147impl EncryptedPassportElementBankStatement {
148 /// Creates a new `EncryptedPassportElementBankStatement`.
149 ///
150 /// # Arguments
151 ///
152 /// * `files` - An array of encrypted files with documents.
153 /// * `hash` - An element hash.
154 pub fn new<A, B>(files: A, hash: B) -> Self
155 where
156 A: IntoIterator<Item = PassportFile>,
157 B: Into<String>,
158 {
159 Self {
160 files: files.into_iter().collect(),
161 hash: hash.into(),
162 translation: None,
163 }
164 }
165
166 /// Sets a new translation.
167 ///
168 /// # Arguments
169 ///
170 /// * `value` - An array of encrypted files with translated versions of documents.
171 pub fn with_translation<T>(mut self, value: T) -> Self
172 where
173 T: IntoIterator<Item = PassportFile>,
174 {
175 self.translation = Some(value.into_iter().collect());
176 self
177 }
178}
179
180/// Represents a driver license.
181#[serde_with::skip_serializing_none]
182#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
183pub struct EncryptedPassportElementDriverLicense {
184 /// A base64-encoded encrypted
185 /// Telegram Passport element data provided by a user.
186 ///
187 /// Can be decrypted and verified using
188 /// the accompanying [`EncryptedCredentials`].
189 pub data: String,
190 /// An encrypted file with a front side
191 /// of a document, provided by a user.
192 ///
193 /// The file can be decrypted and verified
194 /// using the accompanying [`EncryptedCredentials`].
195 pub front_side: PassportFile,
196 /// A base64-encoded element hash for
197 /// using in [`crate::types::PassportElementError::unspecified`].
198 pub hash: String,
199 /// An encrypted file with a selfie of a user
200 /// holding a document, provided by a user.
201 ///
202 /// The file can be decrypted and verified
203 /// using the accompanying [`EncryptedCredentials`].
204 pub selfie: PassportFile,
205 /// An encrypted file with a reverse side of a document,
206 /// provided by a user.
207 ///
208 /// The file can be decrypted and verified
209 /// using the accompanying [`EncryptedCredentials`].
210 pub reverse_side: PassportFile,
211 /// An array of encrypted files with translated
212 /// versions of documents provided by a user.
213 ///
214 /// Files can be decrypted and verified
215 /// using the accompanying [`EncryptedCredentials`].
216 pub translation: Option<Vec<PassportFile>>,
217}
218
219impl EncryptedPassportElementDriverLicense {
220 /// Creates a new `EncryptedPassportElementDriverLicense`.
221 ///
222 /// # Arguments
223 ///
224 /// * `data` - An encrypted data provided by a user.
225 /// * `hash` - An element hash.
226 /// * `front_side` - An encrypted file with a front side of a document.
227 /// * `reverse_side` - An encrypted file with a reverse side of a document.
228 /// * `selfie` - An encrypted file with a selfie of a user.
229 pub fn new<A, B>(
230 data: A,
231 hash: B,
232 front_side: PassportFile,
233 reverse_side: PassportFile,
234 selfie: PassportFile,
235 ) -> Self
236 where
237 A: Into<String>,
238 B: Into<String>,
239 {
240 Self {
241 data: data.into(),
242 front_side,
243 hash: hash.into(),
244 selfie,
245 reverse_side,
246 translation: None,
247 }
248 }
249
250 /// Sets a new translation.
251 ///
252 /// # Arguments
253 ///
254 /// * `value` - An array of encrypted files with translated versions of documents.
255 pub fn with_translation<T>(mut self, value: T) -> Self
256 where
257 T: IntoIterator<Item = PassportFile>,
258 {
259 self.translation = Some(value.into_iter().collect());
260 self
261 }
262}
263
264/// Represents an E-Mail.
265#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
266pub struct EncryptedPassportElementEmail {
267 /// A user's verified email address.
268 pub email: String,
269 /// A base64-encoded element hash for
270 /// using in [`crate::types::PassportElementError::unspecified`].
271 pub hash: String,
272}
273
274impl EncryptedPassportElementEmail {
275 /// Creates a new `EncryptedPassportElementEmail`.
276 ///
277 /// # Arguments
278 ///
279 /// * `email` - A user's verified email address.
280 /// * `hash` - An element hash.
281 pub fn new<A, B>(email: A, hash: B) -> Self
282 where
283 A: Into<String>,
284 B: Into<String>,
285 {
286 Self {
287 email: email.into(),
288 hash: hash.into(),
289 }
290 }
291}
292
293/// Represents an identity card.
294#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
295#[serde_with::skip_serializing_none]
296pub struct EncryptedPassportElementIdentityCard {
297 /// A base64-encoded encrypted
298 /// Telegram Passport element data provided by a user.
299 ///
300 /// Can be decrypted and verified using
301 /// the accompanying [`EncryptedCredentials`].
302 pub data: String,
303 /// An encrypted file with a front side
304 /// of a document, provided by a user.
305 ///
306 /// The file can be decrypted and verified
307 /// using the accompanying [`EncryptedCredentials`].
308 pub front_side: PassportFile,
309 /// A base64-encoded element hash for
310 /// using in [`crate::types::PassportElementError::unspecified`].
311 pub hash: String,
312 /// An encrypted file with a reverse side of a document,
313 /// provided by a user.
314 ///
315 /// The file can be decrypted and verified
316 /// using the accompanying [`EncryptedCredentials`].
317 pub reverse_side: PassportFile,
318 /// An encrypted file with a selfie of a user
319 /// holding a document, provided by a user.
320 ///
321 /// The file can be decrypted and verified
322 /// using the accompanying [`EncryptedCredentials`].
323 pub selfie: PassportFile,
324 /// An array of encrypted files with translated
325 /// versions of documents provided by a user.
326 ///
327 /// Files can be decrypted and verified
328 /// using the accompanying [`EncryptedCredentials`].
329 pub translation: Option<Vec<PassportFile>>,
330}
331
332impl EncryptedPassportElementIdentityCard {
333 /// Creates a new `EncryptedPassportElementIdentityCard`.
334 ///
335 /// # Arguments
336 ///
337 /// * `data` - An encrypted data provided by a user.
338 /// * `hash` - An element hash.
339 /// * `front_side` - An encrypted file with a front side of a document.
340 /// * `reverse_side` - An encrypted file with a reverse side of a document.
341 /// * `selfie` - An encrypted file with a selfie of a user.
342 pub fn new<A, B>(
343 data: A,
344 hash: B,
345 front_side: PassportFile,
346 reverse_side: PassportFile,
347 selfie: PassportFile,
348 ) -> Self
349 where
350 A: Into<String>,
351 B: Into<String>,
352 {
353 Self {
354 data: data.into(),
355 front_side,
356 hash: hash.into(),
357 reverse_side,
358 selfie,
359 translation: None,
360 }
361 }
362
363 /// Sets a new translation.
364 ///
365 /// # Arguments
366 ///
367 /// * `value` - An array of encrypted files with translated versions of documents.
368 pub fn with_translation<T>(mut self, value: T) -> Self
369 where
370 T: IntoIterator<Item = PassportFile>,
371 {
372 self.translation = Some(value.into_iter().collect());
373 self
374 }
375}
376
377/// Represents an internal passport.
378#[serde_with::skip_serializing_none]
379#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
380pub struct EncryptedPassportElementInternalPassport {
381 /// A base64-encoded encrypted
382 /// Telegram Passport element data provided by a user.
383 ///
384 /// Can be decrypted and verified using
385 /// the accompanying [`EncryptedCredentials`].
386 pub data: String,
387 /// An encrypted file with a front side
388 /// of a document, provided by a user.
389 ///
390 /// The file can be decrypted and verified
391 /// using the accompanying [`EncryptedCredentials`].
392 pub front_side: PassportFile,
393 /// A base64-encoded element hash for
394 /// using in [`crate::types::PassportElementError::unspecified`].
395 pub hash: String,
396 /// An encrypted file with a selfie of a user
397 /// holding a document, provided by a user.
398 ///
399 /// The file can be decrypted and verified
400 /// using the accompanying [`EncryptedCredentials`].
401 pub selfie: PassportFile,
402 /// An array of encrypted files with translated
403 /// versions of documents provided by a user.
404 ///
405 /// Files can be decrypted and verified
406 /// using the accompanying [`EncryptedCredentials`].
407 pub translation: Option<Vec<PassportFile>>,
408}
409
410impl EncryptedPassportElementInternalPassport {
411 /// Creates a new `EncryptedPassportElementInternalPassport`.
412 ///
413 /// # Arguments
414 ///
415 /// * `data` - An encrypted data provided by a user.
416 /// * `hash` - An element hash.
417 /// * `front_side` - An encrypted file with a front side of a document.
418 /// * `selfie` - An Encrypted file with a selfie of a user.
419 pub fn new<A, B>(data: A, hash: B, front_side: PassportFile, selfie: PassportFile) -> Self
420 where
421 A: Into<String>,
422 B: Into<String>,
423 {
424 Self {
425 data: data.into(),
426 front_side,
427 hash: hash.into(),
428 selfie,
429 translation: None,
430 }
431 }
432
433 /// Sets a new translation.
434 ///
435 /// # Arguments
436 ///
437 /// * `value` - An array of encrypted files with translated versions of documents.
438 pub fn with_translation<T>(mut self, value: T) -> Self
439 where
440 T: IntoIterator<Item = PassportFile>,
441 {
442 self.translation = Some(value.into_iter().collect());
443 self
444 }
445}
446
447/// Represents a passport.
448#[serde_with::skip_serializing_none]
449#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
450pub struct EncryptedPassportElementPassport {
451 /// A base64-encoded encrypted
452 /// Telegram Passport element data provided by a user.
453 ///
454 /// Can be decrypted and verified using
455 /// the accompanying [`EncryptedCredentials`].
456 pub data: String,
457 /// An encrypted file with a front side
458 /// of the document, provided by a user.
459 ///
460 /// The file can be decrypted and verified
461 /// using the accompanying [`EncryptedCredentials`].
462 pub front_side: PassportFile,
463 /// Base64-encoded element hash for
464 /// using in [`crate::types::PassportElementError::unspecified`].
465 pub hash: String,
466 /// An encrypted file with a selfie of a user
467 /// holding a document, provided by a user.
468 ///
469 /// The file can be decrypted and verified
470 /// using the accompanying [`EncryptedCredentials`].
471 pub selfie: PassportFile,
472 /// An array of encrypted files with translated
473 /// versions of documents provided by a user.
474 ///
475 /// Files can be decrypted and verified
476 /// using the accompanying [`EncryptedCredentials`].
477 pub translation: Option<Vec<PassportFile>>,
478}
479
480impl EncryptedPassportElementPassport {
481 /// Creates a new `EncryptedPassportElementPassport`.
482 ///
483 /// # Arguments
484 ///
485 /// * `data` - An encrypted data provided by a user.
486 /// * `hash` - An element hash.
487 /// * `front_side` - An encrypted file with a front side of a document.
488 /// * `selfie` - An encrypted file with a selfie of a user.
489 pub fn new<A, B>(data: A, hash: B, front_side: PassportFile, selfie: PassportFile) -> Self
490 where
491 A: Into<String>,
492 B: Into<String>,
493 {
494 Self {
495 data: data.into(),
496 front_side,
497 hash: hash.into(),
498 selfie,
499 translation: None,
500 }
501 }
502
503 /// Sets a new translation.
504 ///
505 /// # Arguments
506 ///
507 /// * `value` - An array of encrypted files with translated versions of documents.
508 pub fn with_translation<T>(mut self, value: T) -> Self
509 where
510 T: IntoIterator<Item = PassportFile>,
511 {
512 self.translation = Some(value.into_iter().collect());
513 self
514 }
515}
516
517/// Represents a passport registration.
518#[serde_with::skip_serializing_none]
519#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
520pub struct EncryptedPassportElementPassportRegistration {
521 /// Array of encrypted files with
522 /// documents provided by a user.
523 ///
524 /// Files can be decrypted and verified
525 /// using the accompanying [`EncryptedCredentials`].
526 pub files: Vec<PassportFile>,
527 /// Base64-encoded element hash for
528 /// using in [`crate::types::PassportElementError::unspecified`].
529 pub hash: String,
530 /// Array of encrypted files with translated
531 /// versions of documents provided by a user.
532 ///
533 /// Files can be decrypted and verified
534 /// using the accompanying [`EncryptedCredentials`].
535 pub translation: Option<Vec<PassportFile>>,
536}
537
538impl EncryptedPassportElementPassportRegistration {
539 /// Creates a new `EncryptedPassportElementPassportRegistration`.
540 ///
541 /// # Arguments
542 ///
543 /// * `files` - An array of encrypted files with documents.
544 /// * `hash` - An element hash.
545 pub fn new<A, B>(files: A, hash: B) -> Self
546 where
547 A: IntoIterator<Item = PassportFile>,
548 B: Into<String>,
549 {
550 Self {
551 files: files.into_iter().collect(),
552 hash: hash.into(),
553 translation: None,
554 }
555 }
556
557 /// Sets a new translation.
558 ///
559 /// # Arguments
560 ///
561 /// * `value` - An array of encrypted files with translated versions of documents.
562 pub fn with_translation<T>(mut self, value: T) -> Self
563 where
564 T: IntoIterator<Item = PassportFile>,
565 {
566 self.translation = Some(value.into_iter().collect());
567 self
568 }
569}
570
571/// Represents personal details.
572#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
573pub struct EncryptedPassportElementPersonalDetails {
574 /// A base64-encoded encrypted
575 /// Telegram Passport element data provided by a user.
576 ///
577 /// Can be decrypted and verified using
578 /// the accompanying [`EncryptedCredentials`].
579 pub data: String,
580 /// A base64-encoded element hash for
581 /// using in [`crate::types::PassportElementError::unspecified`].
582 pub hash: String,
583}
584
585impl EncryptedPassportElementPersonalDetails {
586 /// Creates a new `EncryptedPassportElementPersonalDetails`.
587 ///
588 /// # Arguments
589 ///
590 /// * `data` - An encrypted data provided by a user.
591 /// * `hash` - An element hash.
592 pub fn new<A, B>(data: A, hash: B) -> Self
593 where
594 A: Into<String>,
595 B: Into<String>,
596 {
597 Self {
598 data: data.into(),
599 hash: hash.into(),
600 }
601 }
602}
603
604/// Represents a phone number.
605#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
606pub struct EncryptedPassportElementPhoneNumber {
607 /// A base64-encoded element hash for.
608 /// using in [`crate::types::PassportElementError::unspecified`]
609 pub hash: String,
610 /// A user's verified phone number.
611 pub phone_number: String,
612}
613
614impl EncryptedPassportElementPhoneNumber {
615 /// Creates a new `EncryptedPassportElementPhoneNumber`.
616 ///
617 /// # Arguments
618 ///
619 /// * `hash` - An element hash.
620 /// * `phone_number` - A user's verified phone number.
621 pub fn new<A, B>(hash: A, phone_number: B) -> Self
622 where
623 A: Into<String>,
624 B: Into<String>,
625 {
626 Self {
627 hash: hash.into(),
628 phone_number: phone_number.into(),
629 }
630 }
631}
632
633/// Represents a rental agreement.
634#[serde_with::skip_serializing_none]
635#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
636pub struct EncryptedPassportElementRentalAgreement {
637 /// An array of encrypted files with
638 /// documents provided by a user.
639 ///
640 /// Files can be decrypted and verified
641 /// using the accompanying [`EncryptedCredentials`].
642 pub files: Vec<PassportFile>,
643 /// A base64-encoded element hash for
644 /// using in [`crate::types::PassportElementError::unspecified`].
645 pub hash: String,
646 /// An array of encrypted files with translated
647 /// versions of documents provided by a user.
648 ///
649 /// Files can be decrypted and verified
650 /// using the accompanying [`EncryptedCredentials`].
651 pub translation: Option<Vec<PassportFile>>,
652}
653
654impl EncryptedPassportElementRentalAgreement {
655 /// Creates a new `EncryptedPassportElementRentalAgreement`.
656 ///
657 /// # Arguments
658 ///
659 /// * `files` - An array of encrypted files with documents.
660 /// * `hash` - An element hash.
661 pub fn new<A, B>(files: A, hash: B) -> Self
662 where
663 A: IntoIterator<Item = PassportFile>,
664 B: Into<String>,
665 {
666 Self {
667 files: files.into_iter().collect(),
668 hash: hash.into(),
669 translation: None,
670 }
671 }
672
673 /// Sets a new translation.
674 ///
675 /// # Arguments
676 ///
677 /// * `value` - An array of encrypted files with translated versions of documents.
678 pub fn with_translation<T>(mut self, value: T) -> Self
679 where
680 T: IntoIterator<Item = PassportFile>,
681 {
682 self.translation = Some(value.into_iter().collect());
683 self
684 }
685}
686
687/// Represents a temporary registration.
688#[serde_with::skip_serializing_none]
689#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
690pub struct EncryptedPassportElementTemporaryRegistration {
691 /// Array of encrypted files with
692 /// documents provided by a user.
693 ///
694 /// Files can be decrypted and verified
695 /// using the accompanying [`EncryptedCredentials`].
696 pub files: Vec<PassportFile>,
697 /// Base64-encoded element hash for
698 /// using in [`crate::types::PassportElementError::unspecified`].
699 pub hash: String,
700 /// Array of encrypted files with translated
701 /// versions of documents provided by a user.
702 ///
703 /// Files can be decrypted and verified
704 /// using the accompanying [`EncryptedCredentials`].
705 pub translation: Option<Vec<PassportFile>>,
706}
707
708impl EncryptedPassportElementTemporaryRegistration {
709 /// Creates a new `EncryptedPassportElementTemporaryRegistration`.
710 ///
711 /// # Arguments
712 ///
713 /// * `files` - An array of encrypted files with documents.
714 /// * `hash` - An element hash.
715 pub fn new<A, B>(files: A, hash: B) -> Self
716 where
717 A: IntoIterator<Item = PassportFile>,
718 B: Into<String>,
719 {
720 Self {
721 files: files.into_iter().collect(),
722 hash: hash.into(),
723 translation: None,
724 }
725 }
726
727 /// Sets a new translation.
728 ///
729 /// # Arguments
730 ///
731 /// * `value` - An array of encrypted files with translated versions of documents.
732 pub fn with_translation<T>(mut self, value: T) -> Self
733 where
734 T: IntoIterator<Item = PassportFile>,
735 {
736 self.translation = Some(value.into_iter().collect());
737 self
738 }
739}
740
741/// Represents an utility bill.
742#[serde_with::skip_serializing_none]
743#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
744pub struct EncryptedPassportElementUtilityBill {
745 /// Array of encrypted files with
746 /// documents provided by a user.
747 ///
748 /// Files can be decrypted and verified
749 /// using the accompanying [`EncryptedCredentials`].
750 pub files: Vec<PassportFile>,
751 /// Base64-encoded element hash for
752 /// using in [`crate::types::PassportElementError::unspecified`].
753 pub hash: String,
754 /// Array of encrypted files with translated
755 /// versions of documents provided by a user.
756 ///
757 /// Files can be decrypted and verified
758 /// using the accompanying [`EncryptedCredentials`].
759 pub translation: Option<Vec<PassportFile>>,
760}
761
762impl EncryptedPassportElementUtilityBill {
763 /// Creates a new `EncryptedPassportElementUtilityBill`.
764 ///
765 /// # Arguments
766 ///
767 /// * `files` - An array of encrypted files with documents.
768 /// * `hash` - An element hash.
769 pub fn new<A, B>(files: A, hash: B) -> Self
770 where
771 A: IntoIterator<Item = PassportFile>,
772 B: Into<String>,
773 {
774 Self {
775 files: files.into_iter().collect(),
776 hash: hash.into(),
777 translation: None,
778 }
779 }
780
781 /// Sets a new translation.
782 ///
783 /// # Arguments
784 ///
785 /// * `value` - An array of encrypted files with translated versions of documents.
786 pub fn with_translation<T>(mut self, value: T) -> Self
787 where
788 T: IntoIterator<Item = PassportFile>,
789 {
790 self.translation = Some(value.into_iter().collect());
791 self
792 }
793}
794
795/// Represents an information about documents
796/// or other Telegram Passport elements shared with a bot by a user.
797#[derive(Clone, Debug, derive_more::From, Deserialize, PartialEq, PartialOrd, Serialize)]
798#[allow(clippy::large_enum_variant)]
799#[serde(rename_all = "snake_case")]
800#[serde(tag = "type")]
801pub enum EncryptedPassportElement {
802 /// Represents an address.
803 Address(EncryptedPassportElementAddress),
804 /// Represents a bank statement.
805 BankStatement(EncryptedPassportElementBankStatement),
806 /// Represents a driver license.
807 DriverLicense(EncryptedPassportElementDriverLicense),
808 /// Represents an E-Mail.
809 Email(EncryptedPassportElementEmail),
810 /// Represents an identity card.
811 IdentityCard(EncryptedPassportElementIdentityCard),
812 /// Represents an internal passport.
813 InternalPassport(EncryptedPassportElementInternalPassport),
814 /// Represents a passport.
815 Passport(EncryptedPassportElementPassport),
816 /// Represents a passport registration.
817 PassportRegistration(EncryptedPassportElementPassportRegistration),
818 /// Represents personal details.
819 PersonalDetails(EncryptedPassportElementPersonalDetails),
820 /// Represents a phone number.
821 PhoneNumber(EncryptedPassportElementPhoneNumber),
822 /// Represents a rental agreement.
823 RentalAgreement(EncryptedPassportElementRentalAgreement),
824 /// Represents a temporary registration.
825 TemporaryRegistration(EncryptedPassportElementTemporaryRegistration),
826 /// Represents a utility bill.
827 UtilityBill(EncryptedPassportElementUtilityBill),
828}
829
830/// Represents a type of an encrypted passport element.
831#[derive(Clone, Copy, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
832#[serde(rename_all = "snake_case")]
833pub enum EncryptedPassportElementType {
834 /// Address.
835 Address,
836 /// Bank statement.
837 BankStatement,
838 /// Driver license.
839 DriverLicense,
840 /// E-Mail.
841 Email,
842 /// Identity card.
843 IdentityCard,
844 /// Internal passport.
845 InternalPassport,
846 /// Passport.
847 Passport,
848 /// Passport registration.
849 PassportRegistration,
850 /// Personal details.
851 PersonalDetails,
852 /// Phone number.
853 PhoneNumber,
854 /// Rental agreement.
855 RentalAgreement,
856 /// Temporary registration.
857 TemporaryRegistration,
858 /// Utility bill.
859 UtilityBill,
860}
861
862/// Represents a telegram Passport data shared with a bot by a user.
863#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
864pub struct PassportData {
865 /// An encrypted credentials required to decrypt the data.
866 pub credentials: EncryptedCredentials,
867 /// An array with information about documents
868 /// and other Telegram Passport elements
869 /// that was shared with a bot.
870 pub data: Vec<EncryptedPassportElement>,
871}
872
873impl PassportData {
874 /// Creates a new `PassportData`.
875 ///
876 /// # Arguments
877 ///
878 /// * `credentials` - An Encrypted credentials required to decrypt the data.
879 /// * `data` - An array with information about documents.
880 pub fn new<T>(credentials: EncryptedCredentials, data: T) -> Self
881 where
882 T: IntoIterator<Item = EncryptedPassportElement>,
883 {
884 Self {
885 credentials,
886 data: data.into_iter().collect(),
887 }
888 }
889}