Some checks failed
Docs CI / lint-and-preview (push) Has been cancelled
feat: Implement BsonJsonConverter for converting BsonDocument and BsonArray to JSON fix: Update project file to include MongoDB.Bson package test: Add GraphOverlayExporterTests to validate NDJSON export functionality refactor: Refactor Program.cs in Attestation Tool for improved argument parsing and error handling docs: Update README for stella-forensic-verify with usage instructions and exit codes feat: Enhance HmacVerifier with clock skew and not-after checks feat: Add MerkleRootVerifier and ChainOfCustodyVerifier for additional verification methods fix: Update DenoRuntimeShim to correctly handle file paths feat: Introduce ComposerAutoloadData and related parsing in ComposerLockReader test: Add tests for Deno runtime execution and verification test: Enhance PHP package tests to include autoload data verification test: Add unit tests for HmacVerifier and verification logic
108 lines
3.5 KiB
C#
108 lines
3.5 KiB
C#
namespace StellaOps.Scanner.Analyzers.Lang.Php.Internal;
|
|
|
|
internal sealed class PhpPackage
|
|
{
|
|
private readonly ComposerPackage _package;
|
|
private readonly ComposerLockData _lockData;
|
|
|
|
public PhpPackage(ComposerPackage package, ComposerLockData lockData)
|
|
{
|
|
_package = package ?? throw new ArgumentNullException(nameof(package));
|
|
_lockData = lockData ?? throw new ArgumentNullException(nameof(lockData));
|
|
}
|
|
|
|
public string Name => _package.Name;
|
|
|
|
public string Version => _package.Version;
|
|
|
|
public string Purl => $"pkg:composer/{Name}@{Version}";
|
|
|
|
public string ComponentKey => $"purl::{Purl}";
|
|
|
|
public IEnumerable<KeyValuePair<string, string?>> CreateMetadata()
|
|
{
|
|
yield return new KeyValuePair<string, string?>("composer.dev", _package.IsDev ? "true" : "false");
|
|
|
|
if (!string.IsNullOrWhiteSpace(_package.Type))
|
|
{
|
|
yield return new KeyValuePair<string, string?>("composer.type", _package.Type);
|
|
}
|
|
|
|
if (!string.IsNullOrWhiteSpace(_package.SourceType))
|
|
{
|
|
yield return new KeyValuePair<string, string?>("composer.source.type", _package.SourceType);
|
|
}
|
|
|
|
if (!string.IsNullOrWhiteSpace(_package.SourceReference))
|
|
{
|
|
yield return new KeyValuePair<string, string?>("composer.source.ref", _package.SourceReference);
|
|
}
|
|
|
|
if (!_package.Autoload.IsEmpty)
|
|
{
|
|
if (_package.Autoload.Psr4.Count > 0)
|
|
{
|
|
yield return new KeyValuePair<string, string?>(
|
|
"composer.autoload.psr4",
|
|
string.Join(';', _package.Autoload.Psr4));
|
|
}
|
|
|
|
if (_package.Autoload.Classmap.Count > 0)
|
|
{
|
|
yield return new KeyValuePair<string, string?>(
|
|
"composer.autoload.classmap",
|
|
string.Join(';', _package.Autoload.Classmap));
|
|
}
|
|
|
|
if (_package.Autoload.Files.Count > 0)
|
|
{
|
|
yield return new KeyValuePair<string, string?>(
|
|
"composer.autoload.files",
|
|
string.Join(';', _package.Autoload.Files));
|
|
}
|
|
}
|
|
|
|
if (!string.IsNullOrWhiteSpace(_package.DistSha256))
|
|
{
|
|
yield return new KeyValuePair<string, string?>("composer.dist.sha256", _package.DistSha256);
|
|
}
|
|
|
|
if (!string.IsNullOrWhiteSpace(_package.DistUrl))
|
|
{
|
|
yield return new KeyValuePair<string, string?>("composer.dist.url", _package.DistUrl);
|
|
}
|
|
|
|
if (!string.IsNullOrWhiteSpace(_lockData.PluginApiVersion))
|
|
{
|
|
yield return new KeyValuePair<string, string?>("composer.plugin_api_version", _lockData.PluginApiVersion);
|
|
}
|
|
|
|
if (!string.IsNullOrWhiteSpace(_lockData.ContentHash))
|
|
{
|
|
yield return new KeyValuePair<string, string?>("composer.content_hash", _lockData.ContentHash);
|
|
}
|
|
|
|
foreach (var signal in PhpCapabilitySignals.FromPackage(_package))
|
|
{
|
|
yield return signal;
|
|
}
|
|
}
|
|
|
|
public IReadOnlyCollection<LanguageComponentEvidence> CreateEvidence()
|
|
{
|
|
var locator = string.IsNullOrWhiteSpace(_lockData.LockPath)
|
|
? "composer.lock"
|
|
: Path.GetFileName(_lockData.LockPath);
|
|
|
|
return new[]
|
|
{
|
|
new LanguageComponentEvidence(
|
|
LanguageEvidenceKind.File,
|
|
"composer.lock",
|
|
locator,
|
|
Value: $"{Name}@{Version}",
|
|
Sha256: _lockData.LockSha256)
|
|
};
|
|
}
|
|
}
|