feophantlib/processor/
ssl_and_gssapi_parser.rs

1use hex_literal::hex;
2use nom::{bytes::complete::tag, IResult};
3
4pub fn match_ssl_request(input: &[u8]) -> IResult<&[u8], &[u8]> {
5    //From here: https://www.postgresql.org/docs/current/protocol-message-formats.html
6    tag(&hex!("04 D2 16 2F"))(input)
7}
8
9pub fn is_ssl_request(input: &[u8]) -> bool {
10    match_ssl_request(input).is_ok()
11}
12
13fn match_gssapi_request(input: &[u8]) -> IResult<&[u8], &[u8]> {
14    tag(&hex!("04 D2 16 30"))(input)
15}
16
17pub fn is_gssapi_request(input: &[u8]) -> bool {
18    match_gssapi_request(input).is_ok()
19}
20
21#[cfg(test)]
22mod tests {
23    // Note this useful idiom: importing names from outer (for mod tests) scope.
24    use super::*;
25
26    #[test]
27    fn test_ssl_match() {
28        assert!(is_ssl_request(&hex!("04 D2 16 2F")));
29    }
30
31    #[test]
32    fn test_ssl_not_match() {
33        assert!(!is_ssl_request(&hex!("12 34 56")));
34    }
35
36    #[test]
37    fn test_gsspai_match() {
38        assert!(is_gssapi_request(&hex!("04 D2 16 30")));
39    }
40}