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();
                    });
                }
            }
        }
 public static void TestUndefinedItemType()
 {
     using (MemoryStream testStream = new MemoryStream())
     {
         using (AxCryptReaderForTest axCryptReader = new AxCryptReaderForTest(testStream))
         {
             axCryptReader.SetCurrentItemType(AxCryptItemType.Undefined);
             Assert.Throws <InternalErrorException>(() =>
             {
                 bool isOk = axCryptReader.Read();
                 Object.Equals(isOk, null);
             });
         }
     }
 }
Пример #3
0
 public static void TestInvalidItemType()
 {
     using (MemoryStream inputStream = new MemoryStream())
     {
         AxCrypt1Guid.Write(inputStream);
         new PreambleHeaderBlock().Write(inputStream);
         inputStream.Position = 0;
         using (AxCryptReaderForTest axCryptReader = new AxCryptReaderForTest(inputStream))
         {
             DocumentHeaders documentHeaders = new DocumentHeaders(new AesKey());
             Assert.Throws <InternalErrorException>(() =>
             {
                 documentHeaders.Load(axCryptReader);
             });
         }
     }
 }
 public void TestInvalidItemType()
 {
     using (MemoryStream inputStream = new MemoryStream())
     {
         AxCrypt1Guid.Write(inputStream);
         new PreambleHeaderBlock().Write(inputStream);
         inputStream.Position = 0;
         using (AxCryptReaderForTest axCryptReader = new AxCryptReaderForTest(new LookAheadStream(inputStream)))
         {
             V1DocumentHeaders documentHeaders = new V1DocumentHeaders(new Passphrase("secret"), 15);
             Assert.Throws <InternalErrorException>(() =>
             {
                 documentHeaders.Load(axCryptReader);
             });
         }
     }
 }
        public static void TestTooShortStream()
        {
            using (MemoryStream inputStream = new MemoryStream())
            {
                AxCrypt1Guid.Write(inputStream);

                BadHeaderBlock badHeaderBlock = new BadHeaderBlock();
                badHeaderBlock.FakeHeaderBlockLength = 5 + 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.That(axCryptReader.Read(), Is.False, "The stream is too short and end prematurely and should thus be able to read the block");
                    Assert.That(axCryptReader.CurrentItemType, Is.EqualTo(AxCryptItemType.EndOfStream), "The stream is at an end and current item type should reflect this.");
                }
            }
        }
        public static void TestTooLargeHeaderBlockLength()
        {
            using (MemoryStream inputStream = new MemoryStream())
            {
                AxCrypt1Guid.Write(inputStream);

                BadHeaderBlock badHeaderBlock = new BadHeaderBlock();
                badHeaderBlock.FakeHeaderBlockLength = 0x1000000;
                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 too large header block length 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.");
                }
            }
        }
Пример #8
0
 public static void TestInvalidItemType()
 {
     using (MemoryStream inputStream = new MemoryStream())
     {
         AxCrypt1Guid.Write(inputStream);
         new PreambleHeaderBlock().Write(inputStream);
         inputStream.Position = 0;
         using (AxCryptReaderForTest axCryptReader = new AxCryptReaderForTest(inputStream))
         {
             DocumentHeaders documentHeaders = new DocumentHeaders(new AesKey());
             Assert.Throws<InternalErrorException>(() =>
             {
                 documentHeaders.Load(axCryptReader);
             });
         }
     }
 }
 public static void TestUndefinedItemType()
 {
     using (MemoryStream testStream = new MemoryStream())
     {
         using (AxCryptReaderForTest axCryptReader = new AxCryptReaderForTest(testStream))
         {
             axCryptReader.SetCurrentItemType(AxCryptItemType.Undefined);
             Assert.Throws<InternalErrorException>(() =>
             {
                 bool isOk = axCryptReader.Read();
                 Object.Equals(isOk, null);
             });
         }
     }
 }
        public static void TestTooShortStream()
        {
            using (MemoryStream inputStream = new MemoryStream())
            {
                AxCrypt1Guid.Write(inputStream);

                BadHeaderBlock badHeaderBlock = new BadHeaderBlock();
                badHeaderBlock.FakeHeaderBlockLength = 5 + 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.That(axCryptReader.Read(), Is.False, "The stream is too short and end prematurely and should thus be able to read the block");
                    Assert.That(axCryptReader.CurrentItemType, Is.EqualTo(AxCryptItemType.EndOfStream), "The stream is at an end and current item type should reflect this.");
                }
            }
        }
        public static void TestTooLargeHeaderBlockLength()
        {
            using (MemoryStream inputStream = new MemoryStream())
            {
                AxCrypt1Guid.Write(inputStream);

                BadHeaderBlock badHeaderBlock = new BadHeaderBlock();
                badHeaderBlock.FakeHeaderBlockLength = 0x1000000;
                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 too large header block length 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();
                    });
                }
            }
        }