Files
ScadaBridge/src/ZB.MOM.WW.ScadaBridge.Transport/Serialization/ManifestValidator.cs
T
Joseph Doherty 7b0b9c7365 refactor: rename ScadaLink → ZB.MOM.WW.ScadaBridge (code + projects + namespaces)
Solution + 23 src projects + 26 test projects renamed; folders, csproj,
namespaces, and ScadaLinkDbContext/ScadaBridgeDbContext class updated.
ActorSystem "scadalink" → "scadabridge", Akka seed-node URLs migrated.
SQL roles/logins, LDAP domains, CLI command name, and CLI config dir
(~/.scadalink → ~/.scadabridge) also renamed.

Build green; 5 Host.Tests fail awaiting SQL login rename in next commit.
Pre-existing StaleTagMonitor timing flakes unchanged.

Rename script committed at tools/rename-to-scadabridge.sh.
2026-05-28 09:37:45 -04:00

55 lines
2.1 KiB
C#

using System.Security.Cryptography;
using ZB.MOM.WW.ScadaBridge.Commons.Types.Transport;
namespace ZB.MOM.WW.ScadaBridge.Transport.Serialization;
/// <summary>
/// Outcome of validating a <see cref="BundleManifest"/> against the supplied
/// raw content bytes. Distinct values let the importer surface a precise
/// rejection reason to the operator.
/// </summary>
public enum ManifestValidationResult
{
Ok,
UnsupportedFormatVersion,
ContentHashMismatch,
MalformedManifest
}
/// <summary>
/// Inspects a deserialized manifest plus the raw content bytes recovered from
/// the bundle ZIP and reports the first integrity failure (or <see cref="ManifestValidationResult.Ok"/>).
/// </summary>
public sealed class ManifestValidator
{
/// <summary>Validates a deserialized bundle manifest against the raw content bytes and returns the first integrity failure, or <see cref="ManifestValidationResult.Ok"/>.</summary>
/// <param name="manifest">The deserialized manifest to validate.</param>
/// <param name="contentBytes">The raw content bytes extracted from the bundle ZIP.</param>
/// <returns>A <see cref="ManifestValidationResult"/> indicating success or the specific failure kind.</returns>
public ManifestValidationResult Validate(BundleManifest manifest, byte[] contentBytes)
{
if (manifest is null || contentBytes is null)
{
return ManifestValidationResult.MalformedManifest;
}
if (string.IsNullOrEmpty(manifest.SourceEnvironment) || manifest.Contents is null)
{
return ManifestValidationResult.MalformedManifest;
}
if (manifest.BundleFormatVersion != ManifestBuilder.CurrentBundleFormatVersion)
{
return ManifestValidationResult.UnsupportedFormatVersion;
}
var expected = "sha256:" + Convert.ToHexString(SHA256.HashData(contentBytes)).ToLowerInvariant();
if (!string.Equals(expected, manifest.ContentHash, StringComparison.Ordinal))
{
return ManifestValidationResult.ContentHashMismatch;
}
return ManifestValidationResult.Ok;
}
}