TuyaProtocol

Trait TuyaProtocol 

Source
pub trait TuyaProtocol: Send + Sync {
Show 15 methods // Required methods fn version(&self) -> Version; fn get_effective_command(&self, command: CommandType) -> u32; fn generate_payload( &self, device_id: &str, command: CommandType, data: Option<Value>, cid: Option<&str>, t: u64, ) -> Result<(u32, Value)>; fn pack_payload( &self, payload: &[u8], cmd: u32, cipher: &TuyaCipher, ) -> Result<Vec<u8>>; fn decrypt_payload( &self, payload: Vec<u8>, cipher: &TuyaCipher, ) -> Result<Vec<u8>>; fn has_version_header(&self, payload: &[u8]) -> bool; fn requires_session_key(&self) -> bool; fn encrypt_session_key( &self, session_key: &[u8], cipher: &TuyaCipher, nonce: &[u8], ) -> Result<Vec<u8>>; fn get_prefix(&self) -> u32; fn get_hmac_key<'a>(&self, cipher_key: &'a [u8]) -> Option<&'a [u8]>; fn is_empty_payload_allowed(&self, cmd: u32) -> bool; fn should_check_dev22_fallback(&self) -> bool; // Provided methods fn prepare_session_key_negotiation(&self) -> Vec<u8> { ... } fn verify_session_key_response( &self, local_nonce: &[u8], remote_payload: &[u8], local_key: &[u8], ) -> Result<Vec<u8>> { ... } fn finalize_session_key( &self, local_nonce: &[u8], remote_nonce: &[u8], local_key: &[u8], ) -> Result<(Vec<u8>, Vec<u8>)> { ... }
}

Required Methods§

Source

fn version(&self) -> Version

Source

fn get_effective_command(&self, command: CommandType) -> u32

Source

fn generate_payload( &self, device_id: &str, command: CommandType, data: Option<Value>, cid: Option<&str>, t: u64, ) -> Result<(u32, Value)>

Source

fn pack_payload( &self, payload: &[u8], cmd: u32, cipher: &TuyaCipher, ) -> Result<Vec<u8>>

Source

fn decrypt_payload( &self, payload: Vec<u8>, cipher: &TuyaCipher, ) -> Result<Vec<u8>>

Source

fn has_version_header(&self, payload: &[u8]) -> bool

Source

fn requires_session_key(&self) -> bool

Returns whether this protocol version requires session key negotiation.

Source

fn encrypt_session_key( &self, session_key: &[u8], cipher: &TuyaCipher, nonce: &[u8], ) -> Result<Vec<u8>>

Encrypts the session key according to protocol version requirements.

Source

fn get_prefix(&self) -> u32

Returns the message prefix (e.g., 0x55AA or 0x6699) for this protocol version.

Source

fn get_hmac_key<'a>(&self, cipher_key: &'a [u8]) -> Option<&'a [u8]>

Returns the HMAC key to use for message packing/unpacking, if applicable.

Source

fn is_empty_payload_allowed(&self, cmd: u32) -> bool

Returns whether an empty payload is allowed for the given command.

Source

fn should_check_dev22_fallback(&self) -> bool

Returns whether the protocol should attempt dev22 fallback on error.

Provided Methods§

Source

fn prepare_session_key_negotiation(&self) -> Vec<u8>

Step 1: Prepare local nonce for session key negotiation.

Source

fn verify_session_key_response( &self, local_nonce: &[u8], remote_payload: &[u8], local_key: &[u8], ) -> Result<Vec<u8>>

Step 2: Verify the HMAC from device response during negotiation.

Source

fn finalize_session_key( &self, local_nonce: &[u8], remote_nonce: &[u8], local_key: &[u8], ) -> Result<(Vec<u8>, Vec<u8>)>

Step 3: Calculate final session key and its HMAC for the finish message.

Implementors§