parser.py 893 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. import json
  2. import config as cfg
  3. from Utils import *
  4. from tls.AES import AESCipher
  5. LenFunc = cfg.LenFunc
  6. class Parser:
  7. def __init__(self):
  8. gBackPrint("parser ", "created")
  9. def toJSON(self, data):
  10. return json.loads(data)
  11. def toSTRING(self, data):
  12. return json.dumps(data)
  13. def toSEND(self, data):
  14. j = json.dumps(data)
  15. l = LenFunc - len(str(len(j)))
  16. return "00000"[0:l] + str(len(j)) + j
  17. def add(self, data, k, v):
  18. try:
  19. data[k] = v
  20. return data
  21. except Exception as e:
  22. rBackPrint("An exception occurred add", e)
  23. def parser(self, data, addr, id):
  24. data = self.toJSON(data)
  25. gPrint("Simple parser", data)
  26. def encrypt(self,key, msg):
  27. return AESCipher(key).encrypt(msg)
  28. def decrypt(self,key, msg):
  29. return AESCipher(key).decrypt(msg)