rust_rcs_core/security/authentication/
mod.rs1pub mod auth_param;
16pub mod authentication_info;
17pub mod basic;
18pub mod challenge;
19pub mod digest;
20
21use basic::BasicChallengeParams;
22use challenge::ChallengeParser;
23use digest::DigestChallengeParams;
24
25pub enum AuthenticationMethod<'a> {
26 Basic(BasicChallengeParams<'a>),
27 Digest(DigestChallengeParams<'a>),
28}
29
30pub struct AuthenticationMethods<'a> {
31 challenge_parser: ChallengeParser<'a>,
32}
33
34impl<'a> AuthenticationMethods<'a> {
35 pub fn new(s: &'a [u8]) -> AuthenticationMethods<'_> {
36 let challenge_parser = ChallengeParser::new(s);
37 AuthenticationMethods { challenge_parser }
38 }
39}
40
41impl<'a> Iterator for AuthenticationMethods<'a> {
42 type Item = AuthenticationMethod<'a>;
43 fn next(&mut self) -> Option<AuthenticationMethod<'a>> {
44 while let Some(challenge) = self.challenge_parser.next() {
45 match challenge.auth_scheme {
46 b"Basic" => {
47 if let Some(basic_challenge) = BasicChallengeParams::from_challenge(challenge) {
48 return Some(AuthenticationMethod::Basic(basic_challenge));
49 }
50 }
51
52 b"Digest" => {
53 if let Some(digest_challenge) = DigestChallengeParams::from_challenge(challenge)
54 {
55 return Some(AuthenticationMethod::Digest(digest_challenge));
56 }
57 }
58
59 _ => {}
60 }
61 }
62
63 None
64 }
65}