public void DecryptingSingleBlockFrameShouldReturnCorrectData() { Stream stream = new MemoryStream(encryptedSingleBlockFrameData); EncryptedLoaderFrame frame = EncryptedLoaderFrame.Load(stream); byte[] data = frame.Decrypt(); Assert.AreEqual <int>(BootLoaderCryptoAlgorithm.DecryptedBlockSize, data.Length, "Decrypted data should be of correct length."); CollectionAssert.AreEqual(originalSingleBlockFrameData, data); }
public void DecryptingMultiBlockFrameShouldReturnCorrectData() { Stream stream = new MemoryStream(encryptedFrameData); EncryptedLoaderFrame frame = EncryptedLoaderFrame.Load(stream); byte[] data = frame.Decrypt(); Assert.AreEqual <int>(frame.BlockCount * BootLoaderCryptoAlgorithm.DecryptedBlockSize, data.Length, "Decrypted data should be of correct length."); CollectionAssert.AreEqual(originalFrameData, data, "Decrypted data should match known decryption values"); }
public void LoadingFromStreamShouldCreateCorrectFrame() { Stream stream = new MemoryStream(encryptedFrameData); EncryptedLoaderFrame frame = EncryptedLoaderFrame.Load(stream); Assert.IsNotNull(frame, "Correct stream should give actual frame."); Assert.AreEqual <int>(0xFD, frame.Header, "Header from stream is not correct."); Assert.AreEqual <int>(3, frame.BlockCount, "Block count should be set correctly."); }
public void LoadingFromStreamWithWrongSizeShouldThrow() { Stream stream = new MemoryStream(new byte[] { 0xFD }); try { EncryptedLoaderFrame frame = EncryptedLoaderFrame.Load(stream); } catch (Exception ex) { Assert.IsInstanceOfType(ex, typeof(ArgumentException), "Wrong header data should throw as bad argument."); Assert.AreEqual <string>("Stream does not contain enough data.", ex.Message); return; } Assert.Fail("Exception should have been thrown for data with incorrect length."); }
public void LoadingFromStreamWithWrongHeaderShouldThrow() { Stream stream = new MemoryStream(new byte[] { 0x00 }); try { EncryptedLoaderFrame frame = EncryptedLoaderFrame.Load(stream); } catch (Exception ex) { Assert.IsInstanceOfType(ex, typeof(ArgumentException), "Wrong header data should throw as bad argument."); Assert.AreEqual <string>("Invalid header information in stream.", ex.Message); return; } Assert.Fail("Exception should have been thrown for data with bad header."); }