Skip to main content

SecureSerializer

This class provides a signed serializer for securely encoding and decoding data structures. It ensures data integrity by signing the serialized body with a private key and verifying it using a certificate store during deserialization. The class supports configurable digest algorithms and underlying serialization formats like JSON.

Attributes

AttributeTypeDescription
_keykey objectPrivate key used to sign serialized data to ensure authenticity.
_certcertificate objectCertificate used to identify the signer when packing serialized data.
_cert_storedictMapping of signer identifiers to certificates used to verify signatures during deserialization.
_digestdigest algorithmThe hashing algorithm used for generating and verifying message signatures.
_serializerstring = jsonThe name of the serialization format used to encode the data body before signing.

Constructor

Signature

def SecureSerializer(
key: any = None,
cert: any = None,
cert_store: any = None,
digest: string = DEFAULT_SECURITY_DIGEST,
serializer: string = 'json'
)

Parameters

NameTypeDescription
keyany = NoneThe private key used for signing data.
certany = NoneThe certificate associated with the signer.
cert_storeany = NoneA store or dictionary of certificates used for verification.
digeststring = DEFAULT_SECURITY_DIGESTThe digest algorithm to use for signatures.
serializerstring = 'json'The serialization format to use (e.g., 'json').

Methods


serialize()

@classmethod
def serialize(
data: Any
) - > bytes

Serialize data structure into string.

Parameters

NameTypeDescription
dataAnyThe Python data structure to be serialized and cryptographically signed

Returns

TypeDescription
bytesA base64-encoded string containing the signed message, including the signature, signer ID, and content metadata

deserialize()

@classmethod
def deserialize(
data: bytes
) - > Any

Deserialize data structure from string.

Parameters

NameTypeDescription
databytesThe signed and encoded payload string to be verified and unpacked

Returns

TypeDescription
AnyThe original Python data structure reconstructed from the verified and decoded payload