Skip to content

Commit 70c7358

Browse files
authored
Merge pull request #1800 from jku/document-serialization-hash-issue
Metadata API: Document serialization "repro" issue
2 parents 8a0bb88 + 3f3b921 commit 70c7358

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)