-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support latched topics in udp bridge
- Loading branch information
Showing
4 changed files
with
35 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,19 @@ | ||
import base64 | ||
import pickle | ||
import zlib | ||
|
||
from udp_bridge.aes_helper import AESCipher | ||
|
||
|
||
class MessageHandler: | ||
PACKAGE_DELIMITER = b"\xff\xff\xff" | ||
|
||
def __init__(self, encryption_key: str | None): | ||
self.cipher = AESCipher(encryption_key) | ||
|
||
def encrypt_and_encode(self, data: dict) -> bytes: | ||
serialized_data = base64.b64encode(pickle.dumps(data, pickle.HIGHEST_PROTOCOL)).decode("ASCII") | ||
serialized_data = zlib.compress(pickle.dumps(data, pickle.HIGHEST_PROTOCOL)) | ||
return self.cipher.encrypt(serialized_data) | ||
|
||
def dencrypt_and_decode(self, msg: bytes): | ||
def decrypt_and_decode(self, msg: bytes): | ||
decrypted_msg = self.cipher.decrypt(msg) | ||
binary_msg = base64.b64decode(decrypted_msg) | ||
binary_msg = zlib.decompress(decrypted_msg) | ||
return pickle.loads(binary_msg) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters