1# Copyright 2021, New York University and the TUF contributors
2# SPDX-License-Identifier: MIT OR Apache-2.0
3
4"""Configuration options for ``Updater`` class."""
5
6from __future__ import annotations
7
8from dataclasses import dataclass
9from enum import Flag, unique
10
11
12@unique
13class EnvelopeType(Flag):
14 """Configures deserialization and verification mode of TUF metadata.
15
16 Args:
17 METADATA: Traditional canonical JSON -based TUF Metadata.
18 SIMPLE: Dead Simple Signing Envelope. (experimental)
19 """
20
21 METADATA = 1
22 SIMPLE = 2
23
24
25@dataclass
26class UpdaterConfig:
27 """Used to store ``Updater`` configuration.
28
29 Args:
30 max_root_rotations: Maximum number of root rotations.
31 max_delegations: Maximum number of delegations.
32 root_max_length: Maximum length of a root metadata file.
33 timestamp_max_length: Maximum length of a timestamp metadata file.
34 snapshot_max_length: Maximum length of a snapshot metadata file.
35 targets_max_length: Maximum length of a targets metadata file.
36 prefix_targets_with_hash: When `consistent snapshots
37 <https://theupdateframework.github.io/specification/latest/#consistent-snapshots>`_
38 are used, target download URLs are formed by prefixing the filename
39 with a hash digest of file content by default. This can be
40 overridden by setting ``prefix_targets_with_hash`` to ``False``.
41 envelope_type: Configures deserialization and verification mode of TUF
42 metadata. Per default, it is treated as traditional canonical JSON
43 -based TUF Metadata.
44 app_user_agent: Application user agent, e.g. "MyApp/1.0.0". This will be
45 prefixed to ngclient user agent when the default fetcher is used.
46 """
47
48 max_root_rotations: int = 256
49 max_delegations: int = 32
50 root_max_length: int = 512000 # bytes
51 timestamp_max_length: int = 16384 # bytes
52 snapshot_max_length: int = 2000000 # bytes
53 targets_max_length: int = 5000000 # bytes
54 prefix_targets_with_hash: bool = True
55 envelope_type: EnvelopeType = EnvelopeType.METADATA
56 app_user_agent: str | None = None