1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*-
* haprox-rs - a HaProxy protocol parser.
*
* Copyright 2025 (c) Aleksandr Morozov
* The scram-rs crate can be redistributed and/or modified
* under the terms of either of the following licenses:
*
* 1. the Mozilla Public License Version 2.0 (the “MPL”) OR
*
* 2. EUROPEAN UNION PUBLIC LICENCE v. 1.2 EUPL © the European Union 2007, 2016
*/
/*!
A HaProxy V2 parser.
Use the [ProxyHdrV2] to compose the header.
Use the [ProxyV2Parser] to parse the Ha proxy V2 header.
## Examples:
Composer:
```rust
use haprox_rs::{ProxyV2Addr, ProxyHdrV2, HdrV2OpProxy, ProxyTransportFam, PP2TlvClient};
let addr = ProxyV2Addr::try_from(("127.0.0.1:39754", "127.0.0.67:11883")).unwrap();
let mut comp =
ProxyHdrV2::<HdrV2OpProxy>::new(ProxyTransportFam::STREAM, addr).unwrap();
let plts = comp.set_plts();
let mut ssl = plts.add_ssl(PP2TlvClient::PP2_CLIENT_SSL, 0).unwrap();
ssl.add_ssl_sub_version("TLSv1.2").unwrap();
ssl.done().unwrap();
let pkt: Vec<u8> = comp.try_into().unwrap();
```
Parser:
```rust
use haprox_rs::{ProxyV2Addr, ProxyHdrV2, HdrV2OpProxy, ProxyTransportFam,
PP2TlvClient, ProxyV2Parser, ProtocolVersion, HdrV2Command, ProxyV2AddrType, PP2Tlvs};
use haprox_rs::protocol::protocol_raw;
use crate::haprox_rs::protocol::PP2TlvDump;
let pkt_ssl =
b"\x0d\x0a\x0d\x0a\x00\x0d\x0a\x51\x55\x49\x54\x0a\x21\x11\x00\x2a\
\x7f\x00\x00\x01\x7f\x00\x00\x43\x9d\xd2\x2e\x6b\x20\x00\x1b\x07\
\x00\x00\x00\x00\x21\x00\x07\x54\x4c\x53\x76\x31\x2e\x32\x22\x00\
\x09\x6d\x71\x74\x74\x75\x73\x65\x72\x31";
let dec = ProxyV2Parser::try_from_slice(pkt_ssl.as_slice()).unwrap();
assert_eq!(dec.get_transport().is_ok(), true);
assert_eq!(dec.get_transport().unwrap(), ProxyTransportFam::STREAM);
assert_eq!(dec.get_proto_version(), ProtocolVersion::V2);
assert_eq!(dec.get_proto_command(), HdrV2Command::PROXY);
assert_eq!(dec.get_address_family().is_ok(), true);
assert_eq!(dec.get_address_family().unwrap(), ProxyV2AddrType::AfInet);
assert_eq!(dec.get_palyload_len() as usize, pkt_ssl.len() - size_of::<protocol_raw::ProxyHdrV2>());
let addr = dec.get_address().unwrap();
assert_eq!(addr.is_some(), true);
let addr = addr.unwrap();
let maddr = ProxyV2Addr::try_from(("127.0.0.1:40402", "127.0.0.67:11883")).unwrap();
assert_eq!(addr, maddr);
let tlv_iter = dec.get_tlvs_iter();
assert_eq!(tlv_iter.is_some(), true);
let mut tlv_iter = tlv_iter.unwrap();
let type_ssl = tlv_iter.next().unwrap().take_internal().unwrap();
assert_eq!(type_ssl.get_type(), PP2Tlvs::TYPE_SSL);
let PP2Tlvs::TypeSsl { client, verify } = type_ssl else {panic!("wrong")};
assert_eq!(client, PP2TlvClient::all());
assert_eq!(verify, 0);
```
*/
extern crate bitflags;
pub extern crate byteorder;
extern crate crc32fast;
pub use crateHaProxRes;
pub use crate*;
pub use crate;
pub use crate;
pub use ;