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§
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
Sourcefn requires_session_key(&self) -> bool
fn requires_session_key(&self) -> bool
Returns whether this protocol version requires session key negotiation.
Sourcefn encrypt_session_key(
&self,
session_key: &[u8],
cipher: &TuyaCipher,
nonce: &[u8],
) -> Result<Vec<u8>>
fn encrypt_session_key( &self, session_key: &[u8], cipher: &TuyaCipher, nonce: &[u8], ) -> Result<Vec<u8>>
Encrypts the session key according to protocol version requirements.
Sourcefn get_prefix(&self) -> u32
fn get_prefix(&self) -> u32
Returns the message prefix (e.g., 0x55AA or 0x6699) for this protocol version.
Sourcefn get_hmac_key<'a>(&self, cipher_key: &'a [u8]) -> Option<&'a [u8]>
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.
Sourcefn is_empty_payload_allowed(&self, cmd: u32) -> bool
fn is_empty_payload_allowed(&self, cmd: u32) -> bool
Returns whether an empty payload is allowed for the given command.
Sourcefn should_check_dev22_fallback(&self) -> bool
fn should_check_dev22_fallback(&self) -> bool
Returns whether the protocol should attempt dev22 fallback on error.
Provided Methods§
Sourcefn prepare_session_key_negotiation(&self) -> Vec<u8> ⓘ
fn prepare_session_key_negotiation(&self) -> Vec<u8> ⓘ
Step 1: Prepare local nonce for session key negotiation.