Skip to content

Commit c86c036

Browse files
committed
Remove deprecated securesystemslib.formats schemas
TUF specific schemas have moved to tuf.formats, ensure they are used throughout and remove stray references to no longer supported schemas in securesystemslib.format Signed-off-by: Joshua Lock <[email protected]>
1 parent 4fb4cb2 commit c86c036

File tree

11 files changed

+65
-66
lines changed

11 files changed

+65
-66
lines changed

tests/test_formats.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ def test_schemas(self):
7171

7272
'SCHEME_SCHEMA': (securesystemslib.formats.SCHEME_SCHEMA, 'rsassa-pss-sha256'),
7373

74-
'RELPATH_SCHEMA': (securesystemslib.formats.RELPATH_SCHEMA, 'metadata/root/'),
74+
'RELPATH_SCHEMA': (tuf.formats.RELPATH_SCHEMA, 'metadata/root/'),
7575

76-
'RELPATHS_SCHEMA': (securesystemslib.formats.RELPATHS_SCHEMA,
76+
'RELPATHS_SCHEMA': (tuf.formats.RELPATHS_SCHEMA,
7777
['targets/role1/', 'targets/role2/']),
7878

7979
'PATH_SCHEMA': (securesystemslib.formats.PATH_SCHEMA, '/home/someuser/'),
@@ -84,10 +84,10 @@ def test_schemas(self):
8484
'URL_SCHEMA': (securesystemslib.formats.URL_SCHEMA,
8585
'https://www.updateframework.com/'),
8686

87-
'VERSION_SCHEMA': (securesystemslib.formats.VERSION_SCHEMA,
87+
'VERSION_SCHEMA': (tuf.formats.VERSION_SCHEMA,
8888
{'major': 1, 'minor': 0, 'fix': 8}),
8989

90-
'LENGTH_SCHEMA': (securesystemslib.formats.LENGTH_SCHEMA, 8),
90+
'LENGTH_SCHEMA': (tuf.formats.LENGTH_SCHEMA, 8),
9191

9292
'NAME_SCHEMA': (securesystemslib.formats.NAME_SCHEMA, 'Marty McFly'),
9393

tests/test_repository_lib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ def test_get_target_hash(self):
417417
'/packages/file2.txt': 'c9c4a5cdd84858dd6a23d98d7e6e6b2aec45034946c16b2200bc317c75415e92'
418418
}
419419
for filepath, target_hash in six.iteritems(expected_target_hashes):
420-
self.assertTrue(securesystemslib.formats.RELPATH_SCHEMA.matches(filepath))
420+
self.assertTrue(tuf.formats.RELPATH_SCHEMA.matches(filepath))
421421
self.assertTrue(securesystemslib.formats.HASH_SCHEMA.matches(target_hash))
422422
self.assertEqual(repo_lib.get_target_hash(filepath), target_hash)
423423

tests/test_updater.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1592,7 +1592,7 @@ def test_9__get_target_hash(self):
15921592
'/Jalape\xc3\xb1o': '78bfd5c314680545eb48ecad508aceb861f8d6e680f4fe1b791da45c298cda88'
15931593
}
15941594
for filepath, target_hash in six.iteritems(expected_target_hashes):
1595-
self.assertTrue(securesystemslib.formats.RELPATH_SCHEMA.matches(filepath))
1595+
self.assertTrue(tuf.formats.RELPATH_SCHEMA.matches(filepath))
15961596
self.assertTrue(securesystemslib.formats.HASH_SCHEMA.matches(target_hash))
15971597
self.assertEqual(self.repository_updater._get_target_hash(filepath), target_hash)
15981598

tuf/client/updater.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2627,7 +2627,7 @@ def targets_of_role(self, rolename='targets'):
26272627

26282628
# Does 'rolename' have the correct format?
26292629
# Raise 'securesystemslib.exceptions.FormatError' if there is a mismatch.
2630-
securesystemslib.formats.RELPATH_SCHEMA.check_match(rolename)
2630+
tuf.formats.RELPATH_SCHEMA.check_match(rolename)
26312631

26322632
# If we've been given a delegated targets role, we don't know how to
26332633
# validate it without knowing what the delegating role is -- there could
@@ -2690,7 +2690,7 @@ def get_one_valid_targetinfo(self, target_filepath):
26902690

26912691
# Does 'target_filepath' have the correct format?
26922692
# Raise 'securesystemslib.exceptions.FormatError' if there is a mismatch.
2693-
securesystemslib.formats.RELPATH_SCHEMA.check_match(target_filepath)
2693+
tuf.formats.RELPATH_SCHEMA.check_match(target_filepath)
26942694

26952695
target_filepath = target_filepath.replace('\\', '/')
26962696

tuf/developer_tool.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ def _save_project_configuration(metadata_directory, targets_directory,
694694
securesystemslib.formats.PATH_SCHEMA.check_match(metadata_directory)
695695
securesystemslib.formats.PATH_SCHEMA.check_match(prefix)
696696
securesystemslib.formats.PATH_SCHEMA.check_match(targets_directory)
697-
securesystemslib.formats.RELPATH_SCHEMA.check_match(project_name)
697+
tuf.formats.RELPATH_SCHEMA.check_match(project_name)
698698

699699
cfg_file_directory = metadata_directory
700700

tuf/download.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def safe_download(url, required_length):
110110
# Do all of the arguments have the appropriate format?
111111
# Raise 'securesystemslib.exceptions.FormatError' if there is a mismatch.
112112
securesystemslib.formats.URL_SCHEMA.check_match(url)
113-
securesystemslib.formats.LENGTH_SCHEMA.check_match(required_length)
113+
tuf.formats.LENGTH_SCHEMA.check_match(required_length)
114114

115115
return _download_file(url, required_length, STRICT_REQUIRED_LENGTH=True)
116116

@@ -161,7 +161,7 @@ def unsafe_download(url, required_length):
161161
# Do all of the arguments have the appropriate format?
162162
# Raise 'securesystemslib.exceptions.FormatError' if there is a mismatch.
163163
securesystemslib.formats.URL_SCHEMA.check_match(url)
164-
securesystemslib.formats.LENGTH_SCHEMA.check_match(required_length)
164+
tuf.formats.LENGTH_SCHEMA.check_match(required_length)
165165

166166
return _download_file(url, required_length, STRICT_REQUIRED_LENGTH=False)
167167

@@ -216,7 +216,7 @@ def _download_file(url, required_length, STRICT_REQUIRED_LENGTH=True):
216216
# Do all of the arguments have the appropriate format?
217217
# Raise 'securesystemslib.exceptions.FormatError' if there is a mismatch.
218218
securesystemslib.formats.URL_SCHEMA.check_match(url)
219-
securesystemslib.formats.LENGTH_SCHEMA.check_match(required_length)
219+
tuf.formats.LENGTH_SCHEMA.check_match(required_length)
220220

221221
# 'url.replace('\\', '/')' is needed for compatibility with Windows-based
222222
# systems, because they might use back-slashes in place of forward-slashes.

tuf/formats.py

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -89,33 +89,43 @@
8989
# Must be 1, or greater.
9090
METADATAVERSION_SCHEMA = SCHEMA.Integer(lo=0)
9191

92+
# A relative file path (e.g., 'metadata/root/').
93+
RELPATH_SCHEMA = SCHEMA.AnyString()
94+
RELPATHS_SCHEMA = SCHEMA.ListOf(RELPATH_SCHEMA)
95+
9296
VERSIONINFO_SCHEMA = SCHEMA.Object(
9397
object_name = 'VERSIONINFO_SCHEMA',
9498
version = METADATAVERSION_SCHEMA)
9599

96-
# A dict holding the version or file information for a particular metadata
97-
# role. The dict keys hold the relative file paths, and the dict values the
98-
# corresponding version numbers and/or file information.
99-
FILEINFODICT_SCHEMA = SCHEMA.DictOf(
100-
key_schema = securesystemslib.formats.RELPATH_SCHEMA,
101-
value_schema = SCHEMA.OneOf([VERSIONINFO_SCHEMA,
102-
securesystemslib.formats.FILEINFO_SCHEMA]))
103-
104100
# A string representing a role's name.
105101
ROLENAME_SCHEMA = SCHEMA.AnyString()
106102

103+
# A role's threshold value (i.e., the minimum number
104+
# of signatures required to sign a metadata file).
105+
# Must be 1 and greater.
106+
THRESHOLD_SCHEMA = SCHEMA.Integer(lo=1)
107+
108+
# A hexadecimal value in '23432df87ab..' format.
109+
HEX_SCHEMA = SCHEMA.RegularExpression(r'[a-fA-F0-9]+')
110+
111+
# A path hash prefix is a hexadecimal string.
112+
PATH_HASH_PREFIX_SCHEMA = HEX_SCHEMA
113+
114+
# A list of path hash prefixes.
115+
PATH_HASH_PREFIXES_SCHEMA = SCHEMA.ListOf(PATH_HASH_PREFIX_SCHEMA)
116+
107117
# Role object in {'keyids': [keydids..], 'name': 'ABC', 'threshold': 1,
108118
# 'paths':[filepaths..]} format.
109119
# TODO: This is not a role. In further #660-related PRs, fix it, similar to
110120
# the way I did in Uptane's TUF fork.
111121
ROLE_SCHEMA = SCHEMA.Object(
112122
object_name = 'ROLE_SCHEMA',
113-
name = SCHEMA.Optional(securesystemslib.formats.ROLENAME_SCHEMA),
123+
name = SCHEMA.Optional(ROLENAME_SCHEMA),
114124
keyids = securesystemslib.formats.KEYIDS_SCHEMA,
115-
threshold = securesystemslib.formats.THRESHOLD_SCHEMA,
125+
threshold = THRESHOLD_SCHEMA,
116126
terminating = SCHEMA.Optional(securesystemslib.formats.BOOLEAN_SCHEMA),
117-
paths = SCHEMA.Optional(securesystemslib.formats.RELPATHS_SCHEMA),
118-
path_hash_prefixes = SCHEMA.Optional(securesystemslib.formats.PATH_HASH_PREFIXES_SCHEMA))
127+
paths = SCHEMA.Optional(RELPATHS_SCHEMA),
128+
path_hash_prefixes = SCHEMA.Optional(PATH_HASH_PREFIXES_SCHEMA))
119129

120130
# A dict of roles where the dict keys are role names and the dict values holding
121131
# the role data/information.
@@ -150,17 +160,9 @@
150160
# A string representing a role's name.
151161
ROLENAME_SCHEMA = SCHEMA.AnyString()
152162

153-
# A role's threshold value (i.e., the minimum number
154-
# of signatures required to sign a metadata file).
155-
# Must be 1 and greater.
156-
THRESHOLD_SCHEMA = SCHEMA.Integer(lo=1)
157-
158163
# A hexadecimal value in '23432df87ab..' format.
159164
HASH_SCHEMA = SCHEMA.RegularExpression(r'[a-fA-F0-9]+')
160165

161-
# A hexadecimal value in '23432df87ab..' format.
162-
HEX_SCHEMA = SCHEMA.RegularExpression(r'[a-fA-F0-9]+')
163-
164166
# A key identifier (e.g., a hexadecimal value identifying an RSA key).
165167
KEYID_SCHEMA = HASH_SCHEMA
166168

@@ -208,17 +210,6 @@
208210
unknown_sigs = KEYIDS_SCHEMA,
209211
untrusted_sigs = KEYIDS_SCHEMA)
210212

211-
212-
# A relative file path (e.g., 'metadata/root/').
213-
RELPATH_SCHEMA = SCHEMA.AnyString()
214-
RELPATHS_SCHEMA = SCHEMA.ListOf(RELPATH_SCHEMA)
215-
216-
# A path hash prefix is a hexadecimal string.
217-
PATH_HASH_PREFIX_SCHEMA = HEX_SCHEMA
218-
219-
# A list of path hash prefixes.
220-
PATH_HASH_PREFIXES_SCHEMA = SCHEMA.ListOf(PATH_HASH_PREFIX_SCHEMA)
221-
222213
# Role object in {'keyids': [keydids..], 'name': 'ABC', 'threshold': 1,
223214
# 'paths':[filepaths..]} format.
224215
ROLE_SCHEMA = SCHEMA.Object(
@@ -254,6 +245,14 @@
254245
version = SCHEMA.Optional(METADATAVERSION_SCHEMA),
255246
custom = SCHEMA.Optional(SCHEMA.Object()))
256247

248+
# A dict holding the version or file information for a particular metadata
249+
# role. The dict keys hold the relative file paths, and the dict values the
250+
# corresponding version numbers and/or file information.
251+
FILEINFODICT_SCHEMA = SCHEMA.DictOf(
252+
key_schema = RELPATH_SCHEMA,
253+
value_schema = SCHEMA.OneOf([VERSIONINFO_SCHEMA,
254+
FILEINFO_SCHEMA]))
255+
257256
# A dict holding the information for a particular target / file. The dict keys
258257
# hold the relative file paths, and the dict values the corresponding file
259258
# information.
@@ -363,7 +362,7 @@
363362
SNAPSHOT_SCHEMA = SCHEMA.Object(
364363
object_name = 'SNAPSHOT_SCHEMA',
365364
_type = SCHEMA.String('snapshot'),
366-
version = securesystemslib.formats.METADATAVERSION_SCHEMA,
365+
version = METADATAVERSION_SCHEMA,
367366
expires = securesystemslib.formats.ISO8601_DATETIME_SCHEMA,
368367
spec_version = SPECIFICATION_VERSION_SCHEMA,
369368
meta = FILEINFODICT_SCHEMA)
@@ -373,9 +372,9 @@
373372
object_name = 'TIMESTAMP_SCHEMA',
374373
_type = SCHEMA.String('timestamp'),
375374
spec_version = SPECIFICATION_VERSION_SCHEMA,
376-
version = securesystemslib.formats.METADATAVERSION_SCHEMA,
375+
version = METADATAVERSION_SCHEMA,
377376
expires = securesystemslib.formats.ISO8601_DATETIME_SCHEMA,
378-
meta = securesystemslib.formats.FILEDICT_SCHEMA)
377+
meta = FILEDICT_SCHEMA)
379378

380379

381380
# project.cfg file: stores information about the project in a json dictionary
@@ -395,9 +394,9 @@
395394
MIRROR_SCHEMA = SCHEMA.Object(
396395
object_name = 'MIRROR_SCHEMA',
397396
url_prefix = securesystemslib.formats.URL_SCHEMA,
398-
metadata_path = securesystemslib.formats.RELPATH_SCHEMA,
399-
targets_path = securesystemslib.formats.RELPATH_SCHEMA,
400-
confined_target_dirs = securesystemslib.formats.RELPATHS_SCHEMA,
397+
metadata_path = RELPATH_SCHEMA,
398+
targets_path = RELPATH_SCHEMA,
399+
confined_target_dirs = RELPATHS_SCHEMA,
401400
custom = SCHEMA.Optional(SCHEMA.Object()))
402401

403402
# A dictionary of mirrors where the dict keys hold the mirror's name and
@@ -801,7 +800,7 @@ def make_fileinfo(length, hashes, version=None, custom=None):
801800
fileinfo['custom'] = custom
802801

803802
# Raise 'securesystemslib.exceptions.FormatError' if the check fails.
804-
securesystemslib.formats.FILEINFO_SCHEMA.check_match(fileinfo)
803+
FILEINFO_SCHEMA.check_match(fileinfo)
805804

806805
return fileinfo
807806

tuf/mirrors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def get_list_of_mirrors(file_type, file_path, mirrors_dict):
8484
"""
8585

8686
# Checking if all the arguments have appropriate format.
87-
securesystemslib.formats.RELPATH_SCHEMA.check_match(file_path)
87+
tuf.formats.RELPATH_SCHEMA.check_match(file_path)
8888
tuf.formats.MIRRORDICT_SCHEMA.check_match(mirrors_dict)
8989
securesystemslib.formats.NAME_SCHEMA.check_match(file_type)
9090

tuf/repository_lib.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,7 +1203,7 @@ def get_target_hash(target_filepath):
12031203
The hash of 'target_filepath'.
12041204
12051205
"""
1206-
securesystemslib.formats.RELPATH_SCHEMA.check_match(target_filepath)
1206+
tuf.formats.RELPATH_SCHEMA.check_match(target_filepath)
12071207

12081208
# Calculate the hash of the filepath to determine which bin to find the
12091209
# target. The client currently assumes the repository uses
@@ -1416,7 +1416,7 @@ def generate_targets_metadata(targets_directory, target_files, version,
14161416
# types, and that all dict keys are properly named.
14171417
# Raise 'securesystemslib.exceptions.FormatError' if there is a mismatch.
14181418
securesystemslib.formats.PATH_SCHEMA.check_match(targets_directory)
1419-
securesystemslib.formats.PATH_FILEINFO_SCHEMA.check_match(target_files)
1419+
tuf.formats.PATH_FILEINFO_SCHEMA.check_match(target_files)
14201420
tuf.formats.METADATAVERSION_SCHEMA.check_match(version)
14211421
securesystemslib.formats.ISO8601_DATETIME_SCHEMA.check_match(expiration_date)
14221422
securesystemslib.formats.BOOLEAN_SCHEMA.check_match(write_consistent_targets)

tuf/repository_tool.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,7 +1049,7 @@ def version(self):
10491049
"""
10501050
<Purpose>
10511051
A getter method that returns the role's version number, conformant to
1052-
'securesystemslib.formats.VERSION_SCHEMA'.
1052+
'tuf.formats.VERSION_SCHEMA'.
10531053
10541054
<Arguments>
10551055
None.
@@ -1062,7 +1062,7 @@ def version(self):
10621062
10631063
<Returns>
10641064
The role's version number, conformant to
1065-
'securesystemslib.formats.VERSION_SCHEMA'.
1065+
'tuf.formats.VERSION_SCHEMA'.
10661066
"""
10671067

10681068
roleinfo = tuf.roledb.get_roleinfo(self.rolename, self._repository_name)
@@ -1094,7 +1094,7 @@ def version(self, version):
10941094
<Arguments>
10951095
version:
10961096
The role's version number, conformant to
1097-
'securesystemslib.formats.VERSION_SCHEMA'.
1097+
'tuf.formats.VERSION_SCHEMA'.
10981098
10991099
<Exceptions>
11001100
securesystemslib.exceptions.FormatError, if the 'version' argument is
@@ -1140,7 +1140,7 @@ def threshold(self):
11401140
11411141
<Returns>
11421142
The role's threshold value, conformant to
1143-
'securesystemslib.formats.THRESHOLD_SCHEMA'.
1143+
'tuf.formats.THRESHOLD_SCHEMA'.
11441144
"""
11451145

11461146
roleinfo = tuf.roledb.get_roleinfo(self._rolename, self._repository_name)
@@ -1166,7 +1166,7 @@ def threshold(self, threshold):
11661166
threshold:
11671167
An integer value that sets the role's threshold value, or the minimum
11681168
number of signatures needed for metadata to be considered fully
1169-
signed. Conformant to 'securesystemslib.formats.THRESHOLD_SCHEMA'.
1169+
signed. Conformant to 'tuf.formats.THRESHOLD_SCHEMA'.
11701170
11711171
<Exceptions>
11721172
securesystemslib.exceptions.FormatError, if the 'threshold' argument is
@@ -1184,7 +1184,7 @@ def threshold(self, threshold):
11841184
# Ensure the arguments have the appropriate number of objects and object
11851185
# types, and that all dict keys are properly named. Raise
11861186
# 'securesystemslib.exceptions.FormatError' if any are improperly formatted.
1187-
securesystemslib.formats.THRESHOLD_SCHEMA.check_match(threshold)
1187+
tuf.formats.THRESHOLD_SCHEMA.check_match(threshold)
11881188

11891189
roleinfo = tuf.roledb.get_roleinfo(self._rolename, self._repository_name)
11901190
roleinfo['previous_threshold'] = roleinfo['threshold']
@@ -1983,7 +1983,7 @@ def add_targets(self, list_of_targets):
19831983
# Ensure the arguments have the appropriate number of objects and object
19841984
# types, and that all dict keys are properly named.
19851985
# Raise 'securesystemslib.exceptions.FormatError' if there is a mismatch.
1986-
securesystemslib.formats.RELPATHS_SCHEMA.check_match(list_of_targets)
1986+
tuf.formats.RELPATHS_SCHEMA.check_match(list_of_targets)
19871987

19881988
# Update the tuf.roledb entry.
19891989
targets_directory_length = len(self._targets_directory)
@@ -2054,7 +2054,7 @@ def remove_target(self, filepath):
20542054
# Ensure the arguments have the appropriate number of objects and object
20552055
# types, and that all dict keys are properly named. Raise
20562056
# 'securesystemslib.exceptions.FormatError' if there is a mismatch.
2057-
securesystemslib.formats.RELPATH_SCHEMA.check_match(filepath)
2057+
tuf.formats.RELPATH_SCHEMA.check_match(filepath)
20582058

20592059
# Remove 'relative_filepath', if found, and update this Targets roleinfo.
20602060
fileinfo = tuf.roledb.get_roleinfo(self.rolename, self._repository_name)
@@ -2211,15 +2211,15 @@ def delegate(self, rolename, public_keys, paths, threshold=1,
22112211
# Raise 'securesystemslib.exceptions.FormatError' if there is a mismatch.
22122212
tuf.formats.ROLENAME_SCHEMA.check_match(rolename)
22132213
securesystemslib.formats.ANYKEYLIST_SCHEMA.check_match(public_keys)
2214-
securesystemslib.formats.RELPATHS_SCHEMA.check_match(paths)
2215-
securesystemslib.formats.THRESHOLD_SCHEMA.check_match(threshold)
2214+
tuf.formats.RELPATHS_SCHEMA.check_match(paths)
2215+
tuf.formats.THRESHOLD_SCHEMA.check_match(threshold)
22162216
securesystemslib.formats.BOOLEAN_SCHEMA.check_match(terminating)
22172217

22182218
if list_of_targets is not None:
2219-
securesystemslib.formats.RELPATHS_SCHEMA.check_match(list_of_targets)
2219+
tuf.formats.RELPATHS_SCHEMA.check_match(list_of_targets)
22202220

22212221
if path_hash_prefixes is not None:
2222-
securesystemslib.formats.PATH_HASH_PREFIXES_SCHEMA.check_match(path_hash_prefixes)
2222+
tuf.formats.PATH_HASH_PREFIXES_SCHEMA.check_match(path_hash_prefixes)
22232223

22242224
# Keep track of the valid keyids (added to the new Targets object) and
22252225
# their keydicts (added to this Targets delegations).

0 commit comments

Comments
 (0)