Skip to content

Commit

Permalink
Remove serialization module
Browse files Browse the repository at this point in the history
Serialization api is removed from securesystemslib with this
commit because of its complexity and don't having a use case
for a standalone securesystemslib Envelope.

This commit removes `_default_deserializer`, `_default_serializer`
and `get_payload` methods of Envelope with securesystemslib but
keeps `from_dict` and `to_dict` methods to be consistent with
other metadata related classes, e.g. signer.

Signed-off-by: Pradyumna Krishna <[email protected]>
  • Loading branch information
PradyumnaKrishna committed Feb 17, 2023
1 parent 99f13cf commit 1ecb06b
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 468 deletions.
60 changes: 1 addition & 59 deletions securesystemslib/dsse.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,13 @@
from typing import Any, Dict, List

from securesystemslib import exceptions
from securesystemslib.serialization import (
BaseDeserializer,
BaseSerializer,
JSONDeserializer,
JSONSerializable,
JSONSerializer,
SerializationMixin,
)
from securesystemslib._internal.utils import b64enc, b64dec
from securesystemslib.signer import Key, Signature, Signer

logger = logging.getLogger(__name__)


class EnvelopeJSONDeserializer(JSONDeserializer):
"""Deserializes raw bytes and creates an Envelope object using JSON
Deserialization."""

def deserialize(self, raw_data: bytes) -> "Envelope":
"""Deserialize utf-8 encoded JSON bytes into an instance of Envelope.
Arguments:
raw_data: A utf-8 encoded bytes string.
Raises:
DeserializationError: If fails to deserialize raw_data.
Returns:
dict.
"""
try:
return Envelope.from_dict(super().deserialize(raw_data))
except Exception as e:
raise exceptions.DeserializationError(
"Failed to create Envelope"
) from e


class Envelope(SerializationMixin, JSONSerializable):
class Envelope:
"""DSSE Envelope to provide interface for signing arbitrary data.
Attributes:
Expand All @@ -70,14 +38,6 @@ def __eq__(self, other: Any) -> bool:
and self.signatures == other.signatures
)

@staticmethod
def _default_deserializer() -> BaseDeserializer:
return EnvelopeJSONDeserializer()

@staticmethod
def _default_serializer() -> BaseSerializer:
return JSONSerializer()

@classmethod
def from_dict(cls, data: dict) -> "Envelope":
"""Creates a DSSE Envelope from its JSON/dict representation.
Expand Down Expand Up @@ -197,21 +157,3 @@ def verify(self, keys: List[Key], threshold: int) -> Dict[str, Key]:
)

return accepted_keys

def get_payload(
self,
deserializer: BaseDeserializer,
) -> Any:
"""Parse DSSE payload.
Arguments:
deserializer: ``BaseDeserializer`` implementation to use.
Raises:
DeserializationError: The payload cannot be deserialized.
Returns:
The deserialized object of payload.
"""

return deserializer.deserialize(self.payload)
249 changes: 0 additions & 249 deletions securesystemslib/serialization.py

This file was deleted.

Loading

0 comments on commit 1ecb06b

Please sign in to comment.