46
46
SignedSerializer ,
47
47
)
48
48
49
- # Disable the "C0302: Too many lines in module" warning which warns for modules
50
- # with more 1000 lines, because all of the code here is logically connected
51
- # and currently, we are above 1000 lines by a small margin.
52
- # pylint: disable=C0302
49
+ # pylint: disable=too-many-lines
53
50
54
51
# We aim to support SPECIFICATION_VERSION and require the input metadata
55
52
# files to have the same major version (the first number) as ours.
@@ -65,7 +62,6 @@ class Metadata:
65
62
Attributes:
66
63
signed: A subclass of Signed, which has the actual metadata payload,
67
64
i.e. one of Targets, Snapshot, Timestamp or Root.
68
-
69
65
signatures: An ordered dictionary of keyids to Signature objects, each
70
66
signing the canonical serialized representation of 'signed'.
71
67
"""
@@ -92,8 +88,8 @@ def from_dict(cls, metadata: Dict[str, Any]) -> "Metadata":
92
88
93
89
Returns:
94
90
A TUF Metadata object.
95
-
96
91
"""
92
+
97
93
# Dispatch to contained metadata class on metadata _type field.
98
94
_type = metadata ["signed" ]["_type" ]
99
95
@@ -148,8 +144,8 @@ def from_file(
148
144
149
145
Returns:
150
146
A TUF Metadata object.
151
-
152
147
"""
148
+
153
149
if storage_backend is None :
154
150
storage_backend = FilesystemBackend ()
155
151
@@ -202,20 +198,18 @@ def to_file(
202
198
203
199
Arguments:
204
200
filename: The path to write the file to.
205
- serializer: A MetadataSerializer subclass instance that implements
206
- the desired wireline format serialization. Per default a
207
- JSONSerializer is used.
208
- storage_backend: An object that implements
209
- securesystemslib.storage.StorageBackendInterface. Per default
210
- a (local) FilesystemBackend is used.
201
+ serializer: A MetadataSerializer instance that implements the
202
+ desired serialization format. Default is JSONSerializer.
203
+ storage_backend: A StorageBackendInterface implementation. Default
204
+ is FilesystemBackend (i.e. a local file).
211
205
212
206
Raises:
213
207
tuf.api.serialization.SerializationError:
214
208
The metadata object cannot be serialized.
215
209
securesystemslib.exceptions.StorageError:
216
210
The file cannot be written.
217
-
218
211
"""
212
+
219
213
if serializer is None :
220
214
# Use local scope import to avoid circular import errors
221
215
# pylint: disable=import-outside-toplevel
@@ -237,14 +231,12 @@ def sign(
237
231
"""Creates signature over 'signed' and assigns it to 'signatures'.
238
232
239
233
Arguments:
240
- signer: An object implementing the securesystemslib.signer.Signer
241
- interface.
234
+ signer: A securesystemslib.signer.Signer implementation.
242
235
append: A boolean indicating if the signature should be appended to
243
236
the list of signatures or replace any existing signatures. The
244
237
default behavior is to replace signatures.
245
- signed_serializer: A SignedSerializer subclass instance that
246
- implements the desired canonicalization format. Per default a
247
- CanonicalJSONSerializer is used.
238
+ signed_serializer: A SignedSerializer that implements the desired
239
+ serialization format. Default is CanonicalJSONSerializer.
248
240
249
241
Raises:
250
242
tuf.api.serialization.SerializationError:
@@ -255,8 +247,8 @@ def sign(
255
247
256
248
Returns:
257
249
A securesystemslib-style signature object.
258
-
259
250
"""
251
+
260
252
if signed_serializer is None :
261
253
# Use local scope import to avoid circular import errors
262
254
# pylint: disable=import-outside-toplevel
@@ -407,8 +399,9 @@ def bump_version(self) -> None:
407
399
408
400
class Key :
409
401
"""A container class representing the public portion of a Key.
402
+
410
403
Please note that "Key" instances are not semanticly validated during
411
- initialization. We consider this as responsibility of securesystemslib .
404
+ initialization: this only happens at signature verification time .
412
405
413
406
Attributes:
414
407
keyid: An identifier string that must uniquely identify a key within
@@ -420,7 +413,6 @@ class Key:
420
413
"rsassa-pss-sha256", "ed25519", and "ecdsa-sha2-nistp256".
421
414
keyval: A dictionary containing the public portion of the key.
422
415
unrecognized_fields: Dictionary of all unrecognized fields.
423
-
424
416
"""
425
417
426
418
def __init__ (
@@ -512,15 +504,15 @@ def verify_signature(
512
504
513
505
514
506
class Role :
515
- """A container class containing the set of keyids and threshold associated
516
- with a particular role.
507
+ """Container that defines which keys are required to sign roles metadata.
508
+
509
+ Role defines how many keys are required to successfully sign the roles
510
+ metadata, and which keys are accepted.
517
511
518
512
Attributes:
519
- keyids: A set of strings each of which represents a given key.
520
- threshold: An integer representing the required number of keys for that
521
- particular role.
513
+ keyids: A set of strings representing signing keys for this role.
514
+ threshold: Number of keys required to sign this role's metadata.
522
515
unrecognized_fields: Dictionary of all unrecognized fields.
523
-
524
516
"""
525
517
526
518
def __init__ (
@@ -564,29 +556,14 @@ class Root(Signed):
564
556
Attributes:
565
557
consistent_snapshot: An optional boolean indicating whether the
566
558
repository supports consistent snapshots.
567
- keys: A dictionary that contains a public key store used to verify
568
- top level roles metadata signatures::
569
-
570
- {
571
- '<KEYID>': <Key instance>,
572
- ...
573
- },
574
-
575
- roles: A dictionary that contains a list of signing keyids and
576
- a signature threshold for each top level role::
577
-
578
- {
579
- '<ROLE>': <Role istance>,
580
- ...
581
- }
582
-
559
+ keys: Dictionary of keyids to Keys. Defines the keys used in 'roles'.
560
+ roles: Dictionary of role names to Roles. Defines which keys are
561
+ required to sign the metadata for a specific role.
583
562
"""
584
563
585
564
_signed_type = "root"
586
565
587
- # TODO: determine an appropriate value for max-args and fix places where
588
- # we violate that. This __init__ function takes 7 arguments, whereas the
589
- # default max-args value for pylint is 5
566
+ # TODO: determine an appropriate value for max-args
590
567
# pylint: disable=too-many-arguments
591
568
def __init__ (
592
569
self ,
@@ -709,18 +686,8 @@ class MetaFile(BaseFile):
709
686
Attributes:
710
687
version: An integer indicating the version of the metadata file.
711
688
length: An optional integer indicating the length of the metadata file.
712
- hashes: An optional dictionary mapping hash algorithms to the
713
- hashes resulting from applying them over the metadata file
714
- contents.::
715
-
716
- 'hashes': {
717
- '<HASH ALGO 1>': '<METADATA FILE HASH 1>',
718
- '<HASH ALGO 2>': '<METADATA FILE HASH 2>',
719
- ...
720
- }
721
-
689
+ hashes: An optional dictionary of hash algorithm names to hash values.
722
690
unrecognized_fields: Dictionary of all unrecognized fields.
723
-
724
691
"""
725
692
726
693
def __init__ (
@@ -767,10 +734,11 @@ def to_dict(self) -> Dict[str, Any]:
767
734
return res_dict
768
735
769
736
def verify_length_and_hashes (self , data : Union [bytes , BinaryIO ]):
770
- """Verifies that the length and hashes of "data" match expected
771
- values.
737
+ """Verifies that the length and hashes of "data" match expected values.
738
+
772
739
Args:
773
740
data: File object or its content in bytes.
741
+
774
742
Raises:
775
743
LengthOrHashMismatchError: Calculated length or hashes do not
776
744
match expected values.
@@ -786,13 +754,11 @@ def verify_length_and_hashes(self, data: Union[bytes, BinaryIO]):
786
754
class Timestamp (Signed ):
787
755
"""A container for the signed part of timestamp metadata.
788
756
789
- Attributes:
790
- meta: A dictionary that contains information about snapshot metadata::
791
-
792
- {
793
- 'snapshot.json': <MetaFile INSTANCE>
794
- }
757
+ Timestamp contains information about the snapshot Metadata file.
795
758
759
+ Attributes:
760
+ meta: A dictionary of filenames to MetaFiles. The only valid key value
761
+ is the snapshot filename, as defined by the specification.
796
762
"""
797
763
798
764
_signed_type = "timestamp"
@@ -834,15 +800,10 @@ def update(self, snapshot_meta: MetaFile) -> None:
834
800
class Snapshot (Signed ):
835
801
"""A container for the signed part of snapshot metadata.
836
802
837
- Attributes:
838
- meta: A dictionary that contains information about targets metadata::
839
-
840
- {
841
- 'targets.json': <MetaFile INSTANCE>,
842
- '<DELEGATED TARGETS ROLE 1>.json': <MetaFile INSTANCE>,
843
- '<DELEGATED TARGETS ROLE 2>.json': <MetaFile INSTANCE>,
844
- }
803
+ Snapshot contains information about all target Metadata files.
845
804
805
+ Attributes:
806
+ meta: A dictionary of target metadata filenames to MetaFile objects.
846
807
"""
847
808
848
809
_signed_type = "snapshot"
@@ -891,18 +852,14 @@ class DelegatedRole(Role):
891
852
892
853
Attributes:
893
854
name: A string giving the name of the delegated role.
894
- keyids: A set of strings each of which represents a given key.
895
- threshold: An integer representing the required number of keys for that
896
- particular role.
897
855
terminating: A boolean indicating whether subsequent delegations
898
- should be considered.
856
+ should be considered during a target lookup .
899
857
paths: An optional list of strings, where each string describes
900
- a path that the role is trusted to provide.
858
+ a path pattern that the role is trusted to provide.
901
859
path_hash_prefixes: An optional list of HEX_DIGESTs used to succinctly
902
860
describe a set of target paths. Only one of the attributes "paths"
903
- and "path_hash_prefixes" is allowed to be set .
861
+ and "path_hash_prefixes" is allowed within a DelegatedRole .
904
862
unrecognized_fields: Dictionary of all unrecognized fields.
905
-
906
863
"""
907
864
908
865
def __init__ (
@@ -965,12 +922,11 @@ class Delegations:
965
922
"""A container object storing information about all delegations.
966
923
967
924
Attributes:
968
- keys: A dictionary of keyids and key objects containing information
969
- about the corresponding key.
970
- roles: A list of DelegatedRole instances containing information about
971
- all delegated roles .
925
+ keys: Dictionary of keyids to Keys. Defines the keys used in 'roles'.
926
+ roles: List of DelegatedRoles that define which keys are required to
927
+ sign the metadata for a specific role. The roles order also
928
+ defines the order that role delegations are considered in .
972
929
unrecognized_fields: Dictionary of all unrecognized fields.
973
-
974
930
"""
975
931
976
932
def __init__ (
@@ -1014,17 +970,8 @@ class TargetFile(BaseFile):
1014
970
1015
971
Attributes:
1016
972
length: An integer indicating the length of the target file.
1017
- hashes: A dictionary mapping hash algorithms to the
1018
- hashes resulting from applying them over the metadata file
1019
- contents::
1020
-
1021
- 'hashes': {
1022
- '<HASH ALGO 1>': '<TARGET FILE HASH 1>',
1023
- '<HASH ALGO 2>': '<TARGET FILE HASH 2>',
1024
- ...
1025
- }
973
+ hashes: A dictionary of hash algorithm names to hash values.
1026
974
unrecognized_fields: Dictionary of all unrecognized fields.
1027
-
1028
975
"""
1029
976
1030
977
def __init__ (
@@ -1067,10 +1014,11 @@ def to_dict(self) -> Dict[str, Any]:
1067
1014
}
1068
1015
1069
1016
def verify_length_and_hashes (self , data : Union [bytes , BinaryIO ]):
1070
- """Verifies that the length and hashes of "data" match expected
1071
- values.
1017
+ """Verifies that length and hashes of "data" match expected values.
1018
+
1072
1019
Args:
1073
1020
data: File object or its content in bytes.
1021
+
1074
1022
Raises:
1075
1023
LengthOrHashMismatchError: Calculated length or hashes do not
1076
1024
match expected values.
@@ -1082,25 +1030,18 @@ def verify_length_and_hashes(self, data: Union[bytes, BinaryIO]):
1082
1030
class Targets (Signed ):
1083
1031
"""A container for the signed part of targets metadata.
1084
1032
1085
- Attributes:
1086
- targets: A dictionary that contains information about target files::
1087
-
1088
- {
1089
- '<TARGET FILE NAME>': <TargetFile INSTANCE>,
1090
- ...
1091
- }
1092
-
1093
- delegations: An optional object containing a list of delegated target
1094
- roles and public key store used to verify their metadata
1095
- signatures.
1033
+ Targets contains verifying information about target files and also
1034
+ delegates responsibility to other Targets roles.
1096
1035
1036
+ Attributes:
1037
+ targets: A dictionary of target filenames to TargetFiles
1038
+ delegations: An optional Delegations that defines how this Targets
1039
+ further delegates responsibility to other Targets Metadata files.
1097
1040
"""
1098
1041
1099
1042
_signed_type = "targets"
1100
1043
1101
- # TODO: determine an appropriate value for max-args and fix places where
1102
- # we violate that. This __init__ function takes 7 arguments, whereas the
1103
- # default max-args value for pylint is 5
1044
+ # TODO: determine an appropriate value for max-args
1104
1045
# pylint: disable=too-many-arguments
1105
1046
def __init__ (
1106
1047
self ,
0 commit comments