import serial
import struct
from siphashc import siphash

def _hash(key: str, sender: int, receiver: int, msg_type: int, data: bytes):
    packed_data = struct.pack(">h>hBs", sender, receiver, msg_type, data)
    return struct.pack("Q", siphash(key, packed_data))


class SerialMessage(object):
    def __init__(self):
        pass

    def serialize(self):
        pass




class Connection(object):

    def __init__(self, device):
        self._device = device
        self._conn = None

    def connect(self):
        self._conn = serial.Serial(self._device, 115200)

import serial
import struct
from siphashc import siphash


def _hash(key: bytes, sender: int, receiver: int, msg_type: int, data: bytes):
    packed_data = struct.pack(">hhB", sender, receiver, msg_type) + data
    return struct.pack(">Q", siphash(key, packed_data))


class SerialMessage(object):
    def __init__(self):
        pass

    def serialize(self):
        pass


class Connection(object):
    def __init__(self, device):
        self._device = device
        self._conn = None

    def connect(self):
        self._conn = serial.Serial(self._device, 115200)

Fix python siphashing to match c implementation
Fix python siphashing to match c implementation

Signed-off-by: Jan Losinski <577c4104c61edf9f052c616c0c23e67bef4a9955@wh2.tu-dresden.de>

  import serial
  import struct
  from siphashc import siphash
  
+ 
- def _hash(key: str, sender: int, receiver: int, msg_type: int, data: bytes):
+ def _hash(key: bytes, sender: int, receiver: int, msg_type: int, data: bytes):
-     packed_data = struct.pack(">h>hBs", sender, receiver, msg_type, data)
+     packed_data = struct.pack(">hhB", sender, receiver, msg_type) + data
-     return struct.pack("Q", siphash(key, packed_data))
+     return struct.pack(">Q", siphash(key, packed_data))
  
  
  class SerialMessage(object):
      def __init__(self):
          pass
  
      def serialize(self):
          pass
  
  
- 
- 
  class Connection(object):
- 
      def __init__(self, device):
          self._device = device
          self._conn = None
  
      def connect(self):
          self._conn = serial.Serial(self._device, 115200)
  
Fix python siphashing to match c implementation
## Code Before:
import serial
import struct
from siphashc import siphash

def _hash(key: str, sender: int, receiver: int, msg_type: int, data: bytes):
    packed_data = struct.pack(">h>hBs", sender, receiver, msg_type, data)
    return struct.pack("Q", siphash(key, packed_data))


class SerialMessage(object):
    def __init__(self):
        pass

    def serialize(self):
        pass




class Connection(object):

    def __init__(self, device):
        self._device = device
        self._conn = None

    def connect(self):
        self._conn = serial.Serial(self._device, 115200)

## Instruction:
Fix python siphashing to match c implementation
## Code After:
import serial
import struct
from siphashc import siphash


def _hash(key: bytes, sender: int, receiver: int, msg_type: int, data: bytes):
    packed_data = struct.pack(">hhB", sender, receiver, msg_type) + data
    return struct.pack(">Q", siphash(key, packed_data))


class SerialMessage(object):
    def __init__(self):
        pass

    def serialize(self):
        pass


class Connection(object):
    def __init__(self, device):
        self._device = device
        self._conn = None

    def connect(self):
        self._conn = serial.Serial(self._device, 115200)
