AddExtraDataAES() private static method

private static AddExtraDataAES ( ZipEntry entry, ZipExtraData extraData ) : void
entry ZipEntry
extraData ZipExtraData
return void
        public override void Finish()
        {
            if (this.entries == null)
            {
                return;
            }
            if (this.curEntry != null)
            {
                this.CloseEntry();
            }
            long noOfEntries = (long)this.entries.Count;
            long num         = 0L;

            foreach (ZipEntry zipEntry in this.entries)
            {
                this.WriteLeInt(33639248);
                this.WriteLeShort(51);
                this.WriteLeShort(zipEntry.Version);
                this.WriteLeShort(zipEntry.Flags);
                this.WriteLeShort((int)((short)zipEntry.CompressionMethodForHeader));
                this.WriteLeInt((int)zipEntry.DosTime);
                this.WriteLeInt((int)zipEntry.Crc);
                if (zipEntry.IsZip64Forced() || zipEntry.CompressedSize >= (long)((ulong)-1))
                {
                    this.WriteLeInt(-1);
                }
                else
                {
                    this.WriteLeInt((int)zipEntry.CompressedSize);
                }
                if (zipEntry.IsZip64Forced() || zipEntry.Size >= (long)((ulong)-1))
                {
                    this.WriteLeInt(-1);
                }
                else
                {
                    this.WriteLeInt((int)zipEntry.Size);
                }
                byte[] array = ZipConstants.ConvertToArray(zipEntry.Flags, zipEntry.Name);
                if (array.Length > 65535)
                {
                    throw new ZipException("Name too long.");
                }
                ZipExtraData zipExtraData = new ZipExtraData(zipEntry.ExtraData);
                if (zipEntry.CentralHeaderRequiresZip64)
                {
                    zipExtraData.StartNewEntry();
                    if (zipEntry.IsZip64Forced() || zipEntry.Size >= (long)((ulong)-1))
                    {
                        zipExtraData.AddLeLong(zipEntry.Size);
                    }
                    if (zipEntry.IsZip64Forced() || zipEntry.CompressedSize >= (long)((ulong)-1))
                    {
                        zipExtraData.AddLeLong(zipEntry.CompressedSize);
                    }
                    if (zipEntry.Offset >= (long)((ulong)-1))
                    {
                        zipExtraData.AddLeLong(zipEntry.Offset);
                    }
                    zipExtraData.AddNewEntry(1);
                }
                else
                {
                    zipExtraData.Delete(1);
                }
                if (zipEntry.AESKeySize > 0)
                {
                    ZipOutputStream.AddExtraDataAES(zipEntry, zipExtraData);
                }
                byte[] entryData = zipExtraData.GetEntryData();
                byte[] array2    = (zipEntry.Comment == null) ? new byte[0] : ZipConstants.ConvertToArray(zipEntry.Flags, zipEntry.Comment);
                if (array2.Length > 65535)
                {
                    throw new ZipException("Comment too long.");
                }
                this.WriteLeShort(array.Length);
                this.WriteLeShort(entryData.Length);
                this.WriteLeShort(array2.Length);
                this.WriteLeShort(0);
                this.WriteLeShort(0);
                if (zipEntry.ExternalFileAttributes != -1)
                {
                    this.WriteLeInt(zipEntry.ExternalFileAttributes);
                }
                else if (zipEntry.IsDirectory)
                {
                    this.WriteLeInt(16);
                }
                else
                {
                    this.WriteLeInt(0);
                }
                if (zipEntry.Offset >= (long)((ulong)-1))
                {
                    this.WriteLeInt(-1);
                }
                else
                {
                    this.WriteLeInt((int)zipEntry.Offset);
                }
                if (array.Length > 0)
                {
                    this.baseOutputStream_.Write(array, 0, array.Length);
                }
                if (entryData.Length > 0)
                {
                    this.baseOutputStream_.Write(entryData, 0, entryData.Length);
                }
                if (array2.Length > 0)
                {
                    this.baseOutputStream_.Write(array2, 0, array2.Length);
                }
                num += (long)(46 + array.Length + entryData.Length + array2.Length);
            }
            using (ZipHelperStream zipHelperStream = new ZipHelperStream(this.baseOutputStream_))
            {
                zipHelperStream.WriteEndOfCentralDirectory(noOfEntries, num, this.offset, this.zipComment);
            }
            this.entries = null;
        }
        public void PutNextEntry(ZipEntry entry)
        {
            if (entry == null)
            {
                throw new ArgumentNullException("entry");
            }
            if (this.entries == null)
            {
                throw new InvalidOperationException("ZipOutputStream was finished");
            }
            if (this.curEntry != null)
            {
                this.CloseEntry();
            }
            if (this.entries.Count == 2147483647)
            {
                throw new ZipException("Too many entries for Zip file");
            }
            CompressionMethod compressionMethod = entry.CompressionMethod;
            int level = this.defaultCompressionLevel;

            entry.Flags          &= 2048;
            this.patchEntryHeader = false;
            bool flag;

            if (entry.Size == 0L)
            {
                entry.CompressedSize = entry.Size;
                entry.Crc            = 0L;
                compressionMethod    = CompressionMethod.Stored;
                flag = true;
            }
            else
            {
                flag = (entry.Size >= 0L && entry.HasCrc && entry.CompressedSize >= 0L);
                if (compressionMethod == CompressionMethod.Stored)
                {
                    if (!flag)
                    {
                        if (!base.CanPatchEntries)
                        {
                            compressionMethod = CompressionMethod.Deflated;
                            level             = 0;
                        }
                    }
                    else
                    {
                        entry.CompressedSize = entry.Size;
                        flag = entry.HasCrc;
                    }
                }
            }
            if (!flag)
            {
                if (!base.CanPatchEntries)
                {
                    entry.Flags |= 8;
                }
                else
                {
                    this.patchEntryHeader = true;
                }
            }
            if (base.Password != null)
            {
                entry.IsCrypted = true;
                if (entry.Crc < 0L)
                {
                    entry.Flags |= 8;
                }
            }
            entry.Offset            = this.offset;
            entry.CompressionMethod = compressionMethod;
            this.curMethod          = compressionMethod;
            this.sizePatchPos       = -1L;
            if (this.useZip64_ == UseZip64.On || (entry.Size < 0L && this.useZip64_ == UseZip64.Dynamic))
            {
                entry.ForceZip64();
            }
            this.WriteLeInt(67324752);
            this.WriteLeShort(entry.Version);
            this.WriteLeShort(entry.Flags);
            this.WriteLeShort((int)((byte)entry.CompressionMethodForHeader));
            this.WriteLeInt((int)entry.DosTime);
            if (flag)
            {
                this.WriteLeInt((int)entry.Crc);
                if (entry.LocalHeaderRequiresZip64)
                {
                    this.WriteLeInt(-1);
                    this.WriteLeInt(-1);
                }
                else
                {
                    this.WriteLeInt((!entry.IsCrypted) ? ((int)entry.CompressedSize) : ((int)entry.CompressedSize + 12));
                    this.WriteLeInt((int)entry.Size);
                }
            }
            else
            {
                if (this.patchEntryHeader)
                {
                    this.crcPatchPos = this.baseOutputStream_.Position;
                }
                this.WriteLeInt(0);
                if (this.patchEntryHeader)
                {
                    this.sizePatchPos = this.baseOutputStream_.Position;
                }
                if (entry.LocalHeaderRequiresZip64 || this.patchEntryHeader)
                {
                    this.WriteLeInt(-1);
                    this.WriteLeInt(-1);
                }
                else
                {
                    this.WriteLeInt(0);
                    this.WriteLeInt(0);
                }
            }
            byte[] array = ZipConstants.ConvertToArray(entry.Flags, entry.Name);
            if (array.Length > 65535)
            {
                throw new ZipException("Entry name too long.");
            }
            ZipExtraData zipExtraData = new ZipExtraData(entry.ExtraData);

            if (entry.LocalHeaderRequiresZip64)
            {
                zipExtraData.StartNewEntry();
                if (flag)
                {
                    zipExtraData.AddLeLong(entry.Size);
                    zipExtraData.AddLeLong(entry.CompressedSize);
                }
                else
                {
                    zipExtraData.AddLeLong(-1L);
                    zipExtraData.AddLeLong(-1L);
                }
                zipExtraData.AddNewEntry(1);
                if (!zipExtraData.Find(1))
                {
                    throw new ZipException("Internal error cant find extra data");
                }
                if (this.patchEntryHeader)
                {
                    this.sizePatchPos = (long)zipExtraData.CurrentReadIndex;
                }
            }
            else
            {
                zipExtraData.Delete(1);
            }
            if (entry.AESKeySize > 0)
            {
                ZipOutputStream.AddExtraDataAES(entry, zipExtraData);
            }
            byte[] entryData = zipExtraData.GetEntryData();
            this.WriteLeShort(array.Length);
            this.WriteLeShort(entryData.Length);
            if (array.Length > 0)
            {
                this.baseOutputStream_.Write(array, 0, array.Length);
            }
            if (entry.LocalHeaderRequiresZip64 && this.patchEntryHeader)
            {
                this.sizePatchPos += this.baseOutputStream_.Position;
            }
            if (entryData.Length > 0)
            {
                this.baseOutputStream_.Write(entryData, 0, entryData.Length);
            }
            this.offset += (long)(30 + array.Length + entryData.Length);
            if (entry.AESKeySize > 0)
            {
                this.offset += (long)entry.AESOverheadSize;
            }
            this.curEntry = entry;
            this.crc.Reset();
            if (compressionMethod == CompressionMethod.Deflated)
            {
                this.deflater_.Reset();
                this.deflater_.SetLevel(level);
            }
            this.size = 0L;
            if (entry.IsCrypted)
            {
                if (entry.AESKeySize > 0)
                {
                    this.WriteAESHeader(entry);
                }
                else if (entry.Crc < 0L)
                {
                    this.WriteEncryptionHeader(entry.DosTime << 16);
                }
                else
                {
                    this.WriteEncryptionHeader(entry.Crc);
                }
            }
        }