haprox_rs/protocol/autogen/
mod.rs1use autogen_alpn::{AlpnType, ALPNS_LIST};
14
15
16
17pub mod autogen_alpn;
18
19#[derive(Clone, Debug, PartialEq, Eq)]
21pub struct AlpnProtocolId
22{
23 pub ident: AlpnType,
24 pub ident_seq: &'static [u8],
25 pub ident_str: &'static str,
26 pub descr: &'static str,
27}
28
29impl AlpnProtocolId
30{
31 pub
33 fn get_by_alpn_type(altp: AlpnType) -> &'static AlpnProtocolId
34 {
35 return &ALPNS_LIST[altp as usize];
36 }
37
38 pub
41 fn get_by_ident_str(ident: &str) -> Option<&'static AlpnProtocolId>
42 {
43 let idx = ALPNS_LIST.binary_search_by_key(&ident,|v| v.ident_str).ok()?;
44
45 return Some(&ALPNS_LIST[idx]);
46 }
47
48 pub
51 fn get_by_ident_seq(ident: &[u8]) -> Option<&'static AlpnProtocolId>
52 {
53 let idx = ALPNS_LIST.binary_search_by_key(&ident,|v| v.ident_seq).ok()?;
54
55 return Some(&ALPNS_LIST[idx]);
56 }
57}
58
59#[cfg(test)]
60mod tests
61{
62 use crate::protocol::autogen::autogen_alpn::AlpnType;
63
64 use super::AlpnProtocolId;
65
66 #[test]
67 fn test_get_by_ident_str()
68 {
69 let a1 = AlpnProtocolId::get_by_ident_str("h2c");
70 assert_eq!(Some(AlpnProtocolId::get_by_alpn_type(AlpnType::Http2OverTcp)), a1);
71
72 let a1 = AlpnProtocolId::get_by_ident_str("http/1.0");
73 assert_eq!(Some(AlpnProtocolId::get_by_alpn_type(AlpnType::Http10)), a1);
74
75 let a1 = AlpnProtocolId::get_by_ident_str("https/1.0");
76 assert_eq!(None, a1);
77
78 let a1 = AlpnProtocolId::get_by_ident_seq(b"\x68\x32\x63");
79 assert_eq!(Some(AlpnProtocolId::get_by_alpn_type(AlpnType::Http2OverTcp)), a1);
80
81 let a1 = AlpnProtocolId::get_by_ident_seq(b"\x68\x74\x74\x70\x2f\x31\x2e\x30");
82 assert_eq!(Some(AlpnProtocolId::get_by_alpn_type(AlpnType::Http10)), a1);
83 }
84}