1use puffin::algebra::Matcher;
2use serde::{Deserialize, Serialize};
3
4use crate::tls::rustls::msgs::enums::HandshakeType;
5
6#[derive(Debug, Deserialize, Serialize, Clone, Copy, Hash, Eq, PartialEq)]
9pub enum TlsQueryMatcher {
10 ChangeCipherSpec,
11 Alert,
12 Handshake(Option<HandshakeType>),
13 ApplicationData,
14 Heartbeat,
15 ClientHelloFlight,
17 ServerHelloFlight,
19 EncryptedFlight,
21 OtherFlight,
22}
23
24impl Matcher for TlsQueryMatcher {
25 fn matches(&self, matcher: &TlsQueryMatcher) -> bool {
26 match matcher {
27 TlsQueryMatcher::Handshake(query_handshake_type) => match self {
28 TlsQueryMatcher::Handshake(handshake_type) => {
29 handshake_type.matches(query_handshake_type)
30 }
31 _ => false,
32 },
33 TlsQueryMatcher::ChangeCipherSpec => matches!(self, TlsQueryMatcher::ChangeCipherSpec),
34 TlsQueryMatcher::Alert => matches!(self, TlsQueryMatcher::Alert),
35 TlsQueryMatcher::Heartbeat => matches!(self, TlsQueryMatcher::Heartbeat),
36 TlsQueryMatcher::ApplicationData => matches!(self, TlsQueryMatcher::ApplicationData),
37 TlsQueryMatcher::ClientHelloFlight => {
38 matches!(self, TlsQueryMatcher::ClientHelloFlight)
39 }
40 TlsQueryMatcher::ServerHelloFlight => {
41 matches!(self, TlsQueryMatcher::ServerHelloFlight)
42 }
43 TlsQueryMatcher::EncryptedFlight => matches!(self, TlsQueryMatcher::EncryptedFlight),
44 TlsQueryMatcher::OtherFlight => matches!(self, TlsQueryMatcher::OtherFlight),
45 }
46 }
47
48 fn specificity(&self) -> u32 {
49 match self {
50 TlsQueryMatcher::Handshake(handshake_type) => {
51 1 + match handshake_type {
52 None => 0,
53 Some(handshake_type) => handshake_type.specificity(),
54 }
55 }
56 _ => 0,
57 }
58 }
59}