|
89 | 89 | # Must be 1, or greater. |
90 | 90 | METADATAVERSION_SCHEMA = SCHEMA.Integer(lo=0) |
91 | 91 |
|
| 92 | +# A relative file path (e.g., 'metadata/root/'). |
| 93 | +RELPATH_SCHEMA = SCHEMA.AnyString() |
| 94 | +RELPATHS_SCHEMA = SCHEMA.ListOf(RELPATH_SCHEMA) |
| 95 | + |
92 | 96 | VERSIONINFO_SCHEMA = SCHEMA.Object( |
93 | 97 | object_name = 'VERSIONINFO_SCHEMA', |
94 | 98 | version = METADATAVERSION_SCHEMA) |
95 | 99 |
|
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 | | - |
104 | 100 | # A string representing a role's name. |
105 | 101 | ROLENAME_SCHEMA = SCHEMA.AnyString() |
106 | 102 |
|
| 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 | + |
107 | 117 | # Role object in {'keyids': [keydids..], 'name': 'ABC', 'threshold': 1, |
108 | 118 | # 'paths':[filepaths..]} format. |
109 | 119 | # TODO: This is not a role. In further #660-related PRs, fix it, similar to |
110 | 120 | # the way I did in Uptane's TUF fork. |
111 | 121 | ROLE_SCHEMA = SCHEMA.Object( |
112 | 122 | object_name = 'ROLE_SCHEMA', |
113 | | - name = SCHEMA.Optional(securesystemslib.formats.ROLENAME_SCHEMA), |
| 123 | + name = SCHEMA.Optional(ROLENAME_SCHEMA), |
114 | 124 | keyids = securesystemslib.formats.KEYIDS_SCHEMA, |
115 | | - threshold = securesystemslib.formats.THRESHOLD_SCHEMA, |
| 125 | + threshold = THRESHOLD_SCHEMA, |
116 | 126 | 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)) |
119 | 129 |
|
120 | 130 | # A dict of roles where the dict keys are role names and the dict values holding |
121 | 131 | # the role data/information. |
|
150 | 160 | # A string representing a role's name. |
151 | 161 | ROLENAME_SCHEMA = SCHEMA.AnyString() |
152 | 162 |
|
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 | | - |
158 | 163 | # A hexadecimal value in '23432df87ab..' format. |
159 | 164 | HASH_SCHEMA = SCHEMA.RegularExpression(r'[a-fA-F0-9]+') |
160 | 165 |
|
161 | | -# A hexadecimal value in '23432df87ab..' format. |
162 | | -HEX_SCHEMA = SCHEMA.RegularExpression(r'[a-fA-F0-9]+') |
163 | | - |
164 | 166 | # A key identifier (e.g., a hexadecimal value identifying an RSA key). |
165 | 167 | KEYID_SCHEMA = HASH_SCHEMA |
166 | 168 |
|
|
208 | 210 | unknown_sigs = KEYIDS_SCHEMA, |
209 | 211 | untrusted_sigs = KEYIDS_SCHEMA) |
210 | 212 |
|
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 | | - |
222 | 213 | # Role object in {'keyids': [keydids..], 'name': 'ABC', 'threshold': 1, |
223 | 214 | # 'paths':[filepaths..]} format. |
224 | 215 | ROLE_SCHEMA = SCHEMA.Object( |
|
254 | 245 | version = SCHEMA.Optional(METADATAVERSION_SCHEMA), |
255 | 246 | custom = SCHEMA.Optional(SCHEMA.Object())) |
256 | 247 |
|
| 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 | + |
257 | 256 | # A dict holding the information for a particular target / file. The dict keys |
258 | 257 | # hold the relative file paths, and the dict values the corresponding file |
259 | 258 | # information. |
|
363 | 362 | SNAPSHOT_SCHEMA = SCHEMA.Object( |
364 | 363 | object_name = 'SNAPSHOT_SCHEMA', |
365 | 364 | _type = SCHEMA.String('snapshot'), |
366 | | - version = securesystemslib.formats.METADATAVERSION_SCHEMA, |
| 365 | + version = METADATAVERSION_SCHEMA, |
367 | 366 | expires = securesystemslib.formats.ISO8601_DATETIME_SCHEMA, |
368 | 367 | spec_version = SPECIFICATION_VERSION_SCHEMA, |
369 | 368 | meta = FILEINFODICT_SCHEMA) |
|
373 | 372 | object_name = 'TIMESTAMP_SCHEMA', |
374 | 373 | _type = SCHEMA.String('timestamp'), |
375 | 374 | spec_version = SPECIFICATION_VERSION_SCHEMA, |
376 | | - version = securesystemslib.formats.METADATAVERSION_SCHEMA, |
| 375 | + version = METADATAVERSION_SCHEMA, |
377 | 376 | expires = securesystemslib.formats.ISO8601_DATETIME_SCHEMA, |
378 | | - meta = securesystemslib.formats.FILEDICT_SCHEMA) |
| 377 | + meta = FILEDICT_SCHEMA) |
379 | 378 |
|
380 | 379 |
|
381 | 380 | # project.cfg file: stores information about the project in a json dictionary |
|
395 | 394 | MIRROR_SCHEMA = SCHEMA.Object( |
396 | 395 | object_name = 'MIRROR_SCHEMA', |
397 | 396 | 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, |
401 | 400 | custom = SCHEMA.Optional(SCHEMA.Object())) |
402 | 401 |
|
403 | 402 | # 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): |
801 | 800 | fileinfo['custom'] = custom |
802 | 801 |
|
803 | 802 | # Raise 'securesystemslib.exceptions.FormatError' if the check fails. |
804 | | - securesystemslib.formats.FILEINFO_SCHEMA.check_match(fileinfo) |
| 803 | + FILEINFO_SCHEMA.check_match(fileinfo) |
805 | 804 |
|
806 | 805 | return fileinfo |
807 | 806 |
|
|
0 commit comments