// SPDX-License-Identifier: BUSL-1.1
// Sprint: SPRINT_6000_0004_0001 - Scanner Worker Integration
// Task: T5 - Add Configuration and DI Registration
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using StellaOps.BinaryIndex.Core.Services;
using StellaOps.BinaryIndex.Persistence.Services;
using StellaOps.Scanner.Worker.Processing;
namespace StellaOps.Scanner.Worker.Extensions;
///
/// Extension methods for registering BinaryIndex integration services.
///
public static class BinaryIndexServiceExtensions
{
///
/// Adds BinaryIndex integration services to the service collection.
///
public static IServiceCollection AddBinaryIndexIntegration(
this IServiceCollection services,
IConfiguration configuration)
{
var options = configuration
.GetSection("BinaryIndex")
.Get() ?? new BinaryIndexOptions();
if (!options.Enabled)
{
services.AddSingleton();
return services;
}
services.AddSingleton(options);
services.AddScoped();
services.AddScoped();
services.AddScoped();
services.AddScoped();
return services;
}
}
///
/// Configuration options for BinaryIndex integration.
///
public sealed class BinaryIndexOptions
{
///
/// Whether binary vulnerability analysis is enabled.
///
public bool Enabled { get; init; } = true;
///
/// Batch size for binary lookups.
///
public int BatchSize { get; init; } = 100;
///
/// Timeout in milliseconds for binary lookups.
///
public int TimeoutMs { get; init; } = 5000;
///
/// Minimum confidence threshold for reporting matches.
///
public decimal MinConfidence { get; init; } = 0.7m;
}
///
/// Null implementation of IBinaryVulnerabilityService for when binary analysis is disabled.
///
internal sealed class NullBinaryVulnerabilityService : IBinaryVulnerabilityService
{
public Task> LookupByIdentityAsync(
StellaOps.BinaryIndex.Core.Models.BinaryIdentity identity,
LookupOptions? options = null,
CancellationToken ct = default)
{
return Task.FromResult(System.Collections.Immutable.ImmutableArray.Empty);
}
public Task>> LookupBatchAsync(
IEnumerable identities,
LookupOptions? options = null,
CancellationToken ct = default)
{
return Task.FromResult(System.Collections.Immutable.ImmutableDictionary>.Empty);
}
public Task GetFixStatusAsync(
string distro,
string release,
string sourcePkg,
string cveId,
CancellationToken ct = default)
{
return Task.FromResult(null);
}
public Task> GetFixStatusBatchAsync(
string distro,
string release,
string sourcePkg,
IEnumerable cveIds,
CancellationToken ct = default)
{
return Task.FromResult(System.Collections.Immutable.ImmutableDictionary.Empty);
}
public Task> LookupByFingerprintAsync(
byte[] fingerprint,
FingerprintLookupOptions? options = null,
CancellationToken ct = default)
{
return Task.FromResult(System.Collections.Immutable.ImmutableArray.Empty);
}
public Task>> LookupByFingerprintBatchAsync(
IEnumerable<(string Key, byte[] Fingerprint)> fingerprints,
FingerprintLookupOptions? options = null,
CancellationToken ct = default)
{
return Task.FromResult(System.Collections.Immutable.ImmutableDictionary>.Empty);
}
public Task> LookupByDeltaSignatureAsync(
Stream binaryStream,
DeltaSigLookupOptions? options = null,
CancellationToken ct = default)
{
return Task.FromResult(System.Collections.Immutable.ImmutableArray.Empty);
}
public Task> LookupBySymbolHashAsync(
string symbolHash,
string symbolName,
DeltaSigLookupOptions? options = null,
CancellationToken ct = default)
{
return Task.FromResult(System.Collections.Immutable.ImmutableArray.Empty);
}
public Task> IdentifyFunctionFromCorpusAsync(
FunctionFingerprintSet fingerprints,
CorpusLookupOptions? options = null,
CancellationToken ct = default)
{
return Task.FromResult(System.Collections.Immutable.ImmutableArray.Empty);
}
public Task>> IdentifyFunctionsFromCorpusBatchAsync(
IEnumerable<(string Key, FunctionFingerprintSet Fingerprints)> functions,
CorpusLookupOptions? options = null,
CancellationToken ct = default)
{
return Task.FromResult(System.Collections.Immutable.ImmutableDictionary>.Empty);
}
}