Ejemplo n.º 1
0
        public static void TestInvalidHeaderBlockType()
        {
            using (MemoryStream inputStream = new MemoryStream())
            {
                AxCrypt1Guid.Write(inputStream);
                PreambleHeaderBlock preambleHeaderBlock = new PreambleHeaderBlock();
                preambleHeaderBlock.Write(inputStream);

                BadHeaderBlock badHeaderBlock = new BadHeaderBlock();
                badHeaderBlock.FakeHeaderBlockLength = 5;
                badHeaderBlock.SetHeaderBlockType(HeaderBlockType.Encrypted);
                badHeaderBlock.Write(inputStream);
                inputStream.Position = 0;

                using (AxCryptReaderForTest axCryptReader = new AxCryptReaderForTest(inputStream))
                {
                    Assert.That(axCryptReader.Read(), Is.True, "We should be able to read the Guid");
                    Assert.That(axCryptReader.CurrentItemType, Is.EqualTo(AxCryptItemType.MagicGuid), "We're expecting to have found a MagicGuid");
                    Assert.That(axCryptReader.Read(), Is.True, "We should be able to read the next HeaderBlock");
                    Assert.That(axCryptReader.CurrentItemType, Is.EqualTo(AxCryptItemType.HeaderBlock), "We're expecting to have found a HeaderBlock");
                    Assert.That(axCryptReader.CurrentHeaderBlock.HeaderBlockType, Is.EqualTo(HeaderBlockType.Preamble), "We're expecting to have found a Preamble specifically");

                    Assert.Throws <FileFormatException>(() =>
                    {
                        axCryptReader.Read();
                    });
                }
            }
        }
Ejemplo n.º 2
0
        public static void TestNegativeHeaderBlockType()
        {
            using (MemoryStream inputStream = new MemoryStream())
            {
                AxCrypt1Guid.Write(inputStream);

                BadHeaderBlock badHeaderBlock = new BadHeaderBlock();
                badHeaderBlock.SetHeaderBlockType((HeaderBlockType)(-1));
                badHeaderBlock.Write(inputStream);
                inputStream.Position = 0;

                using (AxCryptReaderForTest axCryptReader = new AxCryptReaderForTest(inputStream))
                {
                    Assert.That(axCryptReader.Read(), Is.True, "We should be able to read the Guid");
                    Assert.That(axCryptReader.CurrentItemType, Is.EqualTo(AxCryptItemType.MagicGuid), "We're expecting to have found a MagicGuid");
                    Assert.Throws <FileFormatException>(() =>
                    {
                        axCryptReader.Read();
                    }, "A negative header block type is not valid.");
                }
            }
        }
        public static void TestNegativeHeaderBlockType()
        {
            using (MemoryStream inputStream = new MemoryStream())
            {
                AxCrypt1Guid.Write(inputStream);

                BadHeaderBlock badHeaderBlock = new BadHeaderBlock();
                badHeaderBlock.SetHeaderBlockType((HeaderBlockType)(-1));
                badHeaderBlock.Write(inputStream);
                inputStream.Position = 0;

                using (AxCryptReaderForTest axCryptReader = new AxCryptReaderForTest(inputStream))
                {
                    Assert.That(axCryptReader.Read(), Is.True, "We should be able to read the Guid");
                    Assert.That(axCryptReader.CurrentItemType, Is.EqualTo(AxCryptItemType.MagicGuid), "We're expecting to have found a MagicGuid");
                    Assert.Throws<FileFormatException>(() =>
                    {
                        axCryptReader.Read();
                    }, "A negative header block type is not valid.");
                }
            }
        }
        public static void TestInvalidHeaderBlockType()
        {
            using (MemoryStream inputStream = new MemoryStream())
            {
                AxCrypt1Guid.Write(inputStream);
                PreambleHeaderBlock preambleHeaderBlock = new PreambleHeaderBlock();
                preambleHeaderBlock.Write(inputStream);

                BadHeaderBlock badHeaderBlock = new BadHeaderBlock();
                badHeaderBlock.FakeHeaderBlockLength = 5;
                badHeaderBlock.SetHeaderBlockType(HeaderBlockType.Encrypted);
                badHeaderBlock.Write(inputStream);
                inputStream.Position = 0;

                using (AxCryptReaderForTest axCryptReader = new AxCryptReaderForTest(inputStream))
                {
                    Assert.That(axCryptReader.Read(), Is.True, "We should be able to read the Guid");
                    Assert.That(axCryptReader.CurrentItemType, Is.EqualTo(AxCryptItemType.MagicGuid), "We're expecting to have found a MagicGuid");
                    Assert.That(axCryptReader.Read(), Is.True, "We should be able to read the next HeaderBlock");
                    Assert.That(axCryptReader.CurrentItemType, Is.EqualTo(AxCryptItemType.HeaderBlock), "We're expecting to have found a HeaderBlock");
                    Assert.That(axCryptReader.CurrentHeaderBlock.HeaderBlockType, Is.EqualTo(HeaderBlockType.Preamble), "We're expecting to have found a Preamble specifically");

                    Assert.Throws<FileFormatException>(() =>
                    {
                        axCryptReader.Read();
                    });
                }
            }
        }