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
| Attribute | Type | Description |
|---|---|---|
| _key | key object | Private key used to sign serialized data to ensure authenticity. |
| _cert | certificate object | Certificate used to identify the signer when packing serialized data. |
| _cert_store | dict | Mapping of signer identifiers to certificates used to verify signatures during deserialization. |
| _digest | digest algorithm | The hashing algorithm used for generating and verifying message signatures. |
| _serializer | string = json | The 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
| Name | Type | Description |
|---|---|---|
| key | any = None | The private key used for signing data. |
| cert | any = None | The certificate associated with the signer. |
| cert_store | any = None | A store or dictionary of certificates used for verification. |
| digest | string = DEFAULT_SECURITY_DIGEST | The digest algorithm to use for signatures. |
| serializer | string = 'json' | The serialization format to use (e.g., 'json'). |
Methods
serialize()
@classmethod
def serialize(
data: Any
) - > bytes
Serialize data structure into string.
Parameters
| Name | Type | Description |
|---|---|---|
| data | Any | The Python data structure to be serialized and cryptographically signed |
Returns
| Type | Description |
|---|---|
bytes | A 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
| Name | Type | Description |
|---|---|---|
| data | bytes | The signed and encoded payload string to be verified and unpacked |
Returns
| Type | Description |
|---|---|
Any | The original Python data structure reconstructed from the verified and decoded payload |