Skip to content

Commit

Permalink
bench: return the intoto payload if requested
Browse files Browse the repository at this point in the history
This will allow further benchmarking for things that need the payload,
such as signing.

Signed-off-by: Spencer Schrock <[email protected]>
  • Loading branch information
spencerschrock committed Jan 24, 2025
1 parent 6cb9ff1 commit d99e271
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions benchmarks/serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import argparse
from collections.abc import Callable
import pathlib
from typing import Optional

from model_signing.hashing import file
from model_signing.hashing import hashing
Expand Down Expand Up @@ -103,7 +104,7 @@ def _hasher_factory(path: pathlib.Path) -> file.FileHasher:
return _hasher_factory


def run(args: argparse.Namespace) -> None:
def run(args: argparse.Namespace) -> Optional[in_toto.IntotoPayload]:
"""Performs the benchmark.
Args:
Expand Down Expand Up @@ -146,29 +147,26 @@ def run(args: argparse.Namespace) -> None:
serializer = serializer_factory(hasher, max_workers=args.max_workers)

# 3. Signing layer
if args.skip_manifest:
in_toto_builder = id # Do nothing, just evaluate the argument
if args.single_digest:
in_toto_builder = in_toto.SingleDigestIntotoPayload
else:
if args.single_digest:
in_toto_builder = in_toto.SingleDigestIntotoPayload
# TODO: Once Python 3.9 support is deprecated revert to `match`
if args.digest_of_digests:
if args.use_shards:
in_toto_builder = in_toto.DigestOfShardDigestsIntotoPayload
else:
in_toto_builder = in_toto.DigestOfDigestsIntotoPayload
else:
# TODO: Once Python 3.9 support is deprecated revert to `match`
if args.digest_of_digests:
if args.use_shards:
in_toto_builder = in_toto.DigestOfShardDigestsIntotoPayload
else:
in_toto_builder = in_toto.DigestOfDigestsIntotoPayload
if args.use_shards:
in_toto_builder = in_toto.ShardDigestsIntotoPayload
else:
if args.use_shards:
in_toto_builder = in_toto.ShardDigestsIntotoPayload
else:
in_toto_builder = in_toto.DigestsIntotoPayload

in_toto_builder = in_toto_builder.from_manifest
in_toto_builder = in_toto.DigestsIntotoPayload

# Put everything together
if not args.dry_run:
in_toto_builder(serializer.serialize(args.path))
manifest = serializer.serialize(args.path)
if not args.skip_manifest:
return in_toto_builder.from_manifest(manifest)


def build_parser() -> argparse.ArgumentParser:
Expand Down

0 comments on commit d99e271

Please sign in to comment.