|
17 | 17 | import argparse |
18 | 18 | from collections.abc import Callable |
19 | 19 | import pathlib |
| 20 | +from typing import Optional |
20 | 21 |
|
21 | 22 | from model_signing.hashing import file |
22 | 23 | from model_signing.hashing import hashing |
@@ -103,7 +104,7 @@ def _hasher_factory(path: pathlib.Path) -> file.FileHasher: |
103 | 104 | return _hasher_factory |
104 | 105 |
|
105 | 106 |
|
106 | | -def run(args: argparse.Namespace) -> None: |
| 107 | +def run(args: argparse.Namespace) -> Optional[in_toto.IntotoPayload]: |
107 | 108 | """Performs the benchmark. |
108 | 109 |
|
109 | 110 | Args: |
@@ -146,29 +147,26 @@ def run(args: argparse.Namespace) -> None: |
146 | 147 | serializer = serializer_factory(hasher, max_workers=args.max_workers) |
147 | 148 |
|
148 | 149 | # 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 |
151 | 152 | 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 |
154 | 159 | 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 |
161 | 162 | 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 |
168 | 164 |
|
169 | 165 | # Put everything together |
170 | 166 | 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) |
172 | 170 |
|
173 | 171 |
|
174 | 172 | def build_parser() -> argparse.ArgumentParser: |
|
0 commit comments