|
95 | 95 | # Must be 1, or greater. |
96 | 96 | METADATAVERSION_SCHEMA = SCHEMA.Integer(lo=0) |
97 | 97 |
|
| 98 | +# A relative file path (e.g., 'metadata/root/'). |
| 99 | +RELPATH_SCHEMA = SCHEMA.AnyString() |
| 100 | +RELPATHS_SCHEMA = SCHEMA.ListOf(RELPATH_SCHEMA) |
| 101 | + |
98 | 102 | VERSIONINFO_SCHEMA = SCHEMA.Object( |
99 | 103 | object_name = 'VERSIONINFO_SCHEMA', |
100 | 104 | version = METADATAVERSION_SCHEMA) |
101 | 105 |
|
102 | | -# A dict holding the version or file information for a particular metadata |
103 | | -# role. The dict keys hold the relative file paths, and the dict values the |
104 | | -# corresponding version numbers and/or file information. |
105 | | -FILEINFODICT_SCHEMA = SCHEMA.DictOf( |
106 | | - key_schema = securesystemslib.formats.RELPATH_SCHEMA, |
107 | | - value_schema = SCHEMA.OneOf([VERSIONINFO_SCHEMA, |
108 | | - securesystemslib.formats.FILEINFO_SCHEMA])) |
109 | | - |
110 | 106 | # A string representing a role's name. |
111 | 107 | ROLENAME_SCHEMA = SCHEMA.AnyString() |
112 | 108 |
|
| 109 | +# A role's threshold value (i.e., the minimum number |
| 110 | +# of signatures required to sign a metadata file). |
| 111 | +# Must be 1 and greater. |
| 112 | +THRESHOLD_SCHEMA = SCHEMA.Integer(lo=1) |
| 113 | + |
| 114 | +# A hexadecimal value in '23432df87ab..' format. |
| 115 | +HEX_SCHEMA = SCHEMA.RegularExpression(r'[a-fA-F0-9]+') |
| 116 | + |
| 117 | +# A path hash prefix is a hexadecimal string. |
| 118 | +PATH_HASH_PREFIX_SCHEMA = HEX_SCHEMA |
| 119 | + |
| 120 | +# A list of path hash prefixes. |
| 121 | +PATH_HASH_PREFIXES_SCHEMA = SCHEMA.ListOf(PATH_HASH_PREFIX_SCHEMA) |
| 122 | + |
113 | 123 | # Role object in {'keyids': [keydids..], 'name': 'ABC', 'threshold': 1, |
114 | 124 | # 'paths':[filepaths..]} format. |
115 | 125 | # TODO: This is not a role. In further #660-related PRs, fix it, similar to |
116 | 126 | # the way I did in Uptane's TUF fork. |
117 | 127 | ROLE_SCHEMA = SCHEMA.Object( |
118 | 128 | object_name = 'ROLE_SCHEMA', |
119 | | - name = SCHEMA.Optional(securesystemslib.formats.ROLENAME_SCHEMA), |
| 129 | + name = SCHEMA.Optional(ROLENAME_SCHEMA), |
120 | 130 | keyids = securesystemslib.formats.KEYIDS_SCHEMA, |
121 | | - threshold = securesystemslib.formats.THRESHOLD_SCHEMA, |
| 131 | + threshold = THRESHOLD_SCHEMA, |
122 | 132 | terminating = SCHEMA.Optional(securesystemslib.formats.BOOLEAN_SCHEMA), |
123 | | - paths = SCHEMA.Optional(securesystemslib.formats.RELPATHS_SCHEMA), |
124 | | - path_hash_prefixes = SCHEMA.Optional(securesystemslib.formats.PATH_HASH_PREFIXES_SCHEMA)) |
| 133 | + paths = SCHEMA.Optional(RELPATHS_SCHEMA), |
| 134 | + path_hash_prefixes = SCHEMA.Optional(PATH_HASH_PREFIXES_SCHEMA)) |
125 | 135 |
|
126 | 136 | # A dict of roles where the dict keys are role names and the dict values holding |
127 | 137 | # the role data/information. |
|
156 | 166 | # A string representing a role's name. |
157 | 167 | ROLENAME_SCHEMA = SCHEMA.AnyString() |
158 | 168 |
|
159 | | -# A role's threshold value (i.e., the minimum number |
160 | | -# of signatures required to sign a metadata file). |
161 | | -# Must be 1 and greater. |
162 | | -THRESHOLD_SCHEMA = SCHEMA.Integer(lo=1) |
163 | | - |
164 | 169 | # A hexadecimal value in '23432df87ab..' format. |
165 | 170 | HASH_SCHEMA = SCHEMA.RegularExpression(r'[a-fA-F0-9]+') |
166 | 171 |
|
167 | | -# A hexadecimal value in '23432df87ab..' format. |
168 | | -HEX_SCHEMA = SCHEMA.RegularExpression(r'[a-fA-F0-9]+') |
169 | | - |
170 | 172 | # A key identifier (e.g., a hexadecimal value identifying an RSA key). |
171 | 173 | KEYID_SCHEMA = HASH_SCHEMA |
172 | 174 |
|
|
214 | 216 | unknown_sigs = KEYIDS_SCHEMA, |
215 | 217 | untrusted_sigs = KEYIDS_SCHEMA) |
216 | 218 |
|
217 | | - |
218 | | -# A relative file path (e.g., 'metadata/root/'). |
219 | | -RELPATH_SCHEMA = SCHEMA.AnyString() |
220 | | -RELPATHS_SCHEMA = SCHEMA.ListOf(RELPATH_SCHEMA) |
221 | | - |
222 | | -# A path hash prefix is a hexadecimal string. |
223 | | -PATH_HASH_PREFIX_SCHEMA = HEX_SCHEMA |
224 | | - |
225 | | -# A list of path hash prefixes. |
226 | | -PATH_HASH_PREFIXES_SCHEMA = SCHEMA.ListOf(PATH_HASH_PREFIX_SCHEMA) |
227 | | - |
228 | 219 | # Role object in {'keyids': [keydids..], 'name': 'ABC', 'threshold': 1, |
229 | 220 | # 'paths':[filepaths..]} format. |
230 | 221 | ROLE_SCHEMA = SCHEMA.Object( |
|
260 | 251 | version = SCHEMA.Optional(METADATAVERSION_SCHEMA), |
261 | 252 | custom = SCHEMA.Optional(SCHEMA.Object())) |
262 | 253 |
|
| 254 | +# A dict holding the version or file information for a particular metadata |
| 255 | +# role. The dict keys hold the relative file paths, and the dict values the |
| 256 | +# corresponding version numbers and/or file information. |
| 257 | +FILEINFODICT_SCHEMA = SCHEMA.DictOf( |
| 258 | + key_schema = RELPATH_SCHEMA, |
| 259 | + value_schema = SCHEMA.OneOf([VERSIONINFO_SCHEMA, |
| 260 | + FILEINFO_SCHEMA])) |
| 261 | + |
263 | 262 | # A dict holding the information for a particular target / file. The dict keys |
264 | 263 | # hold the relative file paths, and the dict values the corresponding file |
265 | 264 | # information. |
|
369 | 368 | SNAPSHOT_SCHEMA = SCHEMA.Object( |
370 | 369 | object_name = 'SNAPSHOT_SCHEMA', |
371 | 370 | _type = SCHEMA.String('snapshot'), |
372 | | - version = securesystemslib.formats.METADATAVERSION_SCHEMA, |
| 371 | + version = METADATAVERSION_SCHEMA, |
373 | 372 | expires = securesystemslib.formats.ISO8601_DATETIME_SCHEMA, |
374 | 373 | spec_version = SPECIFICATION_VERSION_SCHEMA, |
375 | 374 | meta = FILEINFODICT_SCHEMA) |
|
379 | 378 | object_name = 'TIMESTAMP_SCHEMA', |
380 | 379 | _type = SCHEMA.String('timestamp'), |
381 | 380 | spec_version = SPECIFICATION_VERSION_SCHEMA, |
382 | | - version = securesystemslib.formats.METADATAVERSION_SCHEMA, |
| 381 | + version = METADATAVERSION_SCHEMA, |
383 | 382 | expires = securesystemslib.formats.ISO8601_DATETIME_SCHEMA, |
384 | | - meta = securesystemslib.formats.FILEDICT_SCHEMA) |
| 383 | + meta = FILEDICT_SCHEMA) |
385 | 384 |
|
386 | 385 |
|
387 | 386 | # project.cfg file: stores information about the project in a json dictionary |
|
401 | 400 | MIRROR_SCHEMA = SCHEMA.Object( |
402 | 401 | object_name = 'MIRROR_SCHEMA', |
403 | 402 | url_prefix = securesystemslib.formats.URL_SCHEMA, |
404 | | - metadata_path = securesystemslib.formats.RELPATH_SCHEMA, |
405 | | - targets_path = securesystemslib.formats.RELPATH_SCHEMA, |
406 | | - confined_target_dirs = securesystemslib.formats.RELPATHS_SCHEMA, |
| 403 | + metadata_path = RELPATH_SCHEMA, |
| 404 | + targets_path = RELPATH_SCHEMA, |
| 405 | + confined_target_dirs = RELPATHS_SCHEMA, |
407 | 406 | custom = SCHEMA.Optional(SCHEMA.Object())) |
408 | 407 |
|
409 | 408 | # A dictionary of mirrors where the dict keys hold the mirror's name and |
@@ -807,7 +806,7 @@ def make_fileinfo(length, hashes, version=None, custom=None): |
807 | 806 | fileinfo['custom'] = custom |
808 | 807 |
|
809 | 808 | # Raise 'securesystemslib.exceptions.FormatError' if the check fails. |
810 | | - securesystemslib.formats.FILEINFO_SCHEMA.check_match(fileinfo) |
| 809 | + FILEINFO_SCHEMA.check_match(fileinfo) |
811 | 810 |
|
812 | 811 | return fileinfo |
813 | 812 |
|
|
0 commit comments