Packer - Serialize / Deserialize packets¶
Smartglass message un-/packing
Also handles de/encryption internally, this means:
You feed plaintext data (wrapped in XStruct) and you get plaintext data
Note on encryption Depending on the packet-type, acquiring the Initialization Vector and encrypting the protected payload happens differently:
ConnectRequest: The IV is randomly chosen from calculated Elliptic Curve (which happens in
Crypto) and is delivered inside the unprotected payload section of the ConnectRequest message.Messages: The IV is generated by encrypting the first 16 bytes of the unencrypted header.
Note on padding If message has protected payload it might need padding according to PKCS#7 (e.g. padding is in whole bytes, the value of each added byte is the number of bytes that are added, i.e. N bytes, each of value N are added. thx wikipedia).
-
xbox.sg.packer.unpack(buf, crypto=None)¶ Unpacks messages from Smartglass CoreProtocol.
For messages that require decryption, a Crypto instance needs to be passed as well.
The decryption happens in
CryptoTunnel.- Parameters
- Raises
PackerError – On various errors, instance of
PackerError.- Returns
The deserialized message, instance of
Container.- Return type
Container
-
xbox.sg.packer.pack(msg, crypto=None)¶ Packs messages for Smartglass CoreProtocol.
For messages that require encryption, a Crypto instance needs to be passed as well.
- Parameters
msg (XStructObj) – A serializable message, instance of
XStructObj.crypto (Crypto) – Instance of
Crypto.
- Returns
The serialized bytes.
- Return type
-
xbox.sg.packer.payload_length(msg)¶ Calculates the packed length in bytes of the given message.
- Parameters
msg (XStructObj) – A serializable message, instance of
XStructObj.- Returns
The packed message length in bytes.
- Return type