ezk_sip_auth/
lib.rs

1use sip_types::msg::{RequestLine, StatusLine};
2use sip_types::Headers;
3use std::error::Error;
4use std::fmt::Debug;
5
6mod digest;
7
8pub use digest::{DigestAuthenticator, DigestCredentials, DigestError, DigestUser};
9
10/// SIP request authenticator
11pub trait ClientAuthenticator {
12    type Error: Error + Debug;
13
14    /// Modify a request's header to add the required authorization
15    ///
16    /// Implementations like Digest will do nothing here before receiving a rejection response
17    fn authorize_request(&mut self, request: &mut Headers);
18
19    /// Handle a rejection request
20    ///
21    /// Must return an error when no more requests should be sent
22    fn handle_rejection(
23        &mut self,
24        rejected_request: RequestParts<'_>,
25        reject_response: ResponseParts<'_>,
26    ) -> Result<(), Self::Error>;
27}
28
29/// Information about the request that has to be authenticated
30#[derive(Debug, Clone, Copy)]
31pub struct RequestParts<'s> {
32    pub line: &'s RequestLine,
33    pub headers: &'s Headers,
34    pub body: &'s [u8],
35}
36
37/// Information about the response that rejection the authentication
38pub struct ResponseParts<'s> {
39    pub line: &'s StatusLine,
40    pub headers: &'s Headers,
41    pub body: &'s [u8],
42}