public bool Load(AxCryptReader axCryptReader)
        {
            axCryptReader.Read();
            if (axCryptReader.CurrentItemType != AxCryptItemType.MagicGuid)
            {
                throw new FileFormatException("No magic Guid was found.", ErrorStatus.MagicGuidMissing);
            }
            List <HeaderBlock> headerBlocks = new List <HeaderBlock>();

            while (axCryptReader.Read())
            {
                switch (axCryptReader.CurrentItemType)
                {
                case AxCryptItemType.HeaderBlock:
                    headerBlocks.Add(axCryptReader.CurrentHeaderBlock);
                    break;

                case AxCryptItemType.Data:
                    headerBlocks.Add(axCryptReader.CurrentHeaderBlock);
                    _headerBlocks = headerBlocks;
                    EnsureFileFormatVersion();
                    if (GetMasterKey() != null)
                    {
                        SetMasterKeyForEncryptedHeaderBlocks(headerBlocks);
                        return(true);
                    }
                    return(false);

                default:
                    throw new InternalErrorException("The reader returned an AxCryptItemType it should not be possible for it to return.");
                }
            }
            throw new FileFormatException("Premature end of stream.", ErrorStatus.EndOfStream);
        }
        private void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }

            if (disposing)
            {
                if (_dataCrypto != null)
                {
                    _dataCrypto.Dispose();
                    _dataCrypto = null;
                }
                if (_reader != null)
                {
                    _reader.Dispose();
                    _reader = null;
                }
            }

            _disposed = true;
        }
 /// <summary>
 /// Loads an AxCrypt file from the specified reader. After this, the reader is positioned to
 /// read encrypted data.
 /// </summary>
 /// <param name="stream">The stream to read from. Will be disposed when this instance is disposed.</param>
 /// <returns>True if the key was valid, false if it was wrong.</returns>
 public bool Load(Stream stream, AesKey key)
 {
     _reader = AxCryptReader.Create(stream);
     DocumentHeaders documentHeaders = new DocumentHeaders(key);
     PassphraseIsValid = documentHeaders.Load(_reader);
     if (PassphraseIsValid)
     {
         DocumentHeaders = documentHeaders;
     }
     return PassphraseIsValid;
 }