22
22
from collections import OrderedDict
23
23
from datetime import datetime , timedelta
24
24
from pathlib import Path
25
+ from typing import Any , Dict , Iterator , List , Tuple
25
26
26
27
from securesystemslib .keys import generate_ed25519_key
27
28
from securesystemslib .signer import SSlibSigner
37
38
from tuf .api .serialization .json import JSONSerializer
38
39
39
40
40
- def _in (days ) :
41
+ def _in (days : float ) -> datetime :
41
42
"""Adds 'days' to now and returns datetime object w/o microseconds."""
42
43
return datetime .utcnow ().replace (microsecond = 0 ) + timedelta (days = days )
43
44
44
45
45
46
SPEC_VERSION = "1.0.19"
46
- roles = {}
47
- keys = {}
47
+ roles : Dict [ str , Metadata ] = {}
48
+ keys : Dict [ str , Dict [ str , Any ]] = {}
48
49
49
50
# Hash bin delegation
50
51
# ===================
@@ -83,7 +84,7 @@ def _in(days):
83
84
84
85
# Helpers
85
86
# -------
86
- def _bin_name (low , high ) :
87
+ def _bin_name (low : int , high : int ) -> str :
87
88
"""Generates a bin name according to the hash prefixes the bin serves.
88
89
89
90
The name is either a single hash prefix for bin size 1, or a range of hash
@@ -96,7 +97,7 @@ def _bin_name(low, high):
96
97
return f"{ low :0{PREFIX_LEN }x} -{ high :0{PREFIX_LEN }x} "
97
98
98
99
99
- def generate_hash_bins ():
100
+ def generate_hash_bins () -> Iterator [ Tuple [ str , List [ str ]]] :
100
101
"""Returns generator for bin names and hash prefixes per bin."""
101
102
# Iterate over the total number of hash prefixes in 'bin size'-steps to
102
103
# generate bin names and a list of hash prefixes served by each bin.
@@ -110,7 +111,7 @@ def generate_hash_bins():
110
111
yield bin_name , hash_prefixes
111
112
112
113
113
- def find_hash_bin (path ) :
114
+ def find_hash_bin (path : str ) -> str :
114
115
"""Returns name of bin for target file based on the target path hash."""
115
116
# Generate hash digest of passed target path and take its prefix, given the
116
117
# global prefix length for the given number of bins.
@@ -201,7 +202,7 @@ def find_hash_bin(path):
201
202
# about adding target file infos to targets metadata.
202
203
local_path = Path (__file__ ).resolve ()
203
204
target_path = f"{ local_path .parts [- 2 ]} /{ local_path .parts [- 1 ]} "
204
- target_file_info = TargetFile .from_file (target_path , local_path )
205
+ target_file_info = TargetFile .from_file (target_path , str ( local_path ) )
205
206
206
207
# The right bin for a target file is determined by the 'target_path' hash, e.g.:
207
208
#
0 commit comments