Skip to main content

pdk_contracts_lib/api/
credentials.rs

1// Copyright (c) 2026, Salesforce, Inc.,
2// All rights reserved.
3// For full license text, see the LICENSE.txt file
4
5use std::{
6    any::type_name,
7    fmt::{Debug, Display},
8};
9
10use zeroize::ZeroizeOnDrop;
11
12/// Represents a client ID credential.
13#[derive(Debug, Clone)]
14pub struct ClientId(String);
15
16impl ClientId {
17    /// Creates a new [ClientId] from a [String].
18    pub fn new(id: String) -> Self {
19        Self(id)
20    }
21
22    pub fn into_string(self) -> String {
23        self.0
24    }
25
26    pub fn as_str(&self) -> &str {
27        &self.0
28    }
29}
30
31impl Display for ClientId {
32    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
33        f.write_str(&self.0)
34    }
35}
36
37/// Represents a client secret credential.
38/// This type ensures secure memory management by zeroing memory on drop.
39/// [Debug] printing is safe since the internal representation is hidden.
40#[derive(Clone, ZeroizeOnDrop)]
41pub struct ClientSecret(String);
42
43impl ClientSecret {
44    /// Creates a new [ClientSecret] from a [String].
45    pub fn new(client_secret: String) -> Self {
46        Self(client_secret)
47    }
48
49    pub(crate) fn as_str(&self) -> &str {
50        self.0.as_str()
51    }
52}
53
54impl Debug for ClientSecret {
55    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
56        f.debug_tuple(type_name::<Self>())
57            .field(&"**********")
58            .finish()
59    }
60}