Skip to content
Snippets Groups Projects
Commit ba5d95e9 authored by jkerdreu's avatar jkerdreu
Browse files

Fix enum test in message test methods

git-svn-id: https://redmine.imt-atlantique.fr/svn/xaal/code/Python/branches/0.7@2277 b32b6428-25c9-4566-ad07-03861ab6144f
parent b7523f8f
No related branches found
No related tags found
No related merge requests found
......@@ -28,6 +28,7 @@ from . import config
from .exceptions import MessageError,MessageParserError
import ujson as json
#import cbor2 as cbor
import cbor
import datetime
import pysodium
......@@ -46,7 +47,7 @@ class MessageFactory(object):
"""Message Factory:
- Build xAAL message
- Apply security layer, Ciphering/De-Ciphering chacha20 poly1305
- Serialize/Deserialize data in JSON"""
- Serialize/Deserialize data in CBOR"""
def __init__(self, cipher_key):
self.cipher_key = cipher_key # key encode / decode message built from passphrase
......@@ -66,7 +67,6 @@ class MessageFactory(object):
result.append(msg.timestamp[1])
result.append(cbor.dumps(msg.targets))
# import pdb;pdb.set_trace()
# Format payload before ciphering
buf = []
buf.append(msg.source.bytes)
......@@ -77,15 +77,14 @@ class MessageFactory(object):
buf.append(msg.body)
payload = cbor.dumps(buf)
# Payload Ciphering: ciph
# Additionnal Data == json serialization of the targets array
# Payload Ciphering
# Additionnal Data == cbor serialization of the targets array
ad = result[3]
nonce = build_nonce(msg.timestamp)
ciph = pysodium.crypto_aead_chacha20poly1305_ietf_encrypt(payload, ad, nonce, self.cipher_key)
result.append(ciph)
logger.warn(result)
# CBOR serialization
# Final CBOR serialization
pkt = cbor.dumps(result)
return pkt
......@@ -102,7 +101,6 @@ class MessageFactory(object):
except:
raise MessageParserError("Unable to parse CBOR data")
#logger.warning(data_rx)
# Instanciate Message
msg = Message()
try:
......@@ -329,22 +327,22 @@ class Message(object):
return " ".join(l)
def is_request(self):
if self.msgtype == MessageType.REQUEST:
if MessageType(self.msgtype) == MessageType.REQUEST:
return True
return False
def is_reply(self):
if self.msgtype == MessageType.REPLY:
if MessageType(self.msgtype) == MessageType.REPLY:
return True
return False
def is_notify(self):
if self.msgtype == MessageType.NOTIFY:
if MessageType(self.msgtype) == MessageType.NOTIFY:
return True
return False
def is_alive(self):
if self.msgtype == MessageType.NOTIFY and self.action == 'alive':
if self.is_notify() and self.action == 'alive':
return True
return False
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment