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 void TestFindPreambleHeaderBlockFirstButMoreThanOnceShouldThrow() { using (MemoryStream testStream = new MemoryStream()) { AxCrypt1Guid.Write(testStream); PreambleHeaderBlock preambleHeaderBlock = new PreambleHeaderBlock(); preambleHeaderBlock.Write(testStream); preambleHeaderBlock.Write(testStream); testStream.Position = 0; using (V1AxCryptReader axCryptReader = new V1AxCryptReader(new LookAheadStream(testStream))) { 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 void TestFindPreambleHeaderBlockNotFirstShouldThrow() { using (MemoryStream testStream = new MemoryStream()) { AxCrypt1Guid.Write(testStream); VersionHeaderBlock versionHeaderBlock = new VersionHeaderBlock(new byte[] { 3, 2, 2, 0, 0 }); versionHeaderBlock.Write(testStream); PreambleHeaderBlock preambleHeaderBlock = new PreambleHeaderBlock(); preambleHeaderBlock.Write(testStream); testStream.Position = 0; using (V1AxCryptReader axCryptReader = new V1AxCryptReader(new LookAheadStream(testStream))) { 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()); } } }
public static void TestUnrecognizedHeaderBlock() { using (MemoryStream inputStream = new MemoryStream()) { AxCrypt1Guid.Write(inputStream); PreambleHeaderBlock preambleHeaderBlock = new PreambleHeaderBlock(); preambleHeaderBlock.Write(inputStream); UnrecognizedHeaderBlock unrecognizedHeaderBlock = new UnrecognizedHeaderBlock(HeaderBlockType.Unrecognized, new byte[0]); unrecognizedHeaderBlock.Write(inputStream); inputStream.Position = 0; using (AxCryptReader axCryptReader = AxCryptReader.Create(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.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.Unrecognized), "We're expecting to have found an unrecognized block specifically"); } } }
public static void TestKeyWrap2HeaderBlock() { using (MemoryStream inputStream = new MemoryStream()) { AxCrypt1Guid.Write(inputStream); PreambleHeaderBlock preambleHeaderBlock = new PreambleHeaderBlock(); preambleHeaderBlock.Write(inputStream); V1KeyWrap2HeaderBlock keyWrap2HeaderBlock = new V1KeyWrap2HeaderBlock(new byte[0]); keyWrap2HeaderBlock.Write(inputStream); inputStream.Position = 0; using (V1AxCryptReader axCryptReader = new V1AxCryptReader(new LookAheadStream(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.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.KeyWrap2), "We're expecting to have found a KeyWrap2 specifically"); } } }