Skip to content

Commit 9e5fd7e

Browse files
committed
Graph is now its own collection.
Items is no longer exposed; rather the type itself is the collection.
1 parent a2a2d06 commit 9e5fd7e

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

AuthenticodeLint/CheckEngine.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public RuleEngineResult RunAllRules(string file, Graph<Signature> signatures, Li
3535
{
3636
RuleResult result;
3737
var verboseWriter = verbose ? new MemorySignatureLogger() : SignatureLogger.Null;
38-
if (signatures.Items.Count == 0)
38+
if (signatures.Count == 0)
3939
{
4040
result = RuleResult.Fail;
4141
verboseWriter.LogMessage("File is not Authenticode signed.");

AuthenticodeLint/Graph.cs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,27 @@
1-
using System.Collections.Generic;
1+
using System;
2+
using System.Collections;
3+
using System.Collections.Generic;
24

35
namespace AuthenticodeLint
46
{
5-
public class Graph<T>
7+
public class Graph<T> : IReadOnlyList<GraphItem<T>>
68
{
7-
public IReadOnlyCollection<GraphItem<T>> Items { get; }
9+
private readonly IReadOnlyList<GraphItem<T>> _items;
810

9-
public Graph(IReadOnlyCollection<GraphItem<T>> items)
11+
public Graph(IReadOnlyList<GraphItem<T>> items)
1012
{
11-
Items = items;
13+
_items = items;
1214
}
1315

14-
public static Graph<T> Empty { get; } = new Graph<T>(System.Array.Empty<GraphItem<T>>());
16+
public static Graph<T> Empty { get; } = new Graph<T>(Array.Empty<GraphItem<T>>());
17+
18+
public int Count => _items.Count;
19+
20+
public GraphItem<T> this[int index] => _items[index];
1521

1622
public IEnumerable<T> VisitAll()
1723
{
18-
foreach(var item in Items)
24+
foreach(var item in this)
1925
{
2026
yield return item.Node;
2127
foreach(var child in item.Children.VisitAll())
@@ -24,6 +30,11 @@ public IEnumerable<T> VisitAll()
2430
}
2531
}
2632
}
33+
34+
public IEnumerator<GraphItem<T>> GetEnumerator() => _items.GetEnumerator();
35+
36+
IEnumerator IEnumerable.GetEnumerator() => ((IEnumerable<GraphItem<T>>)this).GetEnumerator();
37+
2738
}
2839

2940
public class GraphItem<T>

AuthenticodeLint/Rules/Sha1PrimarySignatureRule.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class Sha1PrimarySignatureRule : IAuthenticodeSignatureRule
1212

1313
public RuleResult Validate(Graph<Signature> graph, SignatureLogger verboseWriter, CheckConfiguration configuration)
1414
{
15-
var primary = graph.Items.SingleOrDefault()?.Node;
15+
var primary = graph.SingleOrDefault()?.Node;
1616
//There are zero signatures.
1717
if (primary == null)
1818
{

0 commit comments

Comments
 (0)