Class ManifestCanonicalizer

java.lang.Object
com.marksayson.deletionchecker.manifest.ManifestCanonicalizer

public final class ManifestCanonicalizer extends Object
Serializes a manifest to its canonical JSON form: keys in ascending order, no insignificant whitespace, and the manifestChecksum field omitted. Generation and verification both hash this exact byte sequence, so they always agree regardless of how a manifest file is actually formatted.

Manifest string values must not contain a quote, a backslash, or a control character — the generator's inputs (entity types, file names, versions, timestamps) never do, and forbidding them keeps the canonical form escape-free and unambiguous.

  • Field Details

    • CHECKSUM_PREFIX

      public static final String CHECKSUM_PREFIX
      Algorithm prefix on a manifestChecksum value: "sha256:".
      See Also:
  • Method Details

    • checksum

      public static String checksum(String canonicalJson)
      Returns the manifestChecksum value for the manifest whose checksum-free canonical form is canonicalJson: CHECKSUM_PREFIX followed by the lowercase-hex SHA-256 of that form's UTF-8 bytes. The writer stores this; verification recomputes it the same way, so both sides always agree.
      Parameters:
      canonicalJson - a manifest's canonical form, as returned by canonicalize(com.marksayson.deletionchecker.manifest.DatasetManifest)
      Returns:
      the manifestChecksum value
    • canonicalize

      public static String canonicalize(DatasetManifest manifest)
      Returns the canonical JSON for manifest, without a manifestChecksum field.
      Parameters:
      manifest - the manifest to serialize
      Returns:
      the canonical JSON string
      Throws:
      IllegalArgumentException - if any string value contains a quote, backslash, or control character