44 lines
1.3 KiB
C#
44 lines
1.3 KiB
C#
// Licensed to StellaOps under the BUSL-1.1 license.
|
|
using StellaOps.ReachGraph.Schema;
|
|
using System.Collections.Immutable;
|
|
|
|
namespace StellaOps.ReachGraph.Serialization;
|
|
|
|
public sealed partial class CanonicalReachGraphSerializer
|
|
{
|
|
private static ImmutableArray<ReachGraphNode> CreateNodes(List<ReachGraphNodeDto> nodes)
|
|
{
|
|
return [.. nodes.Select(n => new ReachGraphNode
|
|
{
|
|
Id = n.Id,
|
|
Kind = n.Kind,
|
|
Ref = n.Ref,
|
|
File = n.File,
|
|
Line = n.Line,
|
|
ModuleHash = n.ModuleHash,
|
|
Addr = n.Addr,
|
|
IsEntrypoint = n.IsEntrypoint,
|
|
IsSink = n.IsSink
|
|
})];
|
|
}
|
|
|
|
private static ImmutableArray<ReachGraphEdge> CreateEdges(List<ReachGraphEdgeDto> edges)
|
|
{
|
|
return [.. edges.Select(e => new ReachGraphEdge
|
|
{
|
|
From = e.From,
|
|
To = e.To,
|
|
Why = new EdgeExplanation
|
|
{
|
|
Type = e.Why.Type,
|
|
Loc = e.Why.Loc,
|
|
Guard = e.Why.Guard,
|
|
Confidence = e.Why.Confidence,
|
|
Metadata = e.Why.Metadata?.Count > 0
|
|
? e.Why.Metadata.ToImmutableDictionary()
|
|
: null
|
|
}
|
|
})];
|
|
}
|
|
}
|