Skip to main content

rama_net/user/credentials/
proxy.rs

1use core::fmt;
2
3use super::{Basic, Bearer};
4
5use rama_core::extensions::Extension;
6
7#[derive(Debug, Clone, Extension)]
8#[extension(tags(net, proxy))]
9/// Extension wrapper that can be used by
10/// Deep Protocol Inspection (DPI) services which
11/// processed an exchanged [`ProxyCredential`].
12pub struct DpiProxyCredential(pub ProxyCredential);
13
14#[derive(Debug, Clone, PartialEq, Eq)]
15/// Proxy credentials.
16pub enum ProxyCredential {
17    /// [`Basic`]` credentials.
18    Basic(Basic),
19    /// [`Bearer`] credentials.
20    Bearer(Bearer),
21}
22
23impl From<Basic> for ProxyCredential {
24    fn from(basic: Basic) -> Self {
25        Self::Basic(basic)
26    }
27}
28
29impl From<Bearer> for ProxyCredential {
30    fn from(bearer: Bearer) -> Self {
31        Self::Bearer(bearer)
32    }
33}
34
35impl fmt::Display for ProxyCredential {
36    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
37        match self {
38            Self::Basic(basic) => basic.fmt(f),
39            Self::Bearer(bearer) => bearer.fmt(f),
40        }
41    }
42}