rzmq 0.5.13

High performance, fully asynchronous, safe pure-Rust implementation of ZeroMQ (ØMQ) messaging with io_uring and TCP Cork acceleration on Linux.
Documentation
use crate::{security::{framer::{ISecureFramer, NullFramer}, mechanism::ProcessTokenAction}, Metadata, ZmqError};

use super::{IDataCipher, Mechanism, MechanismStatus, cipher::PassThroughDataCipher};

#[derive(Debug)]
pub struct NullMechanism;

impl NullMechanism {
  pub const NAME_BYTES: &'static [u8; 20] = b"NULL\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"; // Padded
  pub const NAME: &'static str = "NULL";
}

impl Mechanism for NullMechanism {
  fn name(&self) -> &'static str {
    Self::NAME
  }

  fn process_token(&mut self, _token: &[u8]) -> Result<ProcessTokenAction, ZmqError> {
    // NULL mechanism does nothing with tokens and is always ready.
    Ok(ProcessTokenAction::HandshakeComplete)
  }
  fn produce_token(&mut self) -> Result<Option<Vec<u8>>, ZmqError> {
    Ok(None)
  }
  fn status(&self) -> MechanismStatus {
    MechanismStatus::Ready
  } // Null is always ready
  fn peer_identity(&self) -> Option<Vec<u8>> {
    None
  }
  fn metadata(&self) -> Option<Metadata> {
    None
  }

  fn as_any(&self) -> &dyn std::any::Any {
    self
  }

  fn set_error(&mut self, _reason: String) {
    // Null mechanism doesn't really have a failure mode during handshake itself.
    // If the engine calls this due to transport error, there's no state to change here.
  }
  fn error_reason(&self) -> Option<&str> {
    None // No error state stored
  }

  fn zap_request_needed(&mut self) -> Option<Vec<Vec<u8>>> {
    None
  }
  fn process_zap_reply(&mut self, _reply_frames: &[Vec<u8>]) -> Result<(), ZmqError> {
    Ok(())
  }

  fn into_framer(self: Box<Self>) -> Result<(Box<dyn ISecureFramer>, Option<Vec<u8>>), ZmqError> {
    // For PLAIN, the second tuple element would be self.username.clone()
    Ok((Box::new(NullFramer::new()), None))
  }
}