-
Notifications
You must be signed in to change notification settings - Fork 385
Expand file tree
/
Copy pathZipVerifier.cs
More file actions
45 lines (39 loc) · 1.87 KB
/
ZipVerifier.cs
File metadata and controls
45 lines (39 loc) · 1.87 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
40
41
42
43
44
45
// 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") : base(log, exclusions, options, fileExtension) { }
public override SignatureVerificationResult VerifySignature(string path, string parent, string virtualPath)
=> VerifyDetachedSignature(path, parent, virtualPath);
protected override (string signatureDocument, string signableContent) GetSignatureDocumentAndSignableContent(string path, string tempDir)
=> GetDetachedSignatureDocumentAndSignableContent(path, tempDir);
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();
}
}
}
}
}
}