Skip to content

Commit 3f3b921

Browse files
author
Jussi Kukkonen
committed
Metadata API: Document serialization "repro" issue
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 #1392 Signed-off-by: Jussi Kukkonen <[email protected]>
1 parent 6c1dfce commit 3f3b921

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

tuf/api/metadata.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,13 @@ def to_bytes(
232232
) -> bytes:
233233
"""Return the serialized TUF file format as bytes.
234234
235+
Note that if bytes are first deserialized into ``Metadata`` and then
236+
serialized with ``to_bytes()``, the two are not required to be
237+
identical even though the signatures are guaranteed to stay valid. If
238+
byte-for-byte equivalence is required (which is the case when content
239+
hashes are used in other metadata), the original content should be used
240+
instead of re-serializing.
241+
235242
Arguments:
236243
serializer: A MetadataSerializer instance that implements the
237244
desired serialization format. Default is JSONSerializer.
@@ -265,6 +272,13 @@ def to_file(
265272
) -> None:
266273
"""Writes TUF metadata to file storage.
267274
275+
Note that if a file is first deserialized into ``Metadata`` and then
276+
serialized with ``to_file()``, the two files are not required to be
277+
identical even though the signatures are guaranteed to stay valid. If
278+
byte-for-byte equivalence is required (which is the case when file
279+
hashes are used in other metadata), the original file should be used
280+
instead of re-serializing.
281+
268282
Arguments:
269283
filename: The path to write the file to.
270284
serializer: A MetadataSerializer instance that implements the

0 commit comments

Comments
 (0)