Code cleaning.
[crypto_lab1.git] / lab1_rust / src / packet.rs
index c81fe20..8b02ccd 100644 (file)
@@ -158,19 +158,19 @@ impl Packet {
          _ => ()
       }
 
-      // Compute the MAC. It depends of the choosen variant.
+      // Computes the MAC. It depends of the choosen variant.
       let mac = crypto::compute_mac(data.slice_to(match variant { Weak => data_size, _ => data.len() }));
 
-      // Encrypt.
+      // Encrypts.
       let encrypted_data = match crypto::encrypt(data.as_slice(), iv_from_timestamp(self.timestamp).as_slice()) {
          Some(d) => d,
          _ => return Err(EncryptError)
       };
 
-      // Write packet length.
+      // Writes packet length.
       try_write_io!(output.write_be_u16((encrypted_data.len() + FIXED_PACKET_SIZE) as u16));
 
-      // Write packet type.
+      // Writes packet type.
       try_write_io!(output.write_u8(
          match self.t {
             Command(_) => 0x00,
@@ -180,13 +180,13 @@ impl Packet {
          }
       ));
 
-      // Write timestamp.
+      // Writes timestamp.
       try_write_io!(output.write_be_u64(self.timestamp));
 
-      // Write encrypted data.
+      // Writes encrypted data.
       try_write_io!(output.write(encrypted_data.as_slice()));
 
-      // Write the MAC.
+      // Writes the MAC.
       try_write_io!(output.write(mac));
 
       Ok(())
@@ -199,7 +199,7 @@ impl Packet {
 
       let data_size = try_read_io!(input.read_be_u16());
 
-      // Read and check the packet type.
+      // Reads and checks the packet type.
       let packet_type = try_read_io!(input.read_u8());
       if ![0x00, 0xFF, 0x0A, 0x0B].iter().any(|p| *p == packet_type) {
          consume(input, data_size as uint - 1);
@@ -217,7 +217,7 @@ impl Packet {
          _ => return Err(UnconsistentEncryptedSizeError)
       };
 
-      // Read the MAC.
+      // Reads the MAC.
       let mut mac_read = [0u8, ..10];
       if try_read_io!(input.read(mac_read)) != mac_read.len() {
          return Err(UnconsistentMACSizeError)
@@ -225,7 +225,7 @@ impl Packet {
 
       match variant { Fixed if mac_read != crypto::compute_mac(data.as_slice()) => return Err(MACMismatchError), _ => () };
 
-      // Control the size and the content of the padding then remove it.
+      // Controls the size and the content of the padding then removes it.
       if packet_type == 0x00 || packet_type == 0xFF {
          match data.last() {
             Some(&padding_size) => {
@@ -267,7 +267,7 @@ impl Packet {
    }
 }
 
-// Build an initialization vector: 64 * 0u8 + timestamp (128 bits).
+// Builds an initialization vector: 64 * 0u8 + timestamp (128 bits).
 fn iv_from_timestamp(timestamp: u64) -> Vec<u8> {
    let mut iv = io::MemWriter::with_capacity(16);
    let _ = iv.write_be_u64(0u64);