Data used for packet error has been modified.
[crypto_lab1.git] / src / packet.rs
index ece32c4..632d298 100644 (file)
@@ -76,10 +76,10 @@ pub enum PacketType {
 ///            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)
+///         |0000000000000000| for error packet (16 bytes length)
 ///   MMMMMMMMMM: first 10 bytes (most significant) of the HMAC-SHA256 of:
 ///      |I|C...C| for command ans answer packet
-///      |"0000000000"| for error packet
+///      |0000000000000000| for error packet
 #[deriving(Show)]
 pub struct Packet {
    pub t: PacketType,
@@ -134,7 +134,7 @@ impl Packet {
       let mut data =
          match self.t {
             Command(ref p) | Answer(ref p) => packet_data(p),
-            Error(_) => Vec::from_elem(16, '0' as u8) // Padding as data: 16 * '0'.
+            Error(_) => Vec::from_elem(16, 0) // Padding as data: 16 * 0.
          };
 
       // Compute the MAC
@@ -152,9 +152,13 @@ impl Packet {
          _ => ()
       }
 
+      println!("data not crypted: {}", data);
+
       // Encrypt.
       let encrypted_data = crypto::encrypt(data.as_slice(), iv_from_timestamp(self.timestamp).as_slice());
 
+      println!("data crypted: {}", encrypted_data);
+
       // Write packet length.
       try_write_io!(output.write_be_u16((encrypted_data.len() + FIXED_PACKET_SIZE) as u16));
 
@@ -242,7 +246,7 @@ impl Packet {
             _ => {
                if data.len() != 16 {
                   return Err(UnconsistentDataSizeError)
-               } else if data != Vec::from_elem(16, '0' as u8) {
+               } else if data != Vec::from_elem(16, 0) {
                   return Err(DataError)
                }
                match packet_type { 0x0A => Error(CryptError), _ => Error(AuthError) }