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
use serde::{Deserialize, Serialize}; /// Contains data required for decrypting and authenticating /// [`EncryptedPassportElement`]. /// /// See the [Telegram Passport Documentation] for a complete description of the /// data decryption and authentication processes. /// /// [The official docs](https://core.telegram.org/bots/api#encryptedcredentials). /// /// [`EncryptedPassportElement`]: /// crate::types::EncryptedPassportElement /// [Telegram Passport Documentation]: https://core.telegram.org/passport#receiving-information #[serde_with_macros::skip_serializing_none] #[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)] pub struct EncryptedCredentials { /// Base64-encoded encrypted JSON-serialized data with unique user's /// payload, data hashes and secrets required for /// [`EncryptedPassportElement`] decryption and authentication. /// /// [`EncryptedPassportElement`]: /// crate::types::EncryptedPassportElement pub data: String, // TODO: check base64 type /// Base64-encoded data hash for data authentication. pub hash: String, /// A base64-encoded secret, encrypted with the bot's public RSA key, /// required for data decryption. pub secret: String, } #[cfg(test)] mod tests { use super::*; #[test] fn must_serialize_encrypted_credentials_to_json() { // given let expected_json = r#" { "data":"someData", "hash":"1122", "secret":"secret" }"# .replace("\n", "") .replace(" ", ""); let encrypted_credentials = EncryptedCredentials { data: "someData".to_string(), hash: "1122".to_string(), secret: "secret".to_string(), }; // when let actual_json = serde_json::to_string(&encrypted_credentials).unwrap(); //then assert_eq!(actual_json, expected_json) } }