Skip to main content

confluent_kafka/admin/
scram_credential_info.rs

1// Copyright 2025 Confluent Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! Mechanism and iterations for a SASL/SCRAM credential.
16
17use super::ScramMechanism;
18
19/// Mechanism and iterations for a SASL/SCRAM credential associated with a user.
20///
21/// See [KIP-554: Add Broker-side SCRAM Config API](https://cwiki.apache.org/confluence/display/KAFKA/KIP-554%3A+Add+Broker-side+SCRAM+Config+API).
22#[derive(Debug, Clone, PartialEq, Eq, Hash)]
23#[doc(alias = "org.apache.kafka.clients.admin.ScramCredentialInfo")]
24pub struct ScramCredentialInfo {
25    mechanism: ScramMechanism,
26    iterations: i32,
27}
28
29impl ScramCredentialInfo {
30    /// Creates a new credential info.
31    ///
32    /// # Arguments
33    ///
34    /// - `mechanism` - the required mechanism
35    /// - `iterations` - the number of iterations used when creating the credential
36    #[doc(alias = "org.apache.kafka.clients.admin.ScramCredentialInfo#ScramCredentialInfo")]
37    pub fn new(mechanism: ScramMechanism, iterations: i32) -> Self {
38        Self { mechanism, iterations }
39    }
40
41    /// Returns the mechanism.
42    #[doc(alias = "org.apache.kafka.clients.admin.ScramCredentialInfo#mechanism")]
43    pub fn mechanism(&self) -> ScramMechanism {
44        self.mechanism
45    }
46
47    /// Returns the number of iterations used when creating the credential.
48    #[doc(alias = "org.apache.kafka.clients.admin.ScramCredentialInfo#iterations")]
49    pub fn iterations(&self) -> i32 {
50        self.iterations
51    }
52}
53
54impl std::fmt::Display for ScramCredentialInfo {
55    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
56        write!(
57            f,
58            "ScramCredentialInfo{{mechanism={:?}, iterations={}}}",
59            self.mechanism, self.iterations
60        )
61    }
62}
63
64#[cfg(test)]
65mod tests {
66    use super::*;
67
68    #[test]
69    fn accessors_and_equality() {
70        let info = ScramCredentialInfo::new(ScramMechanism::ScramSha256, 4096);
71        assert_eq!(info.mechanism(), ScramMechanism::ScramSha256);
72        assert_eq!(info.iterations(), 4096);
73        assert_eq!(info, ScramCredentialInfo::new(ScramMechanism::ScramSha256, 4096));
74        assert_ne!(info, ScramCredentialInfo::new(ScramMechanism::ScramSha512, 4096));
75        assert_ne!(info, ScramCredentialInfo::new(ScramMechanism::ScramSha256, 8192));
76    }
77}