rustigram_types/passport.rs
1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, Serialize, Deserialize)]
4/// Data submitted by a user via Telegram Passport.
5pub struct PassportData {
6 /// Array of encrypted passport elements.
7 pub data: Vec<EncryptedPassportElement>,
8 /// Encrypted credentials required to decrypt the data.
9 pub credentials: EncryptedCredentials,
10}
11
12#[derive(Debug, Clone, Serialize, Deserialize)]
13/// An encrypted element containing Telegram Passport data.
14pub struct EncryptedPassportElement {
15 /// Element type (e.g. `"passport"`, `"email"`, `"phone_number"`).
16 #[serde(rename = "type")]
17 pub kind: String,
18 /// Base64-encoded encrypted Telegram Passport element data.
19 pub data: Option<String>,
20 /// User's verified phone number.
21 pub phone_number: Option<String>,
22 /// User's verified email address.
23 pub email: Option<String>,
24 /// Array of encrypted files with documents.
25 pub files: Option<Vec<crate::file::PassportFile>>,
26 /// Encrypted file with the front side of the document.
27 pub front_side: Option<crate::file::PassportFile>,
28 /// Encrypted file with the reverse side of the document.
29 pub reverse_side: Option<crate::file::PassportFile>,
30 /// Encrypted file with a selfie of the user holding the document.
31 pub selfie: Option<crate::file::PassportFile>,
32 /// Array of encrypted files with translated versions of the document.
33 pub translation: Option<Vec<crate::file::PassportFile>>,
34 /// Base64-encoded element hash for error validation.
35 pub hash: String,
36}
37
38#[derive(Debug, Clone, Serialize, Deserialize)]
39/// Credentials required to decrypt and authenticate Telegram Passport data.
40pub struct EncryptedCredentials {
41 /// Base64-encoded encrypted JSON credentials.
42 pub data: String,
43 /// Base64-encoded data hash for authentication.
44 pub hash: String,
45 /// Base64-encoded secret, encrypted with the bot's public RSA key.
46 pub secret: String,
47}
48
49#[derive(Debug, Clone, Serialize, Deserialize)]
50#[serde(tag = "source")]
51/// An error in one of the fields provided by the user via Telegram Passport.
52pub enum PassportElementError {
53 /// Error in one of the data fields.
54 #[serde(rename = "data")]
55 DataField {
56 /// Element type that has the error.
57 r#type: String,
58 /// Name of the data field with the error.
59 field_name: String,
60 /// Base64-encoded data hash.
61 data_hash: String,
62 /// Error message.
63 message: String,
64 },
65 /// Error in the front side of the document.
66 #[serde(rename = "front_side")]
67 FrontSide {
68 /// Element type that has the error.
69 r#type: String,
70 /// Base64-encoded file hash.
71 file_hash: String,
72 /// Error message.
73 message: String,
74 },
75 /// Error in the reverse side of the document.
76 #[serde(rename = "reverse_side")]
77 ReverseSide {
78 /// Element type that has the error.
79 r#type: String,
80 /// Base64-encoded file hash.
81 file_hash: String,
82 /// Error message.
83 message: String,
84 },
85 /// Error in the selfie photo.
86 #[serde(rename = "selfie")]
87 Selfie {
88 /// Element type that has the error.
89 r#type: String,
90 /// Base64-encoded file hash.
91 file_hash: String,
92 /// Error message.
93 message: String,
94 },
95 /// Error in one of the uploaded files.
96 #[serde(rename = "file")]
97 File {
98 /// Element type that has the error.
99 r#type: String,
100 /// Base64-encoded file hash.
101 file_hash: String,
102 /// Error message.
103 message: String,
104 },
105 /// Error in a list of uploaded files.
106 #[serde(rename = "files")]
107 Files {
108 /// Element type that has the error.
109 r#type: String,
110 /// Base64-encoded file hashes.
111 file_hashes: Vec<String>,
112 /// Error message.
113 message: String,
114 },
115 /// Error in one of the translation files.
116 #[serde(rename = "translation_file")]
117 TranslationFile {
118 /// Element type that has the error.
119 r#type: String,
120 /// Base64-encoded file hash.
121 file_hash: String,
122 /// Error message.
123 message: String,
124 },
125 /// Error in a list of translation files.
126 #[serde(rename = "translation_files")]
127 TranslationFiles {
128 /// Element type that has the error.
129 r#type: String,
130 /// Base64-encoded file hashes.
131 file_hashes: Vec<String>,
132 /// Error message.
133 message: String,
134 },
135 /// Error in an unspecified place.
136 #[serde(rename = "unspecified")]
137 Unspecified {
138 /// Element type that has the error.
139 r#type: String,
140 /// Base64-encoded element hash.
141 element_hash: String,
142 /// Error message.
143 message: String,
144 },
145}