mirror of
https://github.com/theupdateframework/python-tuf
synced 2026-05-24 10:08:28 +00:00
Rename a few variables in tuf.api
- Rename _dict to json_dict to avoid wrong semantics of leading underscore. (leading underscore was initially chosen to avoid name shadowing) - Rename 'serializer' argument of type 'SignedSerializer' to 'signed_serializer', to distinguish from 'serializer' argument of type 'MetadataSerializer'. Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
This commit is contained in:
parent
aa8225cb07
commit
d823c8fc01
2 changed files with 15 additions and 14 deletions
|
|
@ -186,7 +186,7 @@ def to_file(
|
|||
|
||||
# Signatures.
|
||||
def sign(self, key: JsonDict, append: bool = False,
|
||||
serializer: Optional[SignedSerializer] = None) -> JsonDict:
|
||||
signed_serializer: Optional[SignedSerializer] = None) -> JsonDict:
|
||||
"""Creates signature over 'signed' and assigns it to 'signatures'.
|
||||
|
||||
Arguments:
|
||||
|
|
@ -194,8 +194,8 @@ def sign(self, key: JsonDict, append: bool = False,
|
|||
append: A boolean indicating if the signature should be appended to
|
||||
the list of signatures or replace any existing signatures. The
|
||||
default behavior is to replace signatures.
|
||||
serializer: A SignedSerializer subclass instance that implements
|
||||
the desired canonicalization format. Per default a
|
||||
signed_serializer: A SignedSerializer subclass instance that
|
||||
implements the desired canonicalization format. Per default a
|
||||
CanonicalJSONSerializer is used.
|
||||
|
||||
Raises:
|
||||
|
|
@ -209,13 +209,14 @@ def sign(self, key: JsonDict, append: bool = False,
|
|||
A securesystemslib-style signature object.
|
||||
|
||||
"""
|
||||
if serializer is None:
|
||||
if signed_serializer is None:
|
||||
# Use local scope import to avoid circular import errors
|
||||
# pylint: disable=import-outside-toplevel
|
||||
from tuf.api.serialization.json import CanonicalJSONSerializer
|
||||
serializer = CanonicalJSONSerializer()
|
||||
signed_serializer = CanonicalJSONSerializer()
|
||||
|
||||
signature = create_signature(key, serializer.serialize(self.signed))
|
||||
signature = create_signature(key,
|
||||
signed_serializer.serialize(self.signed))
|
||||
|
||||
if append:
|
||||
self.signatures.append(signature)
|
||||
|
|
@ -226,13 +227,13 @@ def sign(self, key: JsonDict, append: bool = False,
|
|||
|
||||
|
||||
def verify(self, key: JsonDict,
|
||||
serializer: Optional[SignedSerializer] = None) -> bool:
|
||||
signed_serializer: Optional[SignedSerializer] = None) -> bool:
|
||||
"""Verifies 'signatures' over 'signed' that match the passed key by id.
|
||||
|
||||
Arguments:
|
||||
key: A securesystemslib-style public key object.
|
||||
serializer: A SignedSerializer subclass instance that implements
|
||||
the desired canonicalization format. Per default a
|
||||
signed_serializer: A SignedSerializer subclass instance that
|
||||
implements the desired canonicalization format. Per default a
|
||||
CanonicalJSONSerializer is used.
|
||||
|
||||
Raises:
|
||||
|
|
@ -261,15 +262,15 @@ def verify(self, key: JsonDict,
|
|||
f'{len(signatures_for_keyid)} signatures for key '
|
||||
f'{key["keyid"]}, not sure which one to verify.')
|
||||
|
||||
if serializer is None:
|
||||
if signed_serializer is None:
|
||||
# Use local scope import to avoid circular import errors
|
||||
# pylint: disable=import-outside-toplevel
|
||||
from tuf.api.serialization.json import CanonicalJSONSerializer
|
||||
serializer = CanonicalJSONSerializer()
|
||||
signed_serializer = CanonicalJSONSerializer()
|
||||
|
||||
return verify_signature(
|
||||
key, signatures_for_keyid[0],
|
||||
serializer.serialize(self.signed))
|
||||
signed_serializer.serialize(self.signed))
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -32,8 +32,8 @@ class JSONDeserializer(MetadataDeserializer):
|
|||
def deserialize(self, raw_data: bytes) -> Metadata:
|
||||
"""Deserialize utf-8 encoded JSON bytes into Metadata object. """
|
||||
try:
|
||||
_dict = json.loads(raw_data.decode("utf-8"))
|
||||
return Metadata.from_dict(_dict)
|
||||
json_dict = json.loads(raw_data.decode("utf-8"))
|
||||
return Metadata.from_dict(json_dict)
|
||||
|
||||
except Exception as e: # pylint: disable=broad-except
|
||||
six.raise_from(DeserializationError, e)
|
||||
|
|
|
|||
Loading…
Reference in a new issue