Skip to main content

dingtalk_sdk/
auth.rs

1use std::fmt;
2
3/// Enterprise app credentials (`appkey` + `appsecret`).
4///
5/// `Debug` output redacts `appsecret`.
6#[derive(Clone, PartialEq, Eq, Hash)]
7pub struct AppCredentials {
8    appkey: String,
9    appsecret: String,
10}
11
12impl AppCredentials {
13    /// Creates credentials from app key and app secret.
14    #[must_use]
15    pub fn new(appkey: impl Into<String>, appsecret: impl Into<String>) -> Self {
16        Self {
17            appkey: appkey.into(),
18            appsecret: appsecret.into(),
19        }
20    }
21
22    /// Returns the application key.
23    #[must_use]
24    pub fn appkey(&self) -> &str {
25        &self.appkey
26    }
27
28    /// Returns the application secret.
29    #[must_use]
30    pub fn appsecret(&self) -> &str {
31        &self.appsecret
32    }
33}
34
35impl fmt::Debug for AppCredentials {
36    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
37        f.debug_struct("AppCredentials")
38            .field("appkey", &self.appkey)
39            .field("appsecret", &"<redacted>")
40            .finish()
41    }
42}