Skip to main content

wecomx_auth/
bot.rs

1use std::time::{SystemTime, UNIX_EPOCH};
2
3use serde::{Deserialize, Serialize};
4
5/// Bot 凭据(`botid + secret`)。
6///
7/// 序列化字段名与旧版凭据文件保持一致(`id` / `secret` / `create_time`),
8/// 保证 `credentials.enc` / `bot.enc` 的既有密文可继续解密。
9#[derive(Debug, Clone, Serialize, Deserialize)]
10pub struct BotCredential {
11    pub id: String,
12    pub secret: String,
13    pub create_time: u64,
14}
15
16impl BotCredential {
17    /// Create a new `BotCredential` with `create_time` set to the current timestamp.
18    pub fn new(id: String, secret: String) -> Self {
19        let create_time = SystemTime::now()
20            .duration_since(UNIX_EPOCH)
21            .unwrap_or_default()
22            .as_secs();
23        Self {
24            id,
25            secret,
26            create_time,
27        }
28    }
29}