Diff
Not logged in

Differences From Artifact [10cdd58e03]:

To Artifact [459fe796ba]:


   304    304           for &i in [chunks_start, chunks_end - 1].iter().chain(&next_two) {
   305    305               if self.chunks[i].in_sequencer {
   306    306                   continue;
   307    307               }
   308    308               self.chunks[i].in_sequencer = true;
   309    309               let pos = get_start_end_positions(self.map_size, i as u32).0 as usize;
   310    310               let vec = self.decrypt_chunk(i as u32)?;
   311         -            for (p, byte) in self.sequencer
   312         -                    .iter_mut()
   313         -                    .skip(pos)
   314         -                    .zip(vec) {
          311  +            for (p, byte) in self.sequencer.iter_mut().skip(pos).zip(vec) {
   315    312                   *p = byte;
   316    313               }
   317    314           }
   318    315           for chunk in &mut self.chunks[chunks_start..chunks_end] {
   319    316               chunk.status = ChunkStatus::ToBeHashed;
   320    317               chunk.in_sequencer = true;
   321    318           }
................................................................................
   345    342           for i in chunks_start..chunks_end {
   346    343               if self.chunks[i].in_sequencer {
   347    344                   continue;
   348    345               }
   349    346               self.chunks[i].in_sequencer = true;
   350    347               let pos = get_start_end_positions(self.map_size, i as u32).0 as usize;
   351    348               let vec = self.decrypt_chunk(i as u32)?;
   352         -            for (p, byte) in self.sequencer
   353         -                    .iter_mut()
   354         -                    .skip(pos)
   355         -                    .zip(vec) {
          349  +            for (p, byte) in self.sequencer.iter_mut().skip(pos).zip(vec) {
   356    350                   *p = byte
   357    351               }
   358    352           }
   359    353           Ok(())
   360    354       }
   361    355   
   362    356       fn extend_sequencer_up_to(&mut self, new_len: u64) -> Result<(), SelfEncryptionError<E>> {
   363    357           let old_len = self.sequencer.len() as u64;
   364    358           if new_len > old_len {
   365    359               if new_len > MAX_IN_MEMORY_SIZE as u64 {
   366    360                   self.sequencer.create_mapping()?;
   367    361               } else {
   368         -                self.sequencer.extend(iter::repeat(0).take((new_len - old_len) as usize));
          362  +                self.sequencer
          363  +                    .extend(iter::repeat(0).take((new_len - old_len) as usize));
   369    364               }
   370    365           }
   371    366           Ok(())
   372    367       }
   373    368   
   374    369       fn decrypt_chunk(&self, chunk_number: u32) -> Result<Vec<u8>, SelfEncryptionError<E>> {
   375    370           let name = &self.sorted_map[chunk_number as usize].hash;
................................................................................
   377    372           let (pad, key, iv) = get_pad_key_and_iv(chunk_number, &self.sorted_map, self.map_size);
   378    373           let xor_result = xor(&content, &pad);
   379    374           let decrypted = encryption::decrypt(&xor_result, &key, &iv)?;
   380    375           let mut decompressor = BrotliDecoder::new(vec![]);
   381    376           if decompressor.write_all(&decrypted).is_err() {
   382    377               return Err(SelfEncryptionError::Compression);
   383    378           }
   384         -        decompressor.finish().map_err(|_| SelfEncryptionError::Compression)
          379  +        decompressor
          380  +            .finish()
          381  +            .map_err(|_| SelfEncryptionError::Compression)
   385    382       }
   386    383   }
   387    384   
   388    385   fn encrypt_chunk<E: StorageError>(content: &[u8],
   389    386                                     pki: (Pad, Key, Iv))
   390    387                                     -> Result<Vec<u8>, SelfEncryptionError<E>> {
   391    388       let (pad, key, iv) = pki;
................................................................................
   412    409       let n_2_pre_hash = &sorted_map[n_2 as usize].pre_hash;
   413    410   
   414    411       let mut pad = [0u8; PAD_SIZE];
   415    412       let mut key = [0u8; KEY_SIZE];
   416    413       let mut iv = [0u8; IV_SIZE];
   417    414   
   418    415       for (pad_iv_el, element) in
   419         -        pad.iter_mut().chain(iv.iter_mut()).zip(this_pre_hash.iter().chain(n_2_pre_hash.iter())) {
          416  +        pad.iter_mut()
          417  +            .chain(iv.iter_mut())
          418  +            .zip(this_pre_hash.iter().chain(n_2_pre_hash.iter())) {
   420    419           *pad_iv_el = *element;
   421    420       }
   422    421   
   423    422       for (key_el, element) in key.iter_mut().zip(n_1_pre_hash.iter()) {
   424    423           *key_el = *element;
   425    424       }
   426    425   
................................................................................
   767    766                      ((number_of_chunks * MAX_CHUNK_SIZE) as u64));
   768    767       }
   769    768   
   770    769       fn check_file_size<E: StorageError, S: Storage<E>>(se: &SelfEncryptor<E, S>,
   771    770                                                          expected_file_size: u64) {
   772    771           assert_eq!(se.file_size, expected_file_size);
   773    772           if !se.sorted_map.is_empty() {
   774         -            let chunks_cumulated_size =
   775         -                se.sorted_map.iter().fold(0u64, |acc, chunk| acc + chunk.source_size);
          773  +            let chunks_cumulated_size = se.sorted_map
          774  +                .iter()
          775  +                .fold(0u64, |acc, chunk| acc + chunk.source_size);
   776    776               assert_eq!(chunks_cumulated_size, expected_file_size);
   777    777           }
   778    778       }
   779    779   
   780    780       #[test]
   781    781       fn xor() {
   782    782           let mut data: Vec<u8> = vec![];
................................................................................
   795    795       fn write() {
   796    796           let mut storage = SimpleStorage::new();
   797    797           let mut se = SelfEncryptor::new(&mut storage, DataMap::None)
   798    798               .expect("Encryptor construction shouldn't fail.");
   799    799           let size = 3;
   800    800           let offset = 5u32;
   801    801           let the_bytes = random_bytes(size);
   802         -        se.write(&the_bytes, offset as u64).expect("Writing to encryptor shouldn't fail.");
          802  +        se.write(&the_bytes, offset as u64)
          803  +            .expect("Writing to encryptor shouldn't fail.");
   803    804           check_file_size(&se, (size + offset as usize) as u64);
   804    805       }
   805    806   
   806    807       #[test]
   807    808       fn multiple_writes() {
   808    809           let mut storage = SimpleStorage::new();
   809    810           let size1 = 3;
................................................................................
   811    812           let part1 = random_bytes(size1);
   812    813           let part2 = random_bytes(size2);
   813    814           let data_map;
   814    815           {
   815    816               let mut se = SelfEncryptor::new(&mut storage, DataMap::None)
   816    817                   .expect("First encryptor construction shouldn't fail.");
   817    818               // Just testing multiple subsequent write calls
   818         -            se.write(&part1, 0).expect("Writing part one to encryptor shouldn't fail.");
   819         -            se.write(&part2, size1 as u64).expect("Writing part two to encryptor shouldn't fail.");
          819  +            se.write(&part1, 0)
          820  +                .expect("Writing part one to encryptor shouldn't fail.");
          821  +            se.write(&part2, size1 as u64)
          822  +                .expect("Writing part two to encryptor shouldn't fail.");
   820    823               // Let's also test an overwrite.. over middle bytes of part2
   821    824               se.write(&[4u8, 2], size1 as u64 + 1)
   822    825                   .expect("Overwriting on encryptor shouldn't fail.");
   823    826               check_file_size(&se, (size1 + size2) as u64);
   824    827               data_map = se.close().expect("Closing encryptor shouldn't fail.");
   825    828           }
   826    829           let mut se = SelfEncryptor::new(&mut storage, data_map)
   827    830               .expect("Second encryptor construction shouldn't fail.");
   828         -        let fetched =
   829         -            se.read(0, (size1 + size2) as u64).expect("Reading from encryptor shouldn't fail.");
   830         -        assert!(&fetched[..size1] == &part1[..]);
          831  +        let fetched = se.read(0, (size1 + size2) as u64)
          832  +            .expect("Reading from encryptor shouldn't fail.");
          833  +        assert_eq!(&fetched[..size1], &part1[..]);
   831    834           assert_eq!(fetched[size1], part2[0]);
   832         -        assert!(&fetched[size1 + 1..size1 + 3] == &[4u8, 2][..]);
   833         -        assert!(&fetched[size1 + 3..] == &part2[3..]);
          835  +        assert_eq!(&fetched[size1 + 1..size1 + 3], &[4u8, 2][..]);
          836  +        assert_eq!(&fetched[size1 + 3..], &part2[3..]);
   834    837       }
   835    838   
   836    839       #[test]
   837    840       fn three_min_chunks_minus_one() {
   838    841           let mut storage = SimpleStorage::new();
   839    842           let data_map: DataMap;
   840    843           let bytes_len = (MIN_CHUNK_SIZE * 3) - 1;
   841    844           let the_bytes = random_bytes(bytes_len as usize);
   842    845           {
   843    846               let mut se = SelfEncryptor::new(&mut storage, DataMap::None)
   844    847                   .expect("First encryptor construction shouldn't fail.");
   845         -            se.write(&the_bytes, 0).expect("Writing to encryptor shouldn't fail.");
          848  +            se.write(&the_bytes, 0)
          849  +                .expect("Writing to encryptor shouldn't fail.");
   846    850               assert_eq!(se.sorted_map.len(), 0);
   847    851               assert_eq!(se.sequencer.len(), bytes_len as usize);
   848    852               check_file_size(&se, bytes_len as u64);
   849    853               // check close
   850    854               data_map = se.close().expect("Closing encryptor shouldn't fail.");
   851    855           }
   852    856           match data_map {
................................................................................
   853    857               DataMap::Chunks(_) => panic!("shall not return DataMap::Chunks"),
   854    858               DataMap::Content(ref content) => assert_eq!(content.len(), bytes_len as usize),
   855    859               DataMap::None => panic!("shall not return DataMap::None"),
   856    860           }
   857    861           // check read, write
   858    862           let mut new_se = SelfEncryptor::new(&mut storage, data_map)
   859    863               .expect("Second encryptor construction shouldn't fail.");
   860         -        let fetched =
   861         -            new_se.read(0, bytes_len as u64).expect("Reading from encryptor shouldn't fail.");
   862         -        assert!(fetched == the_bytes);
          864  +        let fetched = new_se
          865  +            .read(0, bytes_len as u64)
          866  +            .expect("Reading from encryptor shouldn't fail.");
          867  +        assert_eq!(fetched, the_bytes);
   863    868       }
   864    869   
   865    870       #[test]
   866    871       fn three_min_chunks() {
   867    872           let mut storage = SimpleStorage::new();
   868    873           let data_map: DataMap;
   869    874           let the_bytes = random_bytes(MIN_CHUNK_SIZE as usize * 3);
   870    875           {
   871    876               let mut se = SelfEncryptor::new(&mut storage, DataMap::None)
   872    877                   .expect("First encryptor construction shouldn't fail.");
   873         -            se.write(&the_bytes, 0).expect("Writing to encryptor shouldn't fail.");
          878  +            se.write(&the_bytes, 0)
          879  +                .expect("Writing to encryptor shouldn't fail.");
   874    880               check_file_size(&se, MIN_CHUNK_SIZE as u64 * 3);
   875    881               let fetched = se.read(0, MIN_CHUNK_SIZE as u64 * 3)
   876    882                   .expect("Reading from encryptor shouldn't fail.");
   877         -            assert!(fetched == the_bytes);
          883  +            assert_eq!(fetched, the_bytes);
   878    884               data_map = se.close().expect("Closing encryptor shouldn't fail.");
   879    885           }
   880    886           match data_map {
   881    887               DataMap::Chunks(ref chunks) => {
   882    888                   assert_eq!(chunks.len(), 3);
   883    889                   assert_eq!(storage.num_entries(), 3);
   884    890                   for chunk_detail in chunks.iter() {
................................................................................
   887    893               }
   888    894               DataMap::Content(_) => panic!("shall not return DataMap::Content"),
   889    895               DataMap::None => panic!("shall not return DataMap::None"),
   890    896           }
   891    897           // check read, write
   892    898           let mut new_se = SelfEncryptor::new(&mut storage, data_map)
   893    899               .expect("Second encryptor construction shouldn't fail.");
   894         -        let fetched = new_se.read(0, MIN_CHUNK_SIZE as u64 * 3)
          900  +        let fetched = new_se
          901  +            .read(0, MIN_CHUNK_SIZE as u64 * 3)
   895    902               .expect("Reading again from encryptor shouldn't fail.");
   896         -        assert!(fetched == the_bytes);
          903  +        assert_eq!(fetched, the_bytes);
   897    904       }
   898    905   
   899    906       #[test]
   900    907       fn three_min_chunks_plus_one() {
   901    908           let mut storage = SimpleStorage::new();
   902    909           let data_map: DataMap;
   903    910           let bytes_len = (MIN_CHUNK_SIZE * 3) + 1;
   904    911           let the_bytes = random_bytes(bytes_len as usize);
   905    912           {
   906    913               let mut se = SelfEncryptor::new(&mut storage, DataMap::None)
   907    914                   .expect("First encryptor construction shouldn't fail.");
   908         -            se.write(&the_bytes, 0).expect("Writing to encryptor shouldn't fail.");
          915  +            se.write(&the_bytes, 0)
          916  +                .expect("Writing to encryptor shouldn't fail.");
   909    917               check_file_size(&se, bytes_len as u64);
   910    918               data_map = se.close().expect("Closing encryptor shouldn't fail.");
   911    919           }
   912    920           match data_map {
   913    921               DataMap::Chunks(ref chunks) => {
   914    922                   assert_eq!(chunks.len(), 3);
   915    923                   assert_eq!(storage.num_entries(), 3);
................................................................................
   918    926                   }
   919    927               }
   920    928               DataMap::Content(_) => panic!("shall not return DataMap::Content"),
   921    929               DataMap::None => panic!("shall not return DataMap::None"),
   922    930           }
   923    931           let mut new_se = SelfEncryptor::new(&mut storage, data_map)
   924    932               .expect("Second encryptor construction shouldn't fail.");
   925         -        let fetched =
   926         -            new_se.read(0, bytes_len as u64).expect("Reading from encryptor shouldn't fail.");
   927         -        assert!(fetched == the_bytes);
          933  +        let fetched = new_se
          934  +            .read(0, bytes_len as u64)
          935  +            .expect("Reading from encryptor shouldn't fail.");
          936  +        assert_eq!(fetched, the_bytes);
   928    937       }
   929    938   
   930    939       #[test]
   931    940       fn three_max_chunks() {
   932    941           let mut storage = SimpleStorage::new();
   933    942           let data_map: DataMap;
   934    943           let bytes_len = MAX_CHUNK_SIZE * 3;
   935    944           let the_bytes = random_bytes(bytes_len as usize);
   936    945           {
   937    946               let mut se = SelfEncryptor::new(&mut storage, DataMap::None)
   938    947                   .expect("First encryptor construction shouldn't fail.");
   939         -            se.write(&the_bytes, 0).expect("Writing to encryptor shouldn't fail.");
          948  +            se.write(&the_bytes, 0)
          949  +                .expect("Writing to encryptor shouldn't fail.");
   940    950               check_file_size(&se, bytes_len as u64);
   941    951               data_map = se.close().expect("Closing encryptor shouldn't fail.");
   942    952           }
   943    953           match data_map {
   944    954               DataMap::Chunks(ref chunks) => {
   945    955                   assert_eq!(chunks.len(), 3);
   946    956                   assert_eq!(storage.num_entries(), 3);
................................................................................
   949    959                   }
   950    960               }
   951    961               DataMap::Content(_) => panic!("shall not return DataMap::Content"),
   952    962               DataMap::None => panic!("shall not return DataMap::None"),
   953    963           }
   954    964           let mut new_se = SelfEncryptor::new(&mut storage, data_map)
   955    965               .expect("Second encryptor construction shouldn't fail.");
   956         -        let fetched =
   957         -            new_se.read(0, bytes_len as u64).expect("Reading from encryptor shouldn't fail.");
   958         -        assert!(fetched == the_bytes);
          966  +        let fetched = new_se
          967  +            .read(0, bytes_len as u64)
          968  +            .expect("Reading from encryptor shouldn't fail.");
          969  +        assert_eq!(fetched, the_bytes);
   959    970       }
   960    971   
   961    972       #[test]
   962    973       fn three_max_chunks_plus_one() {
   963    974           let mut storage = SimpleStorage::new();
   964    975           let data_map: DataMap;
   965    976           let bytes_len = (MAX_CHUNK_SIZE * 3) + 1;
   966    977           let the_bytes = random_bytes(bytes_len as usize);
   967    978           {
   968    979               let mut se = SelfEncryptor::new(&mut storage, DataMap::None)
   969    980                   .expect("First encryptor construction shouldn't fail.");
   970         -            se.write(&the_bytes, 0).expect("Writing to encryptor shouldn't fail.");
          981  +            se.write(&the_bytes, 0)
          982  +                .expect("Writing to encryptor shouldn't fail.");
   971    983               check_file_size(&se, bytes_len as u64);
   972    984               // check close
   973    985               data_map = se.close().expect("Closing encryptor shouldn't fail.");
   974    986           }
   975    987           match data_map {
   976    988               DataMap::Chunks(ref chunks) => {
   977    989                   assert_eq!(chunks.len(), 4);
................................................................................
   982    994               }
   983    995               DataMap::Content(_) => panic!("shall not return DataMap::Content"),
   984    996               DataMap::None => panic!("shall not return DataMap::None"),
   985    997           }
   986    998           // check read and write
   987    999           let mut new_se = SelfEncryptor::new(&mut storage, data_map)
   988   1000               .expect("Second encryptor construction shouldn't fail.");
   989         -        let fetched =
   990         -            new_se.read(0, bytes_len as u64).expect("Reading from encryptor shouldn't fail.");
   991         -        assert!(fetched == the_bytes);
         1001  +        let fetched = new_se
         1002  +            .read(0, bytes_len as u64)
         1003  +            .expect("Reading from encryptor shouldn't fail.");
         1004  +        assert_eq!(fetched, the_bytes);
   992   1005       }
   993   1006   
   994   1007       #[test]
   995   1008       fn seven_and_a_bit_max_chunks() {
   996   1009           let mut storage = SimpleStorage::new();
   997   1010           let data_map: DataMap;
   998   1011           let bytes_len = (MAX_CHUNK_SIZE * 7) + 1024;
   999   1012           let the_bytes = random_bytes(bytes_len as usize);
  1000   1013           {
  1001   1014               let mut se = SelfEncryptor::new(&mut storage, DataMap::None)
  1002   1015                   .expect("First encryptor construction shouldn't fail.");
  1003         -            se.write(&the_bytes, 0).expect("Writing to encryptor shouldn't fail.");
         1016  +            se.write(&the_bytes, 0)
         1017  +                .expect("Writing to encryptor shouldn't fail.");
  1004   1018               check_file_size(&se, bytes_len as u64);
  1005   1019               data_map = se.close().expect("Closing encryptor shouldn't fail.");
  1006   1020           }
  1007   1021           match data_map {
  1008   1022               DataMap::Chunks(ref chunks) => {
  1009   1023                   assert_eq!(chunks.len(), 8);
  1010   1024                   assert_eq!(storage.num_entries(), 8);
................................................................................
  1013   1027                   }
  1014   1028               }
  1015   1029               DataMap::Content(_) => panic!("shall not return DataMap::Content"),
  1016   1030               DataMap::None => panic!("shall not return DataMap::None"),
  1017   1031           }
  1018   1032           let mut new_se = SelfEncryptor::new(&mut storage, data_map)
  1019   1033               .expect("Second encryptor construction shouldn't fail.");
  1020         -        let fetched =
  1021         -            new_se.read(0, bytes_len as u64).expect("Reading from encryptor shouldn't fail.");
  1022         -        assert!(fetched == the_bytes);
         1034  +        let fetched = new_se
         1035  +            .read(0, bytes_len as u64)
         1036  +            .expect("Reading from encryptor shouldn't fail.");
         1037  +        assert_eq!(fetched, the_bytes);
  1023   1038       }
  1024   1039   
  1025   1040       #[test]
  1026   1041       fn large_file_one_byte_under_eleven_chunks() {
  1027   1042           let mut storage = SimpleStorage::new();
  1028   1043           let data_map: DataMap;
  1029   1044           let number_of_chunks: u32 = 11;
  1030   1045           let bytes_len = (MAX_CHUNK_SIZE as usize * number_of_chunks as usize) - 1;
  1031   1046           let the_bytes = random_bytes(bytes_len);
  1032   1047           {
  1033   1048               let mut se = SelfEncryptor::new(&mut storage, DataMap::None)
  1034   1049                   .expect("First encryptor construction shouldn't fail.");
  1035         -            se.write(&the_bytes, 0).expect("Writing to encryptor shouldn't fail.");
         1050  +            se.write(&the_bytes, 0)
         1051  +                .expect("Writing to encryptor shouldn't fail.");
  1036   1052               check_file_size(&se, bytes_len as u64);
  1037   1053               data_map = se.close().expect("Closing encryptor shouldn't fail.");
  1038   1054           }
  1039   1055           match data_map {
  1040   1056               DataMap::Chunks(ref chunks) => {
  1041   1057                   assert_eq!(chunks.len(), number_of_chunks as usize);
  1042   1058                   assert_eq!(storage.num_entries(), number_of_chunks as usize);
................................................................................
  1045   1061                   }
  1046   1062               }
  1047   1063               DataMap::Content(_) => panic!("shall not return DataMap::Content"),
  1048   1064               DataMap::None => panic!("shall not return DataMap::None"),
  1049   1065           }
  1050   1066           let mut new_se = SelfEncryptor::new(&mut storage, data_map)
  1051   1067               .expect("Second encryptor construction shouldn't fail.");
  1052         -        let fetched =
  1053         -            new_se.read(0, bytes_len as u64).expect("Reading from encryptor shouldn't fail.");
  1054         -        assert!(fetched == the_bytes);
         1068  +        let fetched = new_se
         1069  +            .read(0, bytes_len as u64)
         1070  +            .expect("Reading from encryptor shouldn't fail.");
         1071  +        assert_eq!(fetched, the_bytes);
  1055   1072       }
  1056   1073   
  1057   1074       #[test]
  1058   1075       fn large_file_one_byte_over_eleven_chunks() {
  1059   1076           let mut storage = SimpleStorage::new();
  1060   1077           let data_map: DataMap;
  1061   1078           let number_of_chunks: u32 = 11;
  1062   1079           let bytes_len = (MAX_CHUNK_SIZE as usize * number_of_chunks as usize) + 1;
  1063   1080           let the_bytes = random_bytes(bytes_len);
  1064   1081           {
  1065   1082               let mut se = SelfEncryptor::new(&mut storage, DataMap::None)
  1066   1083                   .expect("First encryptor construction shouldn't fail.");
  1067         -            se.write(&the_bytes, 0).expect("Writing to encryptor shouldn't fail.");
         1084  +            se.write(&the_bytes, 0)
         1085  +                .expect("Writing to encryptor shouldn't fail.");
  1068   1086               check_file_size(&se, bytes_len as u64);
  1069   1087               data_map = se.close().expect("Closing encryptor shouldn't fail.");
  1070   1088           }
  1071   1089           match data_map {
  1072   1090               DataMap::Chunks(ref chunks) => {
  1073   1091                   assert_eq!(chunks.len(), number_of_chunks as usize + 1);
  1074   1092                   assert_eq!(storage.num_entries(), number_of_chunks as usize + 1);
................................................................................
  1077   1095                   }
  1078   1096               }
  1079   1097               DataMap::Content(_) => panic!("shall not return DataMap::Content"),
  1080   1098               DataMap::None => panic!("shall not return DataMap::None"),
  1081   1099           }
  1082   1100           let mut new_se = SelfEncryptor::new(&mut storage, data_map)
  1083   1101               .expect("Second encryptor construction shouldn't fail.");
  1084         -        let fetched =
  1085         -            new_se.read(0, bytes_len as u64).expect("Reading from encryptor shouldn't fail.");
  1086         -        assert!(fetched == the_bytes);
         1102  +        let fetched = new_se
         1103  +            .read(0, bytes_len as u64)
         1104  +            .expect("Reading from encryptor shouldn't fail.");
         1105  +        assert_eq!(fetched, the_bytes);
  1087   1106       }
  1088   1107   
  1089   1108       #[test]
  1090   1109       fn large_file_size_1024_over_eleven_chunks() {
  1091   1110           // has been tested for 50 chunks
  1092   1111           let mut storage = SimpleStorage::new();
  1093   1112           let data_map: DataMap;
  1094   1113           let number_of_chunks: u32 = 11;
  1095   1114           let bytes_len = (MAX_CHUNK_SIZE as usize * number_of_chunks as usize) + 1024;
  1096   1115           let the_bytes = random_bytes(bytes_len);
  1097   1116           {
  1098   1117               let mut se = SelfEncryptor::new(&mut storage, DataMap::None)
  1099   1118                   .expect("First encryptor construction shouldn't fail.");
  1100         -            se.write(&the_bytes, 0).expect("Writing to encryptor shouldn't fail.");
         1119  +            se.write(&the_bytes, 0)
         1120  +                .expect("Writing to encryptor shouldn't fail.");
  1101   1121               check_file_size(&se, bytes_len as u64);
  1102   1122               // check close
  1103   1123               data_map = se.close().expect("Closing encryptor shouldn't fail.");
  1104   1124           }
  1105   1125           match data_map {
  1106   1126               DataMap::Chunks(ref chunks) => {
  1107   1127                   assert_eq!(chunks.len(), number_of_chunks as usize + 1);
................................................................................
  1112   1132               }
  1113   1133               DataMap::Content(_) => panic!("shall not return DataMap::Content"),
  1114   1134               DataMap::None => panic!("shall not return DataMap::None"),
  1115   1135           }
  1116   1136           // check read and write
  1117   1137           let mut new_se = SelfEncryptor::new(&mut storage, data_map)
  1118   1138               .expect("Second encryptor construction shouldn't fail.");
  1119         -        let fetched =
  1120         -            new_se.read(0, bytes_len as u64).expect("Reading from encryptor shouldn't fail.");
  1121         -        assert!(fetched == the_bytes);
         1139  +        let fetched = new_se
         1140  +            .read(0, bytes_len as u64)
         1141  +            .expect("Reading from encryptor shouldn't fail.");
         1142  +        assert_eq!(fetched, the_bytes);
  1122   1143       }
  1123   1144   
  1124   1145       #[test]
  1125   1146       fn five_and_extend_to_seven_plus_one() {
  1126   1147           let mut storage = SimpleStorage::new();
  1127   1148           let data_map: DataMap;
  1128   1149           let bytes_len = MAX_CHUNK_SIZE * 5;
  1129   1150           let the_bytes = random_bytes(bytes_len as usize);
  1130   1151           {
  1131   1152               let mut se = SelfEncryptor::new(&mut storage, DataMap::None)
  1132   1153                   .expect("Encryptor construction shouldn't fail.");
  1133         -            se.write(&the_bytes, 0).expect("Writing to encryptor shouldn't fail.");
         1154  +            se.write(&the_bytes, 0)
         1155  +                .expect("Writing to encryptor shouldn't fail.");
  1134   1156               check_file_size(&se, bytes_len as u64);
  1135   1157               se.truncate((7 * MAX_CHUNK_SIZE + 1) as u64)
  1136   1158                   .expect("Truncating encryptor shouldn't fail.");
  1137   1159               check_file_size(&se, (7 * MAX_CHUNK_SIZE + 1) as u64);
  1138   1160               data_map = se.close().expect("Closing encryptor shouldn't fail.");
  1139   1161           }
  1140   1162           match data_map {
................................................................................
  1155   1177           let mut storage = SimpleStorage::new();
  1156   1178           let data_map: DataMap;
  1157   1179           let bytes_len = MAX_CHUNK_SIZE * 3;
  1158   1180           let bytes = random_bytes(bytes_len as usize);
  1159   1181           {
  1160   1182               let mut se = SelfEncryptor::new(&mut storage, DataMap::None)
  1161   1183                   .expect("First encryptor construction shouldn't fail.");
  1162         -            se.write(&bytes, 0).expect("Writing to encryptor shouldn't fail.");
         1184  +            se.write(&bytes, 0)
         1185  +                .expect("Writing to encryptor shouldn't fail.");
  1163   1186               check_file_size(&se, bytes_len as u64);
  1164         -            se.truncate(bytes_len as u64 - 24).expect("Truncating encryptor shouldn't fail.");
         1187  +            se.truncate(bytes_len as u64 - 24)
         1188  +                .expect("Truncating encryptor shouldn't fail.");
  1165   1189               check_file_size(&se, bytes_len as u64 - 24);
  1166   1190               data_map = se.close().expect("Closing encryptor shouldn't fail.");
  1167   1191           }
  1168   1192           assert_eq!(data_map.len(), bytes_len as u64 - 24);
  1169   1193           match data_map {
  1170   1194               DataMap::Chunks(ref chunks) => {
  1171   1195                   assert_eq!(chunks.len(), 3);
................................................................................
  1174   1198                       assert!(storage.has_chunk(&chunk_detail.hash));
  1175   1199                   }
  1176   1200               }
  1177   1201               _ => panic!("data_map should be DataMap::Chunks"),
  1178   1202           }
  1179   1203           let mut se = SelfEncryptor::new(&mut storage, data_map)
  1180   1204               .expect("Second encryptor construction shouldn't fail.");
  1181         -        let fetched =
  1182         -            se.read(0, bytes_len as u64 - 24).expect("Reading from encryptor shouldn't fail.");
  1183         -        assert!(&fetched[..] == &bytes[..(bytes_len - 24) as usize]);
         1205  +        let fetched = se.read(0, bytes_len as u64 - 24)
         1206  +            .expect("Reading from encryptor shouldn't fail.");
         1207  +        assert_eq!(&fetched[..], &bytes[..(bytes_len - 24) as usize]);
  1184   1208       }
  1185   1209   
  1186   1210       #[test]
  1187   1211       fn truncate_from_data_map() {
  1188   1212           let mut storage = SimpleStorage::new();
  1189   1213           let bytes_len = MAX_CHUNK_SIZE * 3;
  1190   1214           let bytes = random_bytes(bytes_len as usize);
  1191   1215           let data_map: DataMap;
  1192   1216           {
  1193   1217               let mut se = SelfEncryptor::new(&mut storage, DataMap::None)
  1194   1218                   .expect("First encryptor construction shouldn't fail.");
  1195         -            se.write(&bytes, 0).expect("Writing to encryptor shouldn't fail.");
         1219  +            se.write(&bytes, 0)
         1220  +                .expect("Writing to encryptor shouldn't fail.");
  1196   1221               check_file_size(&se, bytes_len as u64);
  1197         -            data_map = se.close().expect("Closing first encryptor shouldn't fail.");
         1222  +            data_map = se.close()
         1223  +                .expect("Closing first encryptor shouldn't fail.");
  1198   1224           }
  1199   1225           let data_map2: DataMap;
  1200   1226           {
  1201   1227               // Start with an existing data_map.
  1202   1228               let mut se = SelfEncryptor::new(&mut storage, data_map)
  1203   1229                   .expect("Second encryptor construction shouldn't fail.");
  1204         -            se.truncate(bytes_len as u64 - 24).expect("Truncating encryptor shouldn't fail.");
  1205         -            data_map2 = se.close().expect("Closing second encryptor shouldn't fail.");
         1230  +            se.truncate(bytes_len as u64 - 24)
         1231  +                .expect("Truncating encryptor shouldn't fail.");
         1232  +            data_map2 = se.close()
         1233  +                .expect("Closing second encryptor shouldn't fail.");
  1206   1234           }
  1207   1235           assert_eq!(data_map2.len(), bytes_len as u64 - 24);
  1208   1236           match data_map2 {
  1209   1237               DataMap::Chunks(ref chunks) => {
  1210   1238                   assert_eq!(chunks.len(), 3);
  1211   1239                   // old ones + new ones
  1212   1240                   assert_eq!(storage.num_entries(), 6);
................................................................................
  1214   1242                       assert!(storage.has_chunk(&chunk_detail.hash));
  1215   1243                   }
  1216   1244               }
  1217   1245               _ => panic!("data_map should be DataMap::Chunks"),
  1218   1246           }
  1219   1247           let mut se = SelfEncryptor::new(&mut storage, data_map2)
  1220   1248               .expect("Third encryptor construction shouldn't fail.");
  1221         -        let fetched =
  1222         -            se.read(0, bytes_len as u64 - 24).expect("Reading from encryptor shouldn't fail.");
  1223         -        assert!(&fetched[..] == &bytes[..(bytes_len - 24) as usize]);
         1249  +        let fetched = se.read(0, bytes_len as u64 - 24)
         1250  +            .expect("Reading from encryptor shouldn't fail.");
         1251  +        assert_eq!(&fetched[..], &bytes[..(bytes_len - 24) as usize]);
  1224   1252       }
  1225   1253   
  1226   1254       #[test]
  1227   1255       fn truncate_from_data_map2() {
  1228   1256           let mut storage = SimpleStorage::new();
  1229   1257           let bytes_len = MAX_CHUNK_SIZE * 3;
  1230   1258           let bytes = random_bytes(bytes_len as usize);
  1231   1259           let data_map: DataMap;
  1232   1260           {
  1233   1261               let mut se = SelfEncryptor::new(&mut storage, DataMap::None)
  1234   1262                   .expect("First encryptor construction shouldn't fail.");
  1235         -            se.write(&bytes, 0).expect("Writing to encryptor shouldn't fail.");
         1263  +            se.write(&bytes, 0)
         1264  +                .expect("Writing to encryptor shouldn't fail.");
  1236   1265               check_file_size(&se, bytes_len as u64);
  1237         -            data_map = se.close().expect("Closing first encryptor shouldn't fail.");
         1266  +            data_map = se.close()
         1267  +                .expect("Closing first encryptor shouldn't fail.");
  1238   1268           }
  1239   1269           let data_map2: DataMap;
  1240   1270           {
  1241   1271               // Start with an existing data_map.
  1242   1272               let mut se = SelfEncryptor::new(&mut storage, data_map)
  1243   1273                   .expect("Second encryptor construction shouldn't fail.");
  1244         -            se.truncate(bytes_len as u64 - 1).expect("Truncating encryptor once shouldn't fail.");
         1274  +            se.truncate(bytes_len as u64 - 1)
         1275  +                .expect("Truncating encryptor once shouldn't fail.");
  1245   1276               se.truncate(bytes_len as u64)
  1246   1277                   .expect("Truncating encryptor a second time shouldn't fail.");
  1247         -            data_map2 = se.close().expect("Closing second encryptor shouldn't fail.");
         1278  +            data_map2 = se.close()
         1279  +                .expect("Closing second encryptor shouldn't fail.");
  1248   1280           }
  1249   1281           assert_eq!(data_map2.len(), bytes_len as u64);
  1250   1282           match data_map2 {
  1251   1283               DataMap::Chunks(ref chunks) => {
  1252   1284                   assert_eq!(chunks.len(), 3);
  1253   1285                   // old ones + new ones
  1254   1286                   assert_eq!(storage.num_entries(), 6);
................................................................................
  1256   1288                       assert!(storage.has_chunk(&chunk_detail.hash));
  1257   1289                   }
  1258   1290               }
  1259   1291               _ => panic!("data_map should be DataMap::Chunks"),
  1260   1292           }
  1261   1293           let mut se = SelfEncryptor::new(&mut storage, data_map2)
  1262   1294               .expect("Third encryptor construction shouldn't fail.");
  1263         -        let fetched = se.read(0, bytes_len as u64).expect("Reading from encryptor shouldn't fail.");
         1295  +        let fetched = se.read(0, bytes_len as u64)
         1296  +            .expect("Reading from encryptor shouldn't fail.");
  1264   1297           let matching_bytes = bytes_len as usize - 1;
  1265         -        assert!(&fetched[..matching_bytes] == &bytes[..matching_bytes]);
         1298  +        assert_eq!(&fetched[..matching_bytes], &bytes[..matching_bytes]);
  1266   1299           assert_eq!(fetched[matching_bytes], 0u8);
  1267   1300       }
  1268   1301   
  1269   1302       #[test]
  1270   1303       fn truncate_to_extend_from_data_map() {
  1271   1304           let mut storage = SimpleStorage::new();
  1272   1305           let bytes_len = MAX_CHUNK_SIZE * 3 - 24;
  1273   1306           let bytes = random_bytes(bytes_len as usize);
  1274   1307           let data_map: DataMap;
  1275   1308           {
  1276   1309               let mut se = SelfEncryptor::new(&mut storage, DataMap::None)
  1277   1310                   .expect("First encryptor construction shouldn't fail.");
  1278         -            se.write(&bytes, 0).expect("Writing to encryptor shouldn't fail.");
         1311  +            se.write(&bytes, 0)
         1312  +                .expect("Writing to encryptor shouldn't fail.");
  1279   1313               check_file_size(&se, bytes_len as u64);
  1280         -            data_map = se.close().expect("Closing first encryptor shouldn't fail.");
         1314  +            data_map = se.close()
         1315  +                .expect("Closing first encryptor shouldn't fail.");
  1281   1316           }
  1282   1317           let data_map2: DataMap;
  1283   1318           {
  1284   1319               // Start with an existing data_map.
  1285   1320               let mut se = SelfEncryptor::new(&mut storage, data_map)
  1286   1321                   .expect("Second encryptor construction shouldn't fail.");
  1287         -            se.truncate(bytes_len as u64 + 24).expect("Truncating encryptor shouldn't fail.");
  1288         -            data_map2 = se.close().expect("Closing second encryptor shouldn't fail.");
         1322  +            se.truncate(bytes_len as u64 + 24)
         1323  +                .expect("Truncating encryptor shouldn't fail.");
         1324  +            data_map2 = se.close()
         1325  +                .expect("Closing second encryptor shouldn't fail.");
  1289   1326           }
  1290   1327           assert_eq!(data_map2.len(), bytes_len as u64 + 24);
  1291   1328           match data_map2 {
  1292   1329               DataMap::Chunks(ref chunks) => {
  1293   1330                   assert_eq!(chunks.len(), 3);
  1294   1331                   // old ones + new ones
  1295   1332                   assert_eq!(storage.num_entries(), 6);
................................................................................
  1297   1334                       assert!(storage.has_chunk(&chunk_detail.hash));
  1298   1335                   }
  1299   1336               }
  1300   1337               _ => panic!("data_map should be DataMap::Chunks"),
  1301   1338           }
  1302   1339           let mut se = SelfEncryptor::new(&mut storage, data_map2)
  1303   1340               .expect("Third encryptor construction shouldn't fail.");
  1304         -        let fetched =
  1305         -            se.read(0, bytes_len as u64 + 24).expect("Reading from encryptor shouldn't fail.");
  1306         -        assert!(&fetched[..bytes_len as usize] == &bytes[..]);
  1307         -        assert!(&fetched[bytes_len as usize..] == &[0u8; 24]);
         1341  +        let fetched = se.read(0, bytes_len as u64 + 24)
         1342  +            .expect("Reading from encryptor shouldn't fail.");
         1343  +        assert_eq!(&fetched[..bytes_len as usize], &bytes[..]);
         1344  +        assert_eq!(&fetched[bytes_len as usize..], &[0u8; 24]);
  1308   1345       }
  1309   1346   
  1310   1347       #[test]
  1311   1348       fn large_100mb_file() {
  1312   1349           let mut storage = SimpleStorage::new();
  1313   1350           let data_map: DataMap;
  1314   1351           let number_of_chunks: u32 = 100;
  1315   1352           let bytes_len = MAX_CHUNK_SIZE as usize * number_of_chunks as usize;
  1316   1353           let bytes = random_bytes(bytes_len);
  1317   1354           {
  1318   1355               let mut se = SelfEncryptor::new(&mut storage, DataMap::None)
  1319   1356                   .expect("First encryptor construction shouldn't fail.");
  1320         -            se.write(&bytes, 0).expect("Writing to encryptor shouldn't fail.");
         1357  +            se.write(&bytes, 0)
         1358  +                .expect("Writing to encryptor shouldn't fail.");
  1321   1359               check_file_size(&se, bytes_len as u64);
  1322   1360               data_map = se.close().expect("Closing encryptor shouldn't fail.");
  1323   1361           }
  1324   1362           match data_map {
  1325   1363               DataMap::Chunks(ref chunks) => {
  1326   1364                   assert_eq!(chunks.len(), number_of_chunks as usize);
  1327   1365                   assert_eq!(storage.num_entries(), number_of_chunks as usize);
................................................................................
  1330   1368                   }
  1331   1369               }
  1332   1370               DataMap::Content(_) => panic!("shall not return DataMap::Content"),
  1333   1371               DataMap::None => panic!("shall not return DataMap::None"),
  1334   1372           }
  1335   1373           let mut new_se = SelfEncryptor::new(&mut storage, data_map)
  1336   1374               .expect("Second encryptor construction shouldn't fail.");
  1337         -        let fetched =
  1338         -            new_se.read(0, bytes_len as u64).expect("Reading from encryptor shouldn't fail.");
  1339         -        assert!(fetched == bytes);
         1375  +        let fetched = new_se
         1376  +            .read(0, bytes_len as u64)
         1377  +            .expect("Reading from encryptor shouldn't fail.");
         1378  +        assert_eq!(fetched, bytes);
  1340   1379       }
  1341   1380   
  1342   1381       #[test]
  1343   1382       fn write_starting_with_existing_data_map() {
  1344   1383           let mut storage = SimpleStorage::new();
  1345   1384           let part1_len = MIN_CHUNK_SIZE * 3;
  1346   1385           let part1_bytes = random_bytes(part1_len as usize);
  1347   1386           let data_map: DataMap;
  1348   1387           {
  1349   1388               let mut se = SelfEncryptor::new(&mut storage, DataMap::None)
  1350   1389                   .expect("First encryptor construction shouldn't fail.");
  1351         -            se.write(&part1_bytes, 0).expect("Writing part one to encryptor shouldn't fail.");
         1390  +            se.write(&part1_bytes, 0)
         1391  +                .expect("Writing part one to encryptor shouldn't fail.");
  1352   1392               check_file_size(&se, part1_len as u64);
  1353         -            data_map = se.close().expect("Closing first encryptor shouldn't fail.");
         1393  +            data_map = se.close()
         1394  +                .expect("Closing first encryptor shouldn't fail.");
  1354   1395           }
  1355   1396           let part2_len = 1024;
  1356   1397           let part2_bytes = random_bytes(part2_len as usize);
  1357   1398           let full_len = part1_len + part2_len;
  1358   1399           let data_map2: DataMap;
  1359   1400           {
  1360   1401               // Start with an existing data_map.
  1361   1402               let mut se = SelfEncryptor::new(&mut storage, data_map)
  1362   1403                   .expect("Second encryptor construction shouldn't fail.");
  1363   1404               se.write(&part2_bytes, part1_len as u64)
  1364   1405                   .expect("Writing part two to encryptor shouldn't fail.");
  1365   1406               // check_file_size(&se, full_len);
  1366         -            data_map2 = se.close().expect("Closing second encryptor shouldn't fail.");
         1407  +            data_map2 = se.close()
         1408  +                .expect("Closing second encryptor shouldn't fail.");
  1367   1409           }
  1368   1410           assert_eq!(data_map2.len(), full_len as u64);
  1369   1411   
  1370   1412           let mut se = SelfEncryptor::new(&mut storage, data_map2)
  1371   1413               .expect("Third encryptor construction shouldn't fail.");
  1372         -        let fetched = se.read(0, full_len as u64).expect("Reading from encryptor shouldn't fail.");
  1373         -        assert!(&part1_bytes[..] == &fetched[..part1_len as usize]);
  1374         -        assert!(&part2_bytes[..] == &fetched[part1_len as usize..]);
         1414  +        let fetched = se.read(0, full_len as u64)
         1415  +            .expect("Reading from encryptor shouldn't fail.");
         1416  +        assert_eq!(&part1_bytes[..], &fetched[..part1_len as usize]);
         1417  +        assert_eq!(&part2_bytes[..], &fetched[part1_len as usize..]);
  1375   1418       }
  1376   1419   
  1377   1420       #[test]
  1378   1421       fn write_starting_with_existing_data_map2() {
  1379   1422           let mut storage = SimpleStorage::new();
  1380   1423           let part1_len = MAX_CHUNK_SIZE * 3 - 24;
  1381   1424           let part1_bytes = random_bytes(part1_len as usize);
  1382   1425           let data_map: DataMap;
  1383   1426           {
  1384   1427               let mut se = SelfEncryptor::new(&mut storage, DataMap::None)
  1385   1428                   .expect("First encryptor construction shouldn't fail.");
  1386         -            se.write(&part1_bytes, 0).expect("Writing part one to encryptor shouldn't fail.");
         1429  +            se.write(&part1_bytes, 0)
         1430  +                .expect("Writing part one to encryptor shouldn't fail.");
  1387   1431               check_file_size(&se, part1_len as u64);
  1388         -            data_map = se.close().expect("Closing first encryptor shouldn't fail.");
         1432  +            data_map = se.close()
         1433  +                .expect("Closing first encryptor shouldn't fail.");
  1389   1434           }
  1390   1435           let part2_len = 1024;
  1391   1436           let part2_bytes = random_bytes(part2_len as usize);
  1392   1437           let full_len = part1_len + part2_len;
  1393   1438           let data_map2: DataMap;
  1394   1439           {
  1395   1440               // Start with an existing data_map.
  1396   1441               let mut se = SelfEncryptor::new(&mut storage, data_map)
  1397   1442                   .expect("Second encryptor construction shouldn't fail.");
  1398   1443               se.write(&part2_bytes, part1_len as u64)
  1399   1444                   .expect("Writing part two to encryptor shouldn't fail.");
  1400         -            data_map2 = se.close().expect("Closing second encryptor shouldn't fail.");
         1445  +            data_map2 = se.close()
         1446  +                .expect("Closing second encryptor shouldn't fail.");
  1401   1447           }
  1402   1448           assert_eq!(data_map2.len(), full_len as u64);
  1403   1449           match data_map2 {
  1404   1450               DataMap::Chunks(ref chunks) => {
  1405   1451                   assert_eq!(chunks.len(), 4);
  1406   1452                   // old ones + new ones
  1407   1453                   assert_eq!(storage.num_entries(), 7);
................................................................................
  1410   1456                   }
  1411   1457               }
  1412   1458               _ => panic!("data_map should be DataMap::Chunks"),
  1413   1459           }
  1414   1460   
  1415   1461           let mut se = SelfEncryptor::new(&mut storage, data_map2)
  1416   1462               .expect("Third encryptor construction shouldn't fail.");
  1417         -        let fetched = se.read(0, full_len as u64).expect("Reading from encryptor shouldn't fail.");
  1418         -        assert!(&part1_bytes[..] == &fetched[..part1_len as usize]);
  1419         -        assert!(&part2_bytes[..] == &fetched[part1_len as usize..]);
         1463  +        let fetched = se.read(0, full_len as u64)
         1464  +            .expect("Reading from encryptor shouldn't fail.");
         1465  +        assert_eq!(&part1_bytes[..], &fetched[..part1_len as usize]);
         1466  +        assert_eq!(&part2_bytes[..], &fetched[part1_len as usize..]);
  1420   1467       }
  1421   1468   
  1422   1469       #[test]
  1423   1470       fn overwrite_starting_with_existing_data_map() {
  1424   1471           let mut storage = SimpleStorage::new();
  1425   1472           let part1_len = MAX_CHUNK_SIZE * 4;
  1426   1473           let part1_bytes = random_bytes(part1_len as usize);
  1427   1474           let data_map: DataMap;
  1428   1475           {
  1429   1476               let mut se = SelfEncryptor::new(&mut storage, DataMap::None)
  1430   1477                   .expect("First encryptor construction shouldn't fail.");
  1431         -            se.write(&part1_bytes, 0).expect("Writing part one to encryptor shouldn't fail.");
         1478  +            se.write(&part1_bytes, 0)
         1479  +                .expect("Writing part one to encryptor shouldn't fail.");
  1432   1480               check_file_size(&se, part1_len as u64);
  1433         -            data_map = se.close().expect("Closing first encryptor shouldn't fail.");
         1481  +            data_map = se.close()
         1482  +                .expect("Closing first encryptor shouldn't fail.");
  1434   1483           }
  1435   1484           let part2_len = 2;
  1436   1485           let part2_bytes = random_bytes(part2_len);
  1437   1486           let data_map2: DataMap;
  1438   1487           {
  1439   1488               // Start with an existing data_map.
  1440   1489               let mut se = SelfEncryptor::new(&mut storage, data_map)
  1441   1490                   .expect("Second encryptor construction shouldn't fail.");
  1442   1491               // Overwrite. This and next two chunks will have to be re-encrypted.
  1443         -            se.write(&part2_bytes, 2).expect("Writing part two to encryptor shouldn't fail.");
  1444         -            data_map2 = se.close().expect("Closing second encryptor shouldn't fail.");
         1492  +            se.write(&part2_bytes, 2)
         1493  +                .expect("Writing part two to encryptor shouldn't fail.");
         1494  +            data_map2 = se.close()
         1495  +                .expect("Closing second encryptor shouldn't fail.");
  1445   1496           }
  1446   1497           assert_eq!(data_map2.len(), part1_len as u64);
  1447   1498   
  1448   1499           let mut se = SelfEncryptor::new(&mut storage, data_map2)
  1449   1500               .expect("Third encryptor construction shouldn't fail.");
  1450         -        let fetched = se.read(0, part1_len as u64).expect("Reading from encryptor shouldn't fail.");
  1451         -        assert!(&part1_bytes[..2] == &fetched[..2]);
  1452         -        assert!(&part2_bytes[..] == &fetched[2..2 + part2_len]);
  1453         -        assert!(&part1_bytes[2 + part2_len..] == &fetched[2 + part2_len..]);
         1501  +        let fetched = se.read(0, part1_len as u64)
         1502  +            .expect("Reading from encryptor shouldn't fail.");
         1503  +        assert_eq!(&part1_bytes[..2], &fetched[..2]);
         1504  +        assert_eq!(&part2_bytes[..], &fetched[2..2 + part2_len]);
         1505  +        assert_eq!(&part1_bytes[2 + part2_len..], &fetched[2 + part2_len..]);
  1454   1506       }
  1455   1507   
  1456   1508       fn create_vector_data_map(storage: &mut SimpleStorage, vec_len: usize) -> DataMap {
  1457   1509           let data: Vec<usize> = (0..vec_len).collect();
  1458   1510           let serialised_data: Vec<u8> =
  1459   1511               serialisation::serialise(&data).expect("failed to serialise Vec<usize>");
  1460   1512           let mut self_encryptor = SelfEncryptor::new(storage, DataMap::None)
  1461   1513               .expect("Encryptor construction shouldn't fail.");
  1462         -        self_encryptor.write(&serialised_data, 0).expect("Writing to encryptor shouldn't fail.");
         1514  +        self_encryptor
         1515  +            .write(&serialised_data, 0)
         1516  +            .expect("Writing to encryptor shouldn't fail.");
  1463   1517           check_file_size(&self_encryptor, serialised_data.len() as u64);
  1464         -        self_encryptor.close().expect("Closing encryptor shouldn't fail.")
         1518  +        self_encryptor
         1519  +            .close()
         1520  +            .expect("Closing encryptor shouldn't fail.")
  1465   1521       }
  1466   1522   
  1467   1523       fn check_vector_data_map(storage: &mut SimpleStorage, vec_len: usize, data_map: &DataMap) {
  1468   1524           let mut self_encryptor = SelfEncryptor::new(storage, data_map.clone())
  1469   1525               .expect("Encryptor construction shouldn't fail.");
  1470   1526           let length = self_encryptor.len();
  1471         -        let data_to_deserialise: Vec<u8> =
  1472         -            self_encryptor.read(0, length).expect("Reading from encryptor shouldn't fail.");
         1527  +        let data_to_deserialise: Vec<u8> = self_encryptor
         1528  +            .read(0, length)
         1529  +            .expect("Reading from encryptor shouldn't fail.");
  1473   1530           let data: Vec<usize> = serialisation::deserialise(&data_to_deserialise)
  1474   1531               .expect("failed to deserialise Vec<usize>");
  1475   1532           assert_eq!(data.len(), vec_len);
  1476   1533           for (index, data_char) in data.iter().enumerate() {
  1477   1534               assert_eq!(*data_char, index);
  1478   1535           }
  1479   1536       }