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