use crate::model::host::HostName;
#[non_exhaustive]
#[derive(Debug, Clone, Default)]
pub struct TlsInfo {
pub certificates: Vec<Vec<u8>>,
pub version: Option<&'static str>,
pub cipher_suite: Option<&'static str>,
pub alpn: Option<String>,
}
impl TlsInfo {
#[must_use]
pub fn new(certificates: Vec<Vec<u8>>) -> Self {
Self {
certificates,
..Self::default()
}
}
#[must_use]
pub fn with_version(mut self, version: &'static str) -> Self {
self.version = Some(version);
self
}
#[must_use]
pub fn with_cipher_suite(mut self, suite: &'static str) -> Self {
self.cipher_suite = Some(suite);
self
}
#[must_use]
pub fn with_alpn(mut self, alpn: impl Into<String>) -> Self {
self.alpn = Some(alpn.into());
self
}
pub fn leaf(&self) -> Option<&[u8]> {
self.certificates.first().map(Vec::as_slice)
}
}
#[non_exhaustive]
#[derive(Debug, Clone, Default)]
pub struct ResponseSet {
pub banners: Vec<String>,
pub tls: Option<TlsInfo>,
pub names: Vec<HostName>,
}
impl ResponseSet {
#[must_use]
pub fn from_banners(banners: Vec<String>) -> Self {
Self {
banners,
..Self::default()
}
}
pub(crate) fn extend(&mut self, other: ResponseSet) {
debug_assert!(other.tls.is_none(), "a handshake is not merged");
self.banners.extend(other.banners);
self.names.extend(other.names);
}
#[must_use]
pub fn with_tls(mut self, tls: TlsInfo) -> Self {
self.tls = Some(tls);
self
}
pub fn is_empty(&self) -> bool {
self.banners.is_empty() && self.tls.is_none()
}
}
#[non_exhaustive]
#[derive(Debug, Clone, Default)]
pub struct Collected {
pub frames: Vec<Vec<u8>>,
}
impl Collected {
#[must_use]
pub fn from_frames(frames: Vec<Vec<u8>>) -> Self {
Self { frames }
}
}