module documentation

Serializer abstraction module

This module introduces a simple abstraction over the serialization backend (currently json).

Class BinaryEncoder Undocumented
Class EncodeWithoutPrivateFields Undocumented
Class EncodeWithPrivateFields Undocumented
Class Private Wrap a value so it is hard to leak it accidentally.
Class PrivateDict A dictionary that turns its values to private fields.
Function DumpJson Serialize a given object.
Function DumpSignedJson Serialize a given object and authenticate it.
Function LoadAndVerifyJson Parses and verifies JSON data.
Function LoadJson Unserialize data from bytes.
Function LoadSignedJson Verify that a given message was signed with the given key, and load it.
Function WrapPrivateValues Crawl a JSON decoded structure for private values and wrap them.
Constant _RE_EOLSP Undocumented
def DumpJson(data, private_encoder=None):

Serialize a given object.

Parameters
datathe data to serialize
private_encoderspecify serializer.EncodeWithPrivateFields if you require the produced JSON to also contain private parameters. Otherwise, they will encode to null.
Returns
the bytes representation of data
def DumpSignedJson(data, key, salt=None, key_selector=None, private_encoder=None):

Serialize a given object and authenticate it.

Parameters
datathe data to serialize
keyshared hmac key
saltUndocumented
key_selectorname/id that identifies the key (in case there are multiple keys in use, e.g. in a multi-cluster environment)
private_encodersee DumpJson
Returns
the string representation of data signed by the hmac key
def LoadAndVerifyJson(raw, verify_fn):

Parses and verifies JSON data.

Parameters
raw:stringInput data in JSON format
verify_fn:callableVerification function, usually from ht
Returns
De-serialized data
def LoadJson(data):

Unserialize data from bytes.

Parameters
data:str or bytesthe json-encoded form
Returns
the original data
Raises
JSONDecodeErrorif txt is not a valid JSON document
def LoadSignedJson(txt, key):

Verify that a given message was signed with the given key, and load it.

Parameters
txtjson-encoded hmac-signed message
keythe shared hmac key or a callable taking one argument (the key selector), which returns the hmac key belonging to the key selector. Typical usage is to pass a reference to the get method of a dict.
Returns
tuple of original data, stringoriginal data, salt
Raises
errors.SignatureErrorif the message signature doesn't verify
def WrapPrivateValues(json_data):

Crawl a JSON decoded structure for private values and wrap them.

Parameters
json_datathe json-decoded value to protect.
_RE_EOLSP =

Undocumented

Value
re.compile(r'[ \t]+$',
           re.MULTILINE)