-
Notifications
You must be signed in to change notification settings - Fork 384
Expand file tree
/
Copy pathZipVerifier.cs
More file actions
39 lines (35 loc) · 1.53 KB
/
ZipVerifier.cs
File metadata and controls
39 lines (35 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.IO;
using System.IO.Compression;
using System.Collections.Generic;
using Microsoft.SignCheck.Logging;
namespace Microsoft.SignCheck.Verification
{
public class ZipVerifier : PgpVerifier
{
public ZipVerifier(Log log, Exclusions exclusions, SignatureVerificationOptions options, string fileExtension = ".zip", bool supportsDetachedSignature = false) : base(log, exclusions, options, fileExtension, supportsDetachedSignature) { }
protected override IEnumerable<ArchiveEntry> ReadArchiveEntries(string archivePath)
{
using (var archive = new ZipArchive(File.OpenRead(archivePath), ZipArchiveMode.Read, leaveOpen: false))
{
foreach (var entry in archive.Entries)
{
string relativePath = entry.FullName;
// Skip directories and empty entries
if (!relativePath.EndsWith("/") || entry.Name != "")
{
var contentStream = entry.Open();
yield return new ArchiveEntry()
{
RelativePath = relativePath,
ContentStream = contentStream,
ContentSize = entry.Length
};
contentStream.Close();
}
}
}
}
}
}