Ejemplo n.º 1
0
def add_readings(mac_address: str) -> Response:
    key = get_device_key(mac_address)
    body = decrypt(key, request.get_data())
    body_parsed = json.loads(body.replace(b"'", b'"'))
    handle_readings(mac_address, convert_readings(mac_address, body_parsed))
    response = f"current_time={int(time.time())}&last_config_change={get_device_last_config_change(mac_address)}"
    response_enc = encrypt(key, bytes(response, encoding='utf-8'))
    return Response(response_enc, status=201, content_type=CONTENT_TYPE)
Ejemplo n.º 2
0
def get_config(mac_address: str) -> Response:
    key = get_device_key(mac_address)
    _body = decrypt(key, request.get_data())
    response = f"current_time={int(time.time())}&{get_device_config(mac_address)}"
    response_enc = encrypt(key, bytes(response, encoding='utf-8'))
    return Response(response_enc, content_type=CONTENT_TYPE)
def test_encryption_and_decryption():
    key = bytes.fromhex("0123456789abcdef0123456789abcdef")
    data = b"another chunk of boring test data for encryption, long enough to fill multiple blocks"
    encrypted = encrypt(key, data)
    decrypted = decrypt(key, encrypted)
    assert decrypted == data