Skip to content

Commit d1cc550

Browse files
bench: return the intoto payload if requested (#349)
This will allow further benchmarking for things that need the payload, such as signing. Signed-off-by: Spencer Schrock <[email protected]>
1 parent 6cb9ff1 commit d1cc550

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

benchmarks/serialize.py

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import argparse
1818
from collections.abc import Callable
1919
import pathlib
20+
from typing import Optional
2021

2122
from model_signing.hashing import file
2223
from model_signing.hashing import hashing
@@ -103,7 +104,7 @@ def _hasher_factory(path: pathlib.Path) -> file.FileHasher:
103104
return _hasher_factory
104105

105106

106-
def run(args: argparse.Namespace) -> None:
107+
def run(args: argparse.Namespace) -> Optional[in_toto.IntotoPayload]:
107108
"""Performs the benchmark.
108109
109110
Args:
@@ -146,29 +147,26 @@ def run(args: argparse.Namespace) -> None:
146147
serializer = serializer_factory(hasher, max_workers=args.max_workers)
147148

148149
# 3. Signing layer
149-
if args.skip_manifest:
150-
in_toto_builder = id # Do nothing, just evaluate the argument
150+
if args.single_digest:
151+
in_toto_builder = in_toto.SingleDigestIntotoPayload
151152
else:
152-
if args.single_digest:
153-
in_toto_builder = in_toto.SingleDigestIntotoPayload
153+
# TODO: Once Python 3.9 support is deprecated revert to `match`
154+
if args.digest_of_digests:
155+
if args.use_shards:
156+
in_toto_builder = in_toto.DigestOfShardDigestsIntotoPayload
157+
else:
158+
in_toto_builder = in_toto.DigestOfDigestsIntotoPayload
154159
else:
155-
# TODO: Once Python 3.9 support is deprecated revert to `match`
156-
if args.digest_of_digests:
157-
if args.use_shards:
158-
in_toto_builder = in_toto.DigestOfShardDigestsIntotoPayload
159-
else:
160-
in_toto_builder = in_toto.DigestOfDigestsIntotoPayload
160+
if args.use_shards:
161+
in_toto_builder = in_toto.ShardDigestsIntotoPayload
161162
else:
162-
if args.use_shards:
163-
in_toto_builder = in_toto.ShardDigestsIntotoPayload
164-
else:
165-
in_toto_builder = in_toto.DigestsIntotoPayload
166-
167-
in_toto_builder = in_toto_builder.from_manifest
163+
in_toto_builder = in_toto.DigestsIntotoPayload
168164

169165
# Put everything together
170166
if not args.dry_run:
171-
in_toto_builder(serializer.serialize(args.path))
167+
manifest = serializer.serialize(args.path)
168+
if not args.skip_manifest:
169+
return in_toto_builder.from_manifest(manifest)
172170

173171

174172
def build_parser() -> argparse.ArgumentParser:

0 commit comments

Comments
 (0)