Skip to content

Commit

Permalink
Metadata API: Document serialization "repro" issue
Browse files Browse the repository at this point in the history
It's not obvious to casual reader that reading metadata and then
writing it might not always produce the same file. It's also not
immediately obvious why this matters.

Document both concepts.

Fixes theupdateframework#1392

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
  • Loading branch information
Jussi Kukkonen committed Jan 26, 2022
1 parent e0736d6 commit 4eea98e
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions tuf/api/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,13 @@ def to_bytes(
) -> bytes:
"""Return the serialized TUF file format as bytes.
Note that if bytes are first deserialized into ``Metadata`` and then
serialized with ``to_bytes()``, the two are not guaranteed to be the
same because of whitespace issues. If byte-for-byte equivalence is
required (which is the case when the content hashes have already been
inserted into other metadata), the original content should be used
instead of re-serializing.
Arguments:
serializer: A MetadataSerializer instance that implements the
desired serialization format. Default is JSONSerializer.
Expand Down Expand Up @@ -265,6 +272,13 @@ def to_file(
) -> None:
"""Writes TUF metadata to file storage.
Note that if a file is first deserialized into ``Metadata`` and then
serialized with ``to_file()``, the two files are not guaranteed to be
the same because of whitespace issues. If byte-for-byte equivalence is
required (which is the case when file hashes have already been inserted
into other metadata), the original file should be used instead of
re-serializing.
Arguments:
filename: The path to write the file to.
serializer: A MetadataSerializer instance that implements the
Expand Down

0 comments on commit 4eea98e

Please sign in to comment.