public static void TestNonUtcFileTimes()
        {
            FileInfoHeaderBlock fileInfoHeaderBlock = new FileInfoHeaderBlock();
            fileInfoHeaderBlock.HeaderCrypto = new AesCrypto(new AesKey());

            DateTime utcNow = OS.Current.UtcNow;
            DateTime localNow = utcNow.ToLocalTime();

            fileInfoHeaderBlock.CreationTimeUtc = localNow;
            Assert.That(fileInfoHeaderBlock.CreationTimeUtc.Kind, Is.EqualTo(DateTimeKind.Utc), "The local time should be converted to UTC by the setter.");
            Assert.That(fileInfoHeaderBlock.CreationTimeUtc, Is.EqualTo(utcNow), "The setter should have set the time to value of local time converted to UTC.");

            fileInfoHeaderBlock.LastAccessTimeUtc = localNow;
            Assert.That(fileInfoHeaderBlock.LastAccessTimeUtc.Kind, Is.EqualTo(DateTimeKind.Utc), "The local time should be converted to UTC by the setter.");
            Assert.That(fileInfoHeaderBlock.LastAccessTimeUtc, Is.EqualTo(utcNow), "The setter should have set the time to value of local time converted to UTC.");

            fileInfoHeaderBlock.LastWriteTimeUtc = localNow;
            Assert.That(fileInfoHeaderBlock.LastWriteTimeUtc.Kind, Is.EqualTo(DateTimeKind.Utc), "The local time should be converted to UTC by the setter.");
            Assert.That(fileInfoHeaderBlock.LastWriteTimeUtc, Is.EqualTo(utcNow), "The setter should have set the time to value of local time converted to UTC.");
        }
Esempio n. 2
0
        public override object Clone()
        {
            FileInfoHeaderBlock block = new FileInfoHeaderBlock((byte[])GetDataBlockBytesReference().Clone());

            return(block);
        }
Esempio n. 3
0
        private void ParseHeaderBlock(HeaderBlockType headerBlockType, byte[] dataBlock)
        {
            bool isFirst = CurrentItemType == AxCryptItemType.MagicGuid;

            CurrentItemType = AxCryptItemType.HeaderBlock;

            if (headerBlockType == HeaderBlockType.Preamble)
            {
                if (!isFirst)
                {
                    throw new FileFormatException("Preamble can only be first.", ErrorStatus.FileFormatError);
                }
                CurrentHeaderBlock    = new PreambleHeaderBlock(dataBlock);
                _sendDataToHmacStream = true;
                return;
            }
            else
            {
                if (isFirst)
                {
                    throw new FileFormatException("Preamble must be first.", ErrorStatus.FileFormatError);
                }
            }

            switch (headerBlockType)
            {
            case HeaderBlockType.Version:
                CurrentHeaderBlock = new VersionHeaderBlock(dataBlock);
                break;

            case HeaderBlockType.KeyWrap1:
                CurrentHeaderBlock = new KeyWrap1HeaderBlock(dataBlock);
                break;

            case HeaderBlockType.KeyWrap2:
                CurrentHeaderBlock = new KeyWrap2HeaderBlock(dataBlock);
                break;

            case HeaderBlockType.IdTag:
                CurrentHeaderBlock = new IdTagHeaderBlock(dataBlock);
                break;

            case HeaderBlockType.Data:
                CurrentHeaderBlock = new DataHeaderBlock(dataBlock);
                break;

            case HeaderBlockType.FileNameInfo:
                CurrentHeaderBlock = new FileNameInfoHeaderBlock(dataBlock);
                break;

            case HeaderBlockType.EncryptionInfo:
                CurrentHeaderBlock = new EncryptionInfoHeaderBlock(dataBlock);
                break;

            case HeaderBlockType.CompressionInfo:
                CurrentHeaderBlock = new CompressionInfoHeaderBlock(dataBlock);
                break;

            case HeaderBlockType.FileInfo:
                CurrentHeaderBlock = new FileInfoHeaderBlock(dataBlock);
                break;

            case HeaderBlockType.Compression:
                CurrentHeaderBlock = new CompressionHeaderBlock(dataBlock);
                break;

            case HeaderBlockType.UnicodeFileNameInfo:
                CurrentHeaderBlock = new UnicodeFileNameInfoHeaderBlock(dataBlock);
                break;

            case HeaderBlockType.Encrypted:
            case HeaderBlockType.None:
            case HeaderBlockType.Any:
                throw new FileFormatException("Illegal header block type.", ErrorStatus.FileFormatError);

            default:
                CurrentHeaderBlock = new UnrecognizedHeaderBlock(headerBlockType, dataBlock);
                break;
            }

            if (_sendDataToHmacStream)
            {
                CurrentHeaderBlock.Write(_hmacBufferStream);
            }

            return;
        }
Esempio n. 4
0
        private void ParseHeaderBlock(HeaderBlockType headerBlockType, byte[] dataBlock)
        {
            bool isFirst = CurrentItemType == AxCryptItemType.MagicGuid;
            CurrentItemType = AxCryptItemType.HeaderBlock;

            if (headerBlockType == HeaderBlockType.Preamble)
            {
                if (!isFirst)
                {
                    throw new FileFormatException("Preamble can only be first.", ErrorStatus.FileFormatError);
                }
                CurrentHeaderBlock = new PreambleHeaderBlock(dataBlock);
                _sendDataToHmacStream = true;
                return;
            }
            else
            {
                if (isFirst)
                {
                    throw new FileFormatException("Preamble must be first.", ErrorStatus.FileFormatError);
                }
            }

            switch (headerBlockType)
            {
                case HeaderBlockType.Version:
                    CurrentHeaderBlock = new VersionHeaderBlock(dataBlock);
                    break;

                case HeaderBlockType.KeyWrap1:
                    CurrentHeaderBlock = new KeyWrap1HeaderBlock(dataBlock);
                    break;

                case HeaderBlockType.KeyWrap2:
                    CurrentHeaderBlock = new KeyWrap2HeaderBlock(dataBlock);
                    break;

                case HeaderBlockType.IdTag:
                    CurrentHeaderBlock = new IdTagHeaderBlock(dataBlock);
                    break;

                case HeaderBlockType.Data:
                    CurrentHeaderBlock = new DataHeaderBlock(dataBlock);
                    break;

                case HeaderBlockType.FileNameInfo:
                    CurrentHeaderBlock = new FileNameInfoHeaderBlock(dataBlock);
                    break;

                case HeaderBlockType.EncryptionInfo:
                    CurrentHeaderBlock = new EncryptionInfoHeaderBlock(dataBlock);
                    break;

                case HeaderBlockType.CompressionInfo:
                    CurrentHeaderBlock = new CompressionInfoHeaderBlock(dataBlock);
                    break;

                case HeaderBlockType.FileInfo:
                    CurrentHeaderBlock = new FileInfoHeaderBlock(dataBlock);
                    break;

                case HeaderBlockType.Compression:
                    CurrentHeaderBlock = new CompressionHeaderBlock(dataBlock);
                    break;

                case HeaderBlockType.UnicodeFileNameInfo:
                    CurrentHeaderBlock = new UnicodeFileNameInfoHeaderBlock(dataBlock);
                    break;

                case HeaderBlockType.Encrypted:
                case HeaderBlockType.None:
                case HeaderBlockType.Any:
                    throw new FileFormatException("Illegal header block type.", ErrorStatus.FileFormatError);
                default:
                    CurrentHeaderBlock = new UnrecognizedHeaderBlock(headerBlockType, dataBlock);
                    break;
            }

            if (_sendDataToHmacStream)
            {
                CurrentHeaderBlock.Write(_hmacBufferStream);
            }

            return;
        }
 public override object Clone()
 {
     FileInfoHeaderBlock block = new FileInfoHeaderBlock((byte[])GetDataBlockBytesReference().Clone());
     return block;
 }