rust_rcs_core/security/authentication/
basic.rs

1// Copyright 2023 宋昊文
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
15use super::challenge::Challenge;
16
17pub struct BasicChallengeParams<'a> {
18    pub realm: &'a [u8],
19}
20
21impl<'a> BasicChallengeParams<'a> {
22    pub fn from_challenge(challenge: Challenge<'a>) -> Option<BasicChallengeParams<'a>> {
23        for param in challenge.get_params() {
24            if param.name == b"realm" {
25                if let Some(realm) = param.value {
26                    return Some(BasicChallengeParams { realm });
27                }
28            }
29        }
30
31        None
32    }
33}