From a3d7add3e53dc9d28cbaae23537a8e4736856287 Mon Sep 17 00:00:00 2001 From: John-Mark Gurney Date: Mon, 31 Jan 2022 11:11:02 -0800 Subject: [PATCH] move x25519 tests to _comms module, more will be added.. --- Makefile | 2 +- lora.py | 17 ----------------- lora_comms.py | 19 +++++++++++++++++++ 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/Makefile b/Makefile index 5eb00e7..2885a76 100644 --- a/Makefile +++ b/Makefile @@ -188,7 +188,7 @@ runbuild: $(SRCS) .PHONY: runtests runtests: Makefile lora_comms.py lora.py loraserv.py multicast.py $(LIBLORA_TEST) $(LIBLORA_TEST_SRCS) - ls $(.ALLSRC) | entr sh -c '(cd $(.CURDIR) && $(MAKE) $(.MAKEFLAGS) $(LIBLORA_TEST)) && ((PYTHONPATH="$(.CURDIR)" python3 -m coverage run -m unittest lora multicast loraserv && coverage report --omit=$(.CURDIR)/p/\* -m -i) 2>&1 | head -n 30)' + ls $(.ALLSRC) | entr sh -c '(cd $(.CURDIR) && $(MAKE) $(.MAKEFLAGS) $(LIBLORA_TEST)) && ((PYTHONPATH="$(.CURDIR)" python3 -m coverage run -m unittest lora multicast loraserv lora_comms && coverage report --omit=$(.CURDIR)/p/\* -m -i) 2>&1 | head -n 30)' .if empty(IRR_KEY) && exists($(.CURDIR)/.irr_key) IRR_KEY!= cat $(.CURDIR)/.irr_key diff --git a/lora.py b/lora.py index 1b69c77..bbfd520 100644 --- a/lora.py +++ b/lora.py @@ -603,23 +603,6 @@ class TestSequencing(unittest.IsolatedAsyncioTestCase): # that the order they ran in was correct self.assertEqual(col, list(range(1, 7))) -class TestX25519(unittest.TestCase): - def test_basic(self): - aprivkey = lora_comms.x25519_genkey() - apubkey = lora_comms.x25519_base(aprivkey, 1) - - bprivkey = lora_comms.x25519_genkey() - bpubkey = lora_comms.x25519_base(bprivkey, 1) - - self.assertNotEqual(aprivkey, bprivkey) - self.assertNotEqual(apubkey, bpubkey) - - ra = lora_comms.x25519_wrap(apubkey, aprivkey, bpubkey, 1) - - rb = lora_comms.x25519_wrap(bpubkey, bprivkey, apubkey, 1) - - self.assertEqual(ra, rb) - class TestLORANode(unittest.IsolatedAsyncioTestCase): shared_domain = b'com.funkthat.lora.irrigation.shared.v0.0.1' diff --git a/lora_comms.py b/lora_comms.py index 28867e2..4f8e03b 100644 --- a/lora_comms.py +++ b/lora_comms.py @@ -23,6 +23,7 @@ # import os +import unittest from ctypes import Structure, POINTER, CFUNCTYPE, pointer, sizeof from ctypes import c_uint8, c_uint16, c_ssize_t, c_size_t, c_uint64, c_int @@ -161,3 +162,21 @@ def comms_process_wrap(state, input): comms_process(state, inpkt, outbuf) return outbuf._from() + +class TestX25519(unittest.TestCase): + def test_basic(self): + aprivkey = x25519_genkey() + apubkey = x25519_base(aprivkey, 1) + + bprivkey = x25519_genkey() + bpubkey = x25519_base(bprivkey, 1) + + self.assertNotEqual(aprivkey, bprivkey) + self.assertNotEqual(apubkey, bpubkey) + + ra = x25519_wrap(apubkey, aprivkey, bpubkey, 1) + + rb = x25519_wrap(bpubkey, bprivkey, apubkey, 1) + + self.assertEqual(ra, rb) +