pub enum Variant {
Weak, // The MAC is computed on data without padding.
Fixed // The MAC is computed on data and padding.
pub enum Variant {
Weak, // The MAC is computed on data without padding.
Fixed // The MAC is computed on data and padding.
// A macro to return a 'Err(ReadingError::IO(..))' in case of error.
macro_rules! try_read_io(
($e:expr) => (match $e { Ok(e) => e, Err(e) => return Err(ReadingError::IO(e)) })
// A macro to return a 'Err(ReadingError::IO(..))' in case of error.
macro_rules! try_read_io(
($e:expr) => (match $e { Ok(e) => e, Err(e) => return Err(ReadingError::IO(e)) })
// A macro to return a 'Err(WritingError::IO(..))' in case of error.
macro_rules! try_write_io(
($e:expr) => (match $e { Ok(e) => e, Err(e) => return Err(WritingError::IO(e)) })
// A macro to return a 'Err(WritingError::IO(..))' in case of error.
macro_rules! try_write_io(
($e:expr) => (match $e { Ok(e) => e, Err(e) => return Err(WritingError::IO(e)) })
pub type ReadingResult = Result<Packet, ReadingError>;
pub type WritingResult = Result<(), WritingError>;
pub type ReadingResult = Result<Packet, ReadingError>;
pub type WritingResult = Result<(), WritingError>;
-/// D...D: Encrypted data (AES-256 CBC mode) of:
-/// |I|C...C|P...P| for command and answer packet:
-/// I: Command ID
-/// C: Command payload (from 7 to 39 bytes)
-/// P: Padding from 1 to 16, |I|C...C|P...P| size must be a multiple of 16
-/// |0000000000000000| for error packet (16 bytes length)
+/// D...D: Encrypted data (AES-256 CBC mode) of:
+/// |I|C...C|P...P| for command and answer packet:
+/// I: Command ID
+/// C: Command payload (from 7 to 39 bytes)
+/// P: Padding from 1 to 16, |I|C...C|P...P| size must be a multiple of 16
+/// |0000000000000000| for error packet (16 bytes length)
/// MMMMMMMMMM: first 10 bytes (most significant) of the HMAC-SHA256 of:
/// for command and answer packet:
/// |I|C...C| for weak variant
/// MMMMMMMMMM: first 10 bytes (most significant) of the HMAC-SHA256 of:
/// for command and answer packet:
/// |I|C...C| for weak variant
match self {
&Command(ref data) => write!(formatter, "Command {{ {} }}", data_to_str(data)),
&Answer(ref data) => write!(formatter, "Answer {{ {} }}", data_to_str(data)),
match self {
&Command(ref data) => write!(formatter, "Command {{ {} }}", data_to_str(data)),
&Answer(ref data) => write!(formatter, "Answer {{ {} }}", data_to_str(data)),
let mut iv = io::MemWriter::with_capacity(16);
let _ = iv.write_be_u64(0u64);
let _ = iv.write_be_u64(timestamp);
let mut iv = io::MemWriter::with_capacity(16);
let _ = iv.write_be_u64(0u64);
let _ = iv.write_be_u64(timestamp);