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 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 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 EncryptingMultiBlockFrameShouldReturnCorrectData()
        {
            EncryptedLoaderFrame frame = EncryptedLoaderFrame.Create(originalFrameData);

            byte[] data = frame.GetBytes();

            Assert.AreEqual <int>(3, frame.BlockCount);
            Assert.AreEqual <byte>(0xFD, frame.Header, "Header should indicate 3 blocks.");
            Assert.AreEqual <int>(3 * BootLoaderCryptoAlgorithm.EncryptedBlockSize + 1, data.Length, "Encrypted data should be of correct length.");
            CollectionAssert.AreEqual(encryptedFrameData, data, "Encrypted data should match known encryption values");
        }
        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.");
        }