Repository navigation
Serialization and Metadata API changes - #12
Conversation
BaseDeserializer requires a class type to deserialize the raw_data into a class. This creates a problem with Paylaod Deserialization, where we have to deserialize the same payload multiple time. BaseDeserializer, JSONDeserializer returns json and that get converted into the class object after that. Payload Deserialization will be app specific and will be implemented at project level. Signed-off-by: Pradyumna Krishna <git@onpy.in>
sign is renamed to create_sig and verify is renamed to verify_sigs, so it does not clashes with other methods of current signature wrappers. This has to be done to avoid any breaking change while integrating DSSE in in-toto and tuf projects. Signed-off-by: Pradyumna Krishna <git@onpy.in>
Tests was failing due to changes in serialization and metadata module. Some methods of DSSE Envelope was renamed which was failing the test cases. Signed-off-by: Pradyumna Krishna <git@onpy.in>
| ) -> "Envelope": | ||
|
|
||
| json = super().from_bytes(data, deserializer) | ||
| return cls.from_dict(json) |
There was a problem hiding this comment.
I think you are mixing concerns here. Shouldn't we expect the deserializer passed to from_bytes to return an Envelope? IMO it's better and more flexible to move the logic here to a custom:
class EnvelopeJSONDeserializer: # could also inherit from `JsonDeserializer` and call `super()` below
def deserialize(data):
return Envelope.from_dict(
JsonDeserializer().deserialize(data)
)Then you can return that from default_deserializer() and it will provide you with the from_bytes() you want without the need to override the one inherited from SerializationMixin
Note that in-toto won't use this EnvelopeJSONDeserializer because there we want something like an AnyMetadataJSONDeserializer, which can return either an Envelope or Metablock as described in ITE-5.
So for the purpose of ITE-5, you don't even have to create a EnvelopeJSONDeserializer. But I think it's okay to provide one in securesystemslib as blueprint for custom deserializers.
What do you think?
| @abc.abstractmethod | ||
| def deserialize(self, raw_data: bytes, cls: Any) -> Any: | ||
| def deserialize(self, raw_data: bytes) -> Any: | ||
| """Deserialize bytes to a specific object.""" |
There was a problem hiding this comment.
| """Deserialize bytes to a specific object.""" | |
| """Deserialize bytes.""" |
|
|
||
| def deserialize(self, raw_data: bytes, cls: "JSONSerializable") -> Any: | ||
| """Deserialize utf-8 encoded JSON bytes into an instance of cls. | ||
| def deserialize(self, raw_data: bytes) -> Any: |
There was a problem hiding this comment.
| def deserialize(self, raw_data: bytes) -> Any: | |
| def deserialize(self, raw_data: bytes) -> Dict: |
needs to be imported from typing
| cls: A "JSONSerializable" subclass. | ||
|
|
||
| Returns: | ||
| Object of the provided class type. |
There was a problem hiding this comment.
| Object of the provided class type. | |
| dict |
Maybe the Returns section of the docstring can be omitted, given the type hint and oneliner on top.
| deserialization. | ||
| to dict. It provides `to_dict` method, therefore, JSONSerializer requires | ||
| a subclass of this class for serialization. | ||
| """ |
There was a problem hiding this comment.
Could be shortened to something like...
"""Objects serialized with ``JSONSerializer`` must inherit from this class and
implement its ``to_dict`` method.
"""EnvelopeJSONDeserializer is a subclass of JSONDeserializer which deserializes raw data into an object of Envelope class. This deserializer is exclusive for DSSE Envelope. To avoid circular imports EnvelopeJSONDeserializer is created in metadata.py. Signed-off-by: Pradyumna Krishna <git@onpy.in>
| to dict. It provides `to_dict` method, therefore, JSONSerializer requires | ||
| a subclass of this class for serialization. | ||
| """Objects serialized with ``JSONSerializer`` must inherit from this class | ||
| and implement its ``to_dict`` method.. |
There was a problem hiding this comment.
Nit pick:
| and implement its ``to_dict`` method.. | |
| and implement its ``to_dict`` method. |
Signed-off-by: Pradyumna Krishna <git@onpy.in>
Description of the changes being introduced by the pull request:
BaseDeserializer requires a class type to deserialize the raw_data
into a class. This creates a problem with Paylaod Deserialization,
where we have to deserialize the same payload multiple time.
BaseDeserializer, JSONDeserializer returns json and that get
converted into the class object after that. Payload Deserialization
will be app specific and will be implemented at project level.
sign is renamed to create_sig and verify is renamed to verify_sigs,
so it does not clashes with other methods of current signature
wrappers.
Please verify and check that the pull request fulfils the following requirements: