From b0c9c9bb4cd60a518aef345b5bcdc6376cfcb187 Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Sun, 26 Feb 2017 04:13:57 -0800 Subject: [PATCH] fix basic test --- src/wormhole/_mailbox.py | 16 ++++++++-------- src/wormhole/_order.py | 32 +++++++++++++++++--------------- src/wormhole/_receive.py | 5 +++-- 3 files changed, 28 insertions(+), 25 deletions(-) diff --git a/src/wormhole/_mailbox.py b/src/wormhole/_mailbox.py index 89eccba..9dc8493 100644 --- a/src/wormhole/_mailbox.py +++ b/src/wormhole/_mailbox.py @@ -84,11 +84,11 @@ class Mailbox(object): if side == self._side: self.rx_message_ours(phase, body) else: - self.rx_message_theirs(phase, body) + self.rx_message_theirs(side, phase, body) @m.input() def rx_message_ours(self, phase, body): pass @m.input() - def rx_message_theirs(self, phase, body): pass + def rx_message_theirs(self, side, phase, body): pass @m.input() def rx_closed(self): pass @@ -129,9 +129,9 @@ class Mailbox(object): assert isinstance(body, type(b"")), type(body) self._RC.tx_add(phase, body) @m.output() - def N_release_and_accept(self, phase, body): + def N_release_and_accept(self, side, phase, body): self._N.release() - self._accept(phase, body) + self._accept(side, phase, body) @m.output() def RC_tx_close(self): assert self._mood @@ -139,12 +139,12 @@ class Mailbox(object): def _RC_tx_close(self): self._RC.tx_close(self._mailbox, self._mood) @m.output() - def accept(self, phase, body): - self._accept(phase, body) - def _accept(self, phase, body): + def accept(self, side, phase, body): + self._accept(side, phase, body) + def _accept(self, side, phase, body): if phase not in self._processed: self._processed.add(phase) - self._O.got_message(phase, body) + self._O.got_message(side, phase, body) @m.output() def dequeue(self, phase, body): self._pending_outbound.pop(phase, None) diff --git a/src/wormhole/_order.py b/src/wormhole/_order.py index b21829d..987649f 100644 --- a/src/wormhole/_order.py +++ b/src/wormhole/_order.py @@ -24,41 +24,43 @@ class Order(object): @m.state(terminal=True) def S1_yes_pake(self): pass - def got_message(self, phase, body): + def got_message(self, side, phase, body): #print("ORDER[%s].got_message(%s)" % (self._side, phase)) + assert isinstance(side, type("")), type(phase) assert isinstance(phase, type("")), type(phase) assert isinstance(body, type(b"")), type(body) if phase == "pake": - self.got_pake(phase, body) + self.got_pake(side, phase, body) else: - self.got_non_pake(phase, body) + self.got_non_pake(side, phase, body) @m.input() - def got_pake(self, phase, body): pass + def got_pake(self, side, phase, body): pass @m.input() - def got_non_pake(self, phase, body): pass + def got_non_pake(self, side, phase, body): pass @m.output() - def queue(self, phase, body): + def queue(self, side, phase, body): + assert isinstance(side, type("")), type(phase) assert isinstance(phase, type("")), type(phase) assert isinstance(body, type(b"")), type(body) - self._queue.append((phase, body)) + self._queue.append((side, phase, body)) @m.output() - def notify_key(self, phase, body): + def notify_key(self, side, phase, body): self._K.got_pake(body) @m.output() - def drain(self, phase, body): + def drain(self, side, phase, body): del phase del body - for (phase, body) in self._queue: - self._deliver(phase, body) + for (side, phase, body) in self._queue: + self._deliver(side, phase, body) self._queue[:] = [] @m.output() - def deliver(self, phase, body): - self._deliver(phase, body) + def deliver(self, side, phase, body): + self._deliver(side, phase, body) - def _deliver(self, phase, body): - self._R.got_message(phase, body) + def _deliver(self, side, phase, body): + self._R.got_message(side, phase, body) S0_no_pake.upon(got_non_pake, enter=S0_no_pake, outputs=[queue]) S0_no_pake.upon(got_pake, enter=S1_yes_pake, outputs=[notify_key, drain]) diff --git a/src/wormhole/_receive.py b/src/wormhole/_receive.py index ba2bbc3..5405531 100644 --- a/src/wormhole/_receive.py +++ b/src/wormhole/_receive.py @@ -31,11 +31,12 @@ class Receive(object): def S3_scared(self): pass # from Ordering - def got_message(self, phase, body): + def got_message(self, side, phase, body): + assert isinstance(side, type("")), type(phase) assert isinstance(phase, type("")), type(phase) assert isinstance(body, type(b"")), type(body) assert self._key - data_key = derive_phase_key(self._key, self._side, phase) + data_key = derive_phase_key(self._key, side, phase) try: plaintext = decrypt_data(data_key, body) except CryptoError: