Some checks failed
Docs CI / lint-and-preview (push) Has been cancelled
AOC Guard CI / aoc-guard (push) Has been cancelled
AOC Guard CI / aoc-verify (push) Has been cancelled
Concelier Attestation Tests / attestation-tests (push) Has been cancelled
Export Center CI / export-ci (push) Has been cancelled
Notify Smoke Test / Notify Unit Tests (push) Has been cancelled
Notify Smoke Test / Notifier Service Tests (push) Has been cancelled
Notify Smoke Test / Notification Smoke Test (push) Has been cancelled
Policy Lint & Smoke / policy-lint (push) Has been cancelled
Scanner Analyzers / Discover Analyzers (push) Has been cancelled
Scanner Analyzers / Build Analyzers (push) Has been cancelled
Scanner Analyzers / Test Language Analyzers (push) Has been cancelled
Scanner Analyzers / Validate Test Fixtures (push) Has been cancelled
Scanner Analyzers / Verify Deterministic Output (push) Has been cancelled
Signals CI & Image / signals-ci (push) Has been cancelled
Signals Reachability Scoring & Events / reachability-smoke (push) Has been cancelled
Signals Reachability Scoring & Events / sign-and-upload (push) Has been cancelled
67 lines
2.2 KiB
C#
67 lines
2.2 KiB
C#
using System;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using StellaOps.Scanner.Analyzers.Lang.Rust.Internal;
|
|
|
|
namespace StellaOps.Scanner.Analyzers.Lang.Rust;
|
|
|
|
public sealed class RustLanguageAnalyzer : ILanguageAnalyzer
|
|
{
|
|
public string Id => "rust";
|
|
|
|
public string DisplayName => "Rust Analyzer (preview)";
|
|
|
|
public ValueTask AnalyzeAsync(LanguageAnalyzerContext context, LanguageComponentWriter writer, CancellationToken cancellationToken)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(context);
|
|
ArgumentNullException.ThrowIfNull(writer);
|
|
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
|
|
var collection = RustAnalyzerCollector.Collect(context, cancellationToken);
|
|
|
|
EmitRecords(Id, writer, collection.Crates);
|
|
EmitRecords(Id, writer, collection.Heuristics);
|
|
EmitRecords(Id, writer, collection.Fallbacks);
|
|
|
|
return ValueTask.CompletedTask;
|
|
}
|
|
|
|
private static void EmitRecords(string analyzerId, LanguageComponentWriter writer, IReadOnlyList<RustComponentRecord> records)
|
|
{
|
|
foreach (var record in records)
|
|
{
|
|
if (record is null)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(record.Purl))
|
|
{
|
|
writer.AddFromPurl(
|
|
analyzerId: analyzerId,
|
|
purl: record.Purl!,
|
|
name: record.Name,
|
|
version: record.Version,
|
|
type: record.Type,
|
|
metadata: record.Metadata,
|
|
evidence: record.Evidence,
|
|
usedByEntrypoint: record.UsedByEntrypoint);
|
|
}
|
|
else
|
|
{
|
|
writer.AddFromExplicitKey(
|
|
analyzerId: analyzerId,
|
|
componentKey: record.ComponentKey,
|
|
purl: null,
|
|
name: record.Name,
|
|
version: record.Version,
|
|
type: record.Type,
|
|
metadata: record.Metadata,
|
|
evidence: record.Evidence,
|
|
usedByEntrypoint: record.UsedByEntrypoint);
|
|
}
|
|
}
|
|
}
|
|
}
|