use crate::primitives::pairing::PairingError;
pub(crate) trait PairRequestMessageExt {
fn validate(&self) -> Result<(), crate::Error>;
}
impl PairRequestMessageExt for derec_proto::PairRequestMessage {
#[allow(deprecated)]
fn validate(&self) -> Result<(), crate::Error> {
if self.mlkem_ciphertext.is_empty() {
#[cfg(feature = "logging")]
tracing::warn!("pair request missing mlkem_ciphertext");
return Err(
PairingError::InvalidPairRequestMessage("mlkem_ciphertext is empty").into(),
);
}
if self.ecies_public_key.is_empty() {
#[cfg(feature = "logging")]
tracing::warn!("pair request missing ecies_public_key");
return Err(
PairingError::InvalidPairRequestMessage("ecies_public_key is empty").into(),
);
}
let has_offers = !self.supported_transports.is_empty();
let has_singular = self
.transport_protocol
.as_ref()
.is_some_and(|tp| !tp.uri.trim().is_empty());
if !has_offers && !has_singular {
#[cfg(feature = "logging")]
tracing::warn!("pair request advertises no usable transport endpoint");
return Err(PairingError::EmptyTransportUri.into());
}
Ok(())
}
}