X-Git-Url: http://git.euphorik.ch/?p=crypto_lab1.git;a=blobdiff_plain;f=lab1_rust%2Fsrc%2Fpacket.rs;h=ec63d9e0e1614f355d8fdabb43d6e1b30cf5b80f;hp=4016ccb845ce9cea5513eae64c8ffe8d43de113a;hb=a8641e8dd205140af9206e82169ff5ad107c23f8;hpb=ffb9351a121dff754127787c80dff9e0bcd49848 diff --git a/lab1_rust/src/packet.rs b/lab1_rust/src/packet.rs index 4016ccb..ec63d9e 100644 --- a/lab1_rust/src/packet.rs +++ b/lab1_rust/src/packet.rs @@ -6,6 +6,7 @@ use serialize::hex::{ ToHex }; use self::PacketType::{ Command, Answer, Error }; use crypto; +#[deriving(Show, Copy)] pub enum Variant { Weak, // The MAC is computed on data without padding. Fixed // The MAC is computed on data and padding. @@ -28,7 +29,7 @@ pub enum ReadingError { // 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)) }) -) +); // There are all the errors that may occur when encrypting, authenticating and writing a packet. #[deriving(Show)] @@ -40,7 +41,7 @@ pub enum WritingError { // 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; pub type WritingResult = Result<(), WritingError>; @@ -77,12 +78,12 @@ pub enum PacketType { /// 0x0A: Decrypt error /// 0x0B: Authentication error /// TTTTTTTT: Timestamp (64 bits) -/// 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 @@ -102,7 +103,7 @@ impl fmt::Show for PacketType { match self { &Command(ref data) => write!(formatter, "Command {{ {} }}", data_to_str(data)), &Answer(ref data) => write!(formatter, "Answer {{ {} }}", data_to_str(data)), - &Error(error_type) => write!(formatter, "Error {{ errorType: {} }}", error_type) + &Error(ref error_type) => write!(formatter, "Error {{ errorType: {} }}", error_type) } } }